Home > mdframed > Is it possible to set the title for an mdframed newmdenv without specifying the frametitle key

Is it possible to set the title for an mdframed newmdenv without specifying the frametitle key

April 16Hits:0
Advertisement

I want to be able to invoke a mdframed box and specify a title without using the frametitle=Title syntax:

I want to write

\begin{mdframedbox}[Title]     ...content here... \end{mdframedbox} 

instead of

\begin{mdframedbox}[frametitle=Title]     ...content here... \end{mdframedbox} 

Here is a tex document that compiles without contains how I am currently using the mdframed package to create a box.

\documentclass{article}  \usepackage[framemethod=TikZ]{mdframed}%boxes \usepackage{xcolor}%boxes \usepackage{lipsum}  %% Generic use box with grey background \newmdenv[%     backgroundcolor=gray!15,     linecolor=black,     outerlinewidth=1pt,     roundcorner=1mm,     skipabove=\baselineskip,     skipbelow=\baselineskip,     font=\small,     nobreak=true, ]{graybox}  \begin{document}  \begin{graybox}[frametitle=Gray Box Title] \lipsum[1] \end{graybox}  \end{document} 

Edit:

I have looked through the documentation for mdframed and didn't see anything that stood out. My first guess is that it's not possible as mdframed is written and I'll need to write a wrapper environment around it to get the desired behavior, however I wanted to make sure that I didn't miss something that already existed before trying to write said wrapper

Answers

What I've done is just modify very slightly the way \begin{graybox} works so that it new requires one argument which is the title. I then pass that to the frametitle key. I did this by modify the \graybox command which is implicitly called when you have \begin{graybox}. The little bit of magic that does this is:

