这是我所拥有的: 这是我所想要的:
获取我当前拥有的内容的代码:
\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}
答案1
您可以按照下列步骤进行:
\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}
结果:
此方法在标题之间和标题后留出一些空间。如果您不想要它们:
\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}
结果: