3

I'm dealing with mdframed. I wrote some text in a grey background frame. Then I want to display the frame title, but I don't want that the box which contains the frame title is visible (actually it's white). I just want a box with the title and no background.

Here the code I used:

\documentclass{article}
\usepackage{mdframed, xcolor}

    \newenvironment{myenv}[1]
      {\mdfsetup{
        frametitle={\colorbox{white}{\space#1\space}},
        linecolor=black,
        innertopmargin=10pt,
        backgroundcolor=gray!10!white,
        frametitleaboveskip=-\ht\strutbox,
        frametitlealignment=\center
        }
      \begin{mdframed}%
      }
      {\end{mdframed}}

\begin{document}

    \begin{myenv}{Sintesi}
    {\small Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga}
    \end{myenv}

\end{document}

And the output it's the following:

Frametitle White Background

Where the frame title, "Sintesi", has a white background.

How can I make the title without background?

Thank you very much!

R.

9
  • I am not sure about the desired ouput. Would frametitle={\space#1\space}, this be what you need? – Gonzalo Medina Feb 2 '15 at 0:37
  • Thanks for answering me! I desire a transparent title box. In this way, the writing "Sintesi" has the same background of the box (grey) and the same background of the page (white). I don't know if now it's more clear, probably not..if not I can try to explain again – Dawson Feb 2 '15 at 0:40
  • I used frametitle={\space#1\space} but it just put the writing "Sintesi" above the grey box and I want in the same position it is now! – Dawson Feb 2 '15 at 0:43
  • Please see my answer below. Is it something like that what you need? – Gonzalo Medina Feb 2 '15 at 0:50
  • Absolutely YES. I'm trying to understand what did you write, it's not easy for me, sorry – Dawson Feb 2 '15 at 0:53
1

First version

One option is to place the title using singleextra (for unbroken frames) and firstextra (for broken frames) using a TikZ \node at the desired location and with transparent background. The calc library can be used to place the node at the middle of the upper part of the box, using the special coordinates (O) and (P):

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}

\newenvironment{myenv}[1]
  {\mdfsetup{
    firstextra={
    \node[opacity=0,text opacity=1]
      at ( $ (O|-P)!0.5!(P) $ ) {#1};
    },
    singleextra={
    \node[opacity=0,text opacity=1] 
      at ( $ (O|-P)!0.5!(P) $ ) {#1};
    },
    linecolor=black,
    font=\small,
    hidealllines=true,
    innertopmargin=10pt,
    backgroundcolor=gray!10!white,
    }
  \begin{mdframed}%
  }
  {\end{mdframed}}

\begin{document}

\begin{myenv}{Sintesi}
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga
\end{myenv}

\end{document}

enter image description here

A zoomed-in image showing the title with the two inherited background colors:

enter image description here

You can further adjust the positioning using appropriate shifts:

firstextra={
\node[opacity=0,text opacity=1]
  at ([yshift=1pt] $ (O|-P)!0.5!(P) $ ) {#1};
},
singleextra={
\node[opacity=0,text opacity=1] 
  at ([yshift=1pt] $ (O|-P)!0.5!(P) $ ) {#1};
},

Update

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}

\newenvironment{myenv}[1]
  {\mdfsetup{
    firstextra={
    \node[text opacity=1,fill=white] 
      (title)
      at ( $ (O|-P)!0.5!(P) $ ) {\phantom{#1}};
    \fill[gray!10!white] (title.west|-P) rectangle (title.south east);  
    \node[text opacity=1] 
      at (title) {#1};
    },
    singleextra={
    \node[text opacity=1,fill=white] 
      (title)
      at ( $ (O|-P)!0.5!(P) $ ) {\phantom{#1}};
    \fill[gray!10!white] (title.west|-P) rectangle (title.south east);  
    \node[text opacity=1] 
      at (title) {#1};
    },
    linecolor=black,
    font=\small,
    innertopmargin=10pt,
    backgroundcolor=gray!10!white,
    }
  \begin{mdframed}%
  }
  {\end{mdframed}}

\begin{document}

\begin{myenv}{Sintesi}
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga
\end{myenv}

\end{document}

enter image description here

And the zoomed-in inake for the title:

enter image description here

The coordinate (O) is the lower left corner of the frame, (P) is the upper right corner, so (O|-P) is the upper left corner, and ( $ (O|-P)!0.5!(P) $ ) gives the middle point in the upper segment of the frame.

4
  • I was just asking how can I adjust the positing :) But, following your opinion, is it better like this (with no background) or before, with the white background? Thank you for helping me @Gonzalo – Dawson Feb 2 '15 at 0:57
  • @user51937 I'd rather use a white background and a frame around the title; something like \newenvironment{myenv}[1] {\mdfsetup{ frametitle={\fcolorbox{black}{white}{\space#1\space}}, linecolor=black, innertopmargin=10pt, backgroundcolor=gray!10!white, frametitleaboveskip=-\ht\strutbox, frametitlealignment=\center } \begin{mdframed} } {\end{mdframed}} – Gonzalo Medina Feb 2 '15 at 1:21
  • @user51937 Sorry for the poor formatting of the code in my previous comment, but writing code in comments is painful! – Gonzalo Medina Feb 2 '15 at 1:22
  • Do not even ask sorry, you rule! I'm trying to compare the two ways, I have all the night to understand your code above and finally to chose which way to chose. Grazie ancora! – Dawson Feb 2 '15 at 1:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.