\let\[email protected]=\graybox
\def\graybox#1{
  \[email protected][frametitle={#1}]
}

The first line save the original \graybox definition in \[email protected]. The second and third lines overwrite the \graybox definition so that it calls the original graybox and passes its the first argument (denoted by #1) to the frametitle key.

The \makeatletter and \makeatother below allows the @ symbol to be used in definitions so that \[email protected] can't be accidentally used in the code.

\documentclass{article}

\usepackage[framemethod=TikZ]{mdframed}%boxes
\usepackage{xcolor}%boxes
\usepackage{lipsum}

%% Generic use box with grey background
\newmdenv[%
    backgroundcolor=gray!15,
    linecolor=black,
    outerlinewidth=1pt,
    roundcorner=1mm,
    skipabove=\baselineskip,
    skipbelow=\baselineskip,
    font=\small,
    nobreak=true,
]{graybox}

\makeatletter
\let\[email protected]=\graybox
\def\graybox#1{
  \[email protected][frametitle={#1}]
}
\makeatother

\begin{document}

\begin{graybox}{Gray Box Title}
\lipsum[1]
\end{graybox}

\end{document}

Is it possible to set the title for an mdframed newmdenv without specifying the frametitle key

Addendum

If you want to have the possibility of not displaying a title, the easiest option is to leave the argument blank as the mdframed package will take an blank frametitle as indicating no title.

Otherwise, an alternative would be to give it an optional argument which is conventionally surrounded by [].

% ...
\makeatletter
\let\[email protected]=\graybox
\def\graybox{
  \@ifnextchar[{\[email protected]}{\[email protected]}
}
\def\[email protected][#1]{
  \[email protected][frametitle={#1}]
}
\makeatother

\begin{document}

\begin{graybox}[Gray Box Title]
\lipsum[1]
\end{graybox}

\begin{graybox}
\lipsum[1]
\end{graybox}

\end{document}

Tags:mdframed

Related Articles

  • Is it possible to set the title for an mdframed newmdenv without specifying the frametitle key

    Is it possible to set the title for an mdframed newmdenv without specifying the frametitle keyApril 16

    I want to be able to invoke a mdframed box and specify a title without using the frametitle=Title syntax: I want to write \begin{mdframedbox}[Title] ...content here... \end{mdframedbox} instead of \begin{mdframedbox}[frametitle=Title] ...content here

  • gnuplot + epslatex: \footnotesize in the plot title leaves much space to the left of the key

    gnuplot + epslatex: \footnotesize in the plot title leaves much space to the left of the keyOctober 22

    As the title said, using \footnotesize in plot ... title '\footnotesize Some Title' leaves much space to the left of the corresponding key. The space can be annoying with grids. As you can see in the picture, the space to the left of the keys is even

  • How can I fix the title height in mdframed boxes?

    How can I fix the title height in mdframed boxes?February 23

    I am trying to write a LaTeX document involving a lot of definitions. For this reason, I decided to create a mdframed environment (see below), and place my definitions one after the other in a two-column environment. \newmdenv[% frametitleaboveskip=5

  • How to display the page title/content in the Posts page?January 25

    I made a home.php file and called it Blog. It set it to be the Posts page, but I would like to add a title that will be displayed in that page (the title of page or content). e.g: Posts page: Page title (Maybe page content) == Posts == Post Title Pos

  • Background image for frame title

    Background image for frame titleSeptember 20

    Using beamer, how can I insert a background image under the title of each frame? I could insert an image but the result was that the title disappeared because the image is over it. Any ideas? --------------Solutions------------- You can use the \addt

  • Beamer: strange behaviour of textpos on title page

    Beamer: strange behaviour of textpos on title pageMarch 21

    I'm working on a customized template for LaTeX beamer. It's finished, except for some strange behaviour of textpost on the title page. Sample code: \documentclass[t]{beamer} \usepackage[absolute,overlay]{textpos} \setbeamertemplate{navigation symbols

  • How I can delete title after pagebreak in mdframed box?November 30

    How I can delete frametitle after pagebreak in mdframed box? I try to make a box with the title "Summary" by mdframed package. With the code I attach, the title "Summary" appears in the second page after pagebreak. But I think it seems

  • Vertically centre the title in mdframed

    Vertically centre the title in mdframedJanuary 7

    I wonder how I can vertically centre the argument of \Title inside the frame in the following MWE. \documentclass[12pt]{report} \usepackage[english]{babel} \usepackage{tikz} \usepackage[framemethod=TikZ]{mdframed} \mdfdefinestyle{MyFrame}{% outerline

  • Beamer how to change color of infolines and frame title

    Beamer how to change color of infolines and frame titleSeptember 18

    How could I change the color of color of infolines and frame title in beamer. I am using this now \documentclass[xcolor=dvipsnames]{beamer} \usetheme{CambridgeUS} \useinnertheme{rectangles} \useoutertheme{infolines} \usecolortheme[named=Brown]{struct

  • Title above left line

    Title above left lineDecember 5

    I'm trying to create a mdframed environment where The title is repeated on every page (works fine with repeatframetitle) the title is left aligned relative to the normal text and this implies that the left line should start below the title. Can someo

  • Using beamer frame title in document textJanuary 21

    I use beamer to create a set of slides that are used to present the contents of a document. Both the slides and the printable document contents are contained in a single set of source files; I use the \mode commands to switch between presentation and

  • How can I hide my section title if there is no data in custom fields?June 6

    I wrote this function with a foreach and I'm not able to figure out how to hide the section title if there are no custom fields in $lista. Where should I place the section title? function opening_hours_custom_fields() { /*Define custom fields in this

  • Remove thin border around mdframed title

    Remove thin border around mdframed titleJune 19

    I get a thin border around the title of a mdframed environment which has the color of the actual content area: I want to get rid of this thin red line around the title. MWE: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}

  • Adjust frame title rule with tcolorbox

    Adjust frame title rule with tcolorboxJanuary 13

    I have been unable to locate an example using tcolorbox which sets the color and width of the line below the frame title independent of the background color of the frame title. With mdframed one can control these via frametitlerulecolor=red and frame

  • gnu screen not to change my window titlesFebruary 20

    I set meaningful names to new windows I create in gnu screen, but then when I 'cd' or open vim that name gets changed to 'pwd' for instance. Is there a way to prevent screen from changing the title? I know there's a setting like that in tmux, but for

  • Generic title command used to insert a pdf or text specified as key valueMay 28

    I'm trying to get my own generic title command I can use either to include a pdf file as a title page, is that file exists, or include a text subdivided in keys using the xkeyval package. My question is to be able to use either \title[my_pdf_file.pdf

  • Beamer custom template: Simple head- and footline and a title page

    Beamer custom template: Simple head- and footline and a title pageFebruary 1

    I'm preparing a talk and i don't like the available beamer themes. They all seem to bloated to me, the ones that are minimalistic are too "loose" in my opinion. I like to have a frame around the content, just like i would use a header and a foot

  • How To Beat Google's 'Brandy' UpdateMarch 8

    The Google update of the 17th-20th February 2004 (nicknamed 'Brandy' by WebmasterWorld) resulted in major changes in the results the search engine returns. The 'Brandy' update seems to have incorporated some pre-'Florida' results (another major updat

  • DHTML Utopia: Modern Web Design Using JavaScript & DOM

    DHTML Utopia: Modern Web Design Using JavaScript & DOMJune 1

    Dynamic HTML, called DHTML for short, is the name given to a set of Web development techniques that are mostly used in Web pages that have non-trivial user-input features. DHTML means manipulating the Document Object Model of an HTML document, fiddli

  • Sql Server Full-Text Search Protips Part 3: Getting RANKedDecember 30

    In Part 1 of this series we explored the methodology for enabling a Sql Server database for Full-Text Indexing and enabling Full-Text indices on specific tables. And in Part 2 of this series we explored the methodology for accessing these Full-Text i

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.502 s.