14

How to insert title in mdframed? In my example does not work.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[framemethod=TikZ]{mdframed}

\begin{document}

\section{mdframed}

\begin{mdframed}[numbers=left,frame=single,framesep=5mm,label=Title]
text

text

text

text

text

text

text
\end{mdframed}

\end{document}

I need

------------title------------ enter image description here

And here tytle vertical position?

4
  • 2
    I think \mdfsetup{frametitlealignment=\center} might help. :) Aug 28, 2012 at 15:08
  • You are using some keys which don't belong to mdframed (numbers, frame, framesep); those are keys for lstlistings from the listings package and not for mdframed. Aug 28, 2012 at 15:20
  • See for example file mdframed-example-default.pdf -> example 6 Aug 28, 2012 at 16:20
  • good question, indeed
    – Mikasa
    Jul 10, 2023 at 7:55

1 Answer 1

22

In your example code you are using some keys which don't belong to mdframed; numbers, frame, framesep are keys for lstlistings from the listings package and not for mdframed; with mdframed, you need frametitle:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[framemethod=TikZ]{mdframed}

\mdfsetup{frametitlealignment=\center}

\begin{document}

\section{mdframed}

\begin{mdframed}[frametitle={The title of the frame}]
text
\end{mdframed}

\end{document}

enter image description here

After the edit to the original question, here's a possible solution:

\documentclass{article}
\usepackage{mdframed}
\usepackage{lipsum}

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

\begin{document}

\begin{myenv}{The frame title}
\lipsum[2]
\end{myenv}

\end{document}

enter image description here

6
  • Your answers is perfect, but and the vertical position, with figure above? Aug 28, 2012 at 16:11
  • @RegisdaSilva I updated my answer with a new example code. Is it something like that what you need? Aug 28, 2012 at 16:41
  • @RegisdaSilva You're welcome! I'm glad I could help. Aug 28, 2012 at 17:15
  • You become a mdframed master ;-) Aug 28, 2012 at 17:31
  • @MarcoDaniel Nah, I'm still just an apprentice; you are the master ;-) Aug 28, 2012 at 23:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .