我正在处理mdframed
。我在灰色背景框架中写了一些文本。然后我想显示框架标题,但我不希望包含框架标题的框可见(实际上它是白色的)。我只想要一个带有标题而没有背景的框。
这是我使用的代码:
\documentclass{article}
\usepackage{mdframed, xcolor}
\newenvironment{myenv}[1]
{\mdfsetup{
frametitle={\colorbox{white}{\space#1\space}},
linecolor=black,
innertopmargin=10pt,
backgroundcolor=gray!10!white,
frametitleaboveskip=-\ht\strutbox,
frametitlealignment=\center
}
\begin{mdframed}%
}
{\end{mdframed}}
\begin{document}
\begin{myenv}{Sintesi}
{\small Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga}
\end{myenv}
\end{document}
输出如下:
框架标题“Sintesi”的背景为白色。
如何才能制作出没有背景的标题?
非常感谢!
R.
答案1
第一个版本
singleextra
一种选择是使用(对于连续的帧)和(对于断开的帧)将标题放置在所需位置并使用透明背景firstextra
的 TikZ \node
。可以使用 calc 库将节点放置在框上部的中间,使用特殊坐标(O)
和(P)
:
\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}
\newenvironment{myenv}[1]
{\mdfsetup{
firstextra={
\node[opacity=0,text opacity=1]
at ( $ (O|-P)!0.5!(P) $ ) {#1};
},
singleextra={
\node[opacity=0,text opacity=1]
at ( $ (O|-P)!0.5!(P) $ ) {#1};
},
linecolor=black,
font=\small,
hidealllines=true,
innertopmargin=10pt,
backgroundcolor=gray!10!white,
}
\begin{mdframed}%
}
{\end{mdframed}}
\begin{document}
\begin{myenv}{Sintesi}
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga
\end{myenv}
\end{document}
放大的图像显示具有两种继承的背景颜色的标题:
您可以使用适当的移位进一步调整定位:
firstextra={
\node[opacity=0,text opacity=1]
at ([yshift=1pt] $ (O|-P)!0.5!(P) $ ) {#1};
},
singleextra={
\node[opacity=0,text opacity=1]
at ([yshift=1pt] $ (O|-P)!0.5!(P) $ ) {#1};
},
更新
\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}
\newenvironment{myenv}[1]
{\mdfsetup{
firstextra={
\node[text opacity=1,fill=white]
(title)
at ( $ (O|-P)!0.5!(P) $ ) {\phantom{#1}};
\fill[gray!10!white] (title.west|-P) rectangle (title.south east);
\node[text opacity=1]
at (title) {#1};
},
singleextra={
\node[text opacity=1,fill=white]
(title)
at ( $ (O|-P)!0.5!(P) $ ) {\phantom{#1}};
\fill[gray!10!white] (title.west|-P) rectangle (title.south east);
\node[text opacity=1]
at (title) {#1};
},
linecolor=black,
font=\small,
innertopmargin=10pt,
backgroundcolor=gray!10!white,
}
\begin{mdframed}%
}
{\end{mdframed}}
\begin{document}
\begin{myenv}{Sintesi}
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga
\end{myenv}
\end{document}
标题放大如下:
坐标(O)
是框架的左下角,(P)
是右上角,也是(O|-P)
左上角,并( $ (O|-P)!0.5!(P) $ )
给出框架上段的中间点。