Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
I think \mdfsetup{frametitlealignment=\center} might help. :) –  Paulo Cereda Aug 28 '12 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. –  Gonzalo Medina Aug 28 '12 at 15:20
    
See for example file mdframed-example-default.pdf -> example 6 –  Marco Daniel Aug 28 '12 at 16:20

1 Answer 1

up vote 6 down vote accepted

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

share|improve this answer
    
Your answers is perfect, but and the vertical position, with figure above? –  Regis da Silva Aug 28 '12 at 16:11
    
@RegisdaSilva I updated my answer with a new example code. Is it something like that what you need? –  Gonzalo Medina Aug 28 '12 at 16:41
    
Yes, Gonzalo Medina, perfect. Thanks. –  Regis da Silva Aug 28 '12 at 16:58
    
@RegisdaSilva You're welcome! I'm glad I could help. –  Gonzalo Medina Aug 28 '12 at 17:15
    
You become a mdframed master ;-) –  Marco Daniel Aug 28 '12 at 17:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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