10

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}
6

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

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.