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.

Here is what I have: enter image description here And here is what I would like: enter image description here


The code to get what I currently have:

\documentclass[a4paper, 11pt]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{xcolor}
\usepackage[framemethod=default]{mdframed}

\global\mdfdefinestyle{exampledefault}{%
linecolor=lightgray,linewidth=1pt,%
leftmargin=1cm,rightmargin=1cm
}

\begin{document}

\begin{mdframed}[style=exampledefault, frametitle={Note}]
This is my note.
\end{mdframed}

\end{document}
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

You could proceed as follows:

\documentclass{article}
\usepackage{xcolor}
\usepackage[framemethod=default]{mdframed}

\global\mdfdefinestyle{exampledefault}{%
linecolor=lightgray,linewidth=1pt,%
leftmargin=1cm,rightmargin=1cm,
}

\newenvironment{mymdframed}[1]{%
\mdfsetup{%
frametitle={\colorbox{white}{\,#1\,}},
frametitleaboveskip=-\ht\strutbox,
frametitlealignment=\raggedright
}%
\begin{mdframed}[style=exampledefault]
}{\end{mdframed}}


\begin{document}

\begin{mymdframed}{Note}
This is my note.
\end{mymdframed}
\end{document}

The result:

enter image description here

This method provides some space between and after the title. If you don't want them:

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

\global\mdfdefinestyle{exampledefault}{%
linecolor=lightgray,linewidth=1pt,%
leftmargin=1cm,rightmargin=1cm,
}

\newenvironment{mymdframed}[1]{%
\mdfsetup{%
frametitle={\tikz\node[fill=white,rectangle,inner sep=0pt,outer sep=0pt]{#1};},
frametitleaboveskip=-0.5\ht\strutbox,
frametitlealignment=\raggedright
}%
\begin{mdframed}[style=exampledefault]
}{\end{mdframed}}


\begin{document}

\begin{mymdframed}{Note}
This is my note.
\end{mymdframed}
\end{document}

The result:

enter image description here

share|improve this answer
    
Thank you :-) (more characters) –  Marco Jan 19 '13 at 14:31
add comment

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.