![mdframed:在框架标题下方放置一行并为其添加阴影背景](https://linux22.com/image/241763/mdframed%EF%BC%9A%E5%9C%A8%E6%A1%86%E6%9E%B6%E6%A0%87%E9%A2%98%E4%B8%8B%E6%96%B9%E6%94%BE%E7%BD%AE%E4%B8%80%E8%A1%8C%E5%B9%B6%E4%B8%BA%E5%85%B6%E6%B7%BB%E5%8A%A0%E9%98%B4%E5%BD%B1%E8%83%8C%E6%99%AF.png)
我喜欢使用 来mdframed
创建一个带有可选标题的框架环境。标题必须位于其自己的框中,背景为灰色,如下所示:
我希望这是可能的。
平均能量损失
\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}
\newenvironment{Frame}[1][]{%
\begin{mdframed}[%
frametitle={#1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
]%
}{%
\end{mdframed}
}
\begin{document}
Text
\begin{Frame}[with Title]
Text
\end{Frame}
Text
\begin{Frame}% no Title
Text
\end{Frame}
Text
\end{document}
我喜欢使用mdframed
而不是包装和黑客来制作上面的图片,因为它更灵活:-)
答案1
更新
mdframed 1.2 版新增了设置框架标题的功能。根据您的要求,您可以简单地使用选项frametitlerule=true
和frametitlebackgroundcolor=gray!20
。当前版本可在github。
\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}
\newenvironment{Frame}[1][]{%
\begin{mdframed}[%
frametitle={#1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
frametitlebackgroundcolor=gray!30
]%
}{%
\end{mdframed}
}
\begin{document}
Text
\begin{Frame}[with Title]
Text
\end{Frame}
Text
\begin{Frame}% no Title
Text
\end{Frame}
Text
\end{document}
通过使用tikz
修改标题这里有一个建议。
您必须修改命令\mdframetitleenv
才能影响输出。包本身控制框架标题是否为空。
\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}
\makeatletter
%ORIGINAL
%\providecommand*\mdframedtitleenv[1]{%
% \@afterindentfalse
% {\parindent \z@
% \setlength{\parfillskip}{\z@ plus 1fil}%
% \mdraggedtitle\nobreak\mdf@frametitlefont#1\relax%
% \par}%
% \@afterheading}
\tikzstyle{mybox} = [draw=black, %
fill=gray!20,%
line width=\mdf@middlelinewidth@length,
rectangle,
inner sep=0pt,
inner ysep=0.333em,
minimum height=1cm,
text width = \linewidth
+\mdf@innerleftmargin@length
+\mdf@innerrightmargin@length
+\mdf@linewidth@length,
align=left,
]
\renewcommand*{\mdframedtitleenv}[1]{%
\vspace*{\dimexpr-\mdf@innertopmargin@length-\mdf@linewidth@length\relax}%
\makebox[0pt][l]{%
\hspace*{\dimexpr-\mdf@innerleftmargin@length-\mdf@linewidth@length\relax}%
\begin{tikzpicture}[remember picture]
\node [mybox]{\hspace*{\mdf@innerrightmargin@length}%
\parbox{\linewidth}{\mdf@frametitlefont#1\relax}};%
\end{tikzpicture}%
}%
\par
\@afterheading
}%
\newenvironment{Frame}[1][]{%
\begin{mdframed}[%
frametitle={#1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
]%
}{%
\end{mdframed}
}
\begin{document}
Text
\begin{Frame}[with Title]
Text
\end{Frame}
Text
\begin{Frame}[with Title with Title with Title with Title with Title with Title with Title with Title with Title with Title with Title with Title with Title with Title with Title with Title]
Text
\end{Frame}
Text
\begin{Frame}% no Title
Text
\end{Frame}
Text
\end{document}