我非常喜欢
带有自定义标题的 mdframed digressionarrows 样式。我想通过frametitle
在自定义(即旁注或信息)后显示(如果已定义)来进一步扩展它digressiontitle
。到目前为止,这是我设法做到的:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}
\usepackage{etoolbox}
\usepackage[framemethod=tikz]{mdframed}
\makeatletter
\mdf@do@stringoption{digressiontitle=={Digression}}
\tikzset{
excursus arrow/.style={%
line width=2pt,
draw=gray!40,
rounded corners=2ex,
},
excursus head/.style={
fill=white,
font=\bfseries\sffamily,
text=gray!80,
anchor=base west,
},
}
\mdfdefinestyle{digressionarrows}{%
singleextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path let \p1=(Q), \p2=(O) in (\x1,{(\y1-\y2)/2}) coordinate (M);
\path [excursus arrow, round cap-to]
($(O)+(5em,0ex)$) -| (M) |- %
($(Q)+(12em,0ex)$) .. controls +(0:16em) and +(185:6em) .. %
++(23em,2ex);
\ifx\empty\mdf@frametitle\empty
\node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle};
\else
\node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle:\space\mdf@frametitle};
\fi},
firstextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow,-to] (O) |- %
($(Q)+(12em,0ex)$) .. controls +(0:16em) and +(185:6em) .. %
++(23em,2ex);
\ifx\empty\mdf@frametitle\empty
\node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle};
\else
\node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle:\space\mdf@frametitle};
\fi},
secondextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow,round cap-]($(O)+(5em,0ex)$) -| (Q);},
middleextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow](O) -- (Q);},
middlelinewidth=2.5em,middlelinecolor=white,
hidealllines=true,topline=true,
innertopmargin=0.5ex,
innerbottommargin=2.5ex,
innerrightmargin=2pt,
innerleftmargin=2ex,
skipabove=0.87\baselineskip,
skipbelow=0.62\baselineskip,
}
\makeatother
\newmdenv[style=digressionarrows,digressiontitle=Info]{info}
\newmdenv[style=digressionarrows,digressiontitle=Side note]{sidenote}
\usepackage{lipsum}
\begin{document}
\begin{sidenote}[frametitle=A side note 1]
\lipsum[3]
\end{sidenote}
\begin{info}[frametitle=My frame]
\lipsum[1]
\lipsum
\end{info}
\end{document}
此解决方案的问题是仍然显示。有没有简单的方法可以通过 来frametitle
抑制 的显示?frametitle
mdframed
更新:
以下图片希望能说明问题:
如您所见,“A side note 1”出现了两次,一次是出现在 Side note: 后面的灰色部分,应该保留;一次出现在文本上方的框架内。我想隐藏这个部分。
答案1
最简单的解决方案是为你的标题定义一个新键;这样,两个元素(frametitle
和你的标题)都是独立的。这只需使用类似
\def\mdf@mytitle{}
\define@key{mdf}{mytitle}{%
\def\mdf@mytitle{#1}}
现在,您可以\mdf@mytitle
在内部设置中使用 frametitle 键,而mytitle
在您的 s 选项中使用该键mdframe
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}
\usepackage{etoolbox}
\usepackage{lipsum}
\usepackage[framemethod=tikz]{mdframed}
\makeatletter
\def\mdf@mytitle{}
\define@key{mdf}{mytitle}{%
\def\mdf@mytitle{#1}}
\mdf@do@stringoption{digressiontitle=={Digression}}
\tikzset{
excursus arrow/.style={%
line width=2pt,
draw=gray!40,
rounded corners=2ex,
},
excursus head/.style={
fill=white,
font=\bfseries\sffamily,
text=gray!80,
anchor=base west,
},
}
\mdfdefinestyle{digressionarrows}{%
singleextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path let \p1=(Q), \p2=(O) in (\x1,{(\y1-\y2)/2}) coordinate (M);
\path [excursus arrow, round cap-to]
($(O)+(5em,0ex)$) -| (M) |- %
($(Q)+(12em,0ex)$) .. controls +(0:16em) and +(185:6em) .. %
++(23em,2ex);
\ifx\empty\mdf@mytitle\empty
\node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle};
\else
\node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle:\space\mdf@mytitle};
\fi},
firstextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow,-to] (O) |- %
($(Q)+(12em,0ex)$) .. controls +(0:16em) and +(185:6em) .. %
++(23em,2ex);
\ifx\empty\mdf@mytitle\empty
\node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle};
\else
\node [excursus head] at ($(Q)+(2.5em,-0.75pt)$) {\mdf@digressiontitle:\space\mdf@mytitle};
\fi},
secondextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow,round cap-]($(O)+(5em,0ex)$) -| (Q);},
middleextra={%
\path let \p1=(P), \p2=(O) in (\x2,\y1) coordinate (Q);
\path [excursus arrow](O) -- (Q);},
middlelinewidth=2.5em,middlelinecolor=white,
hidealllines=true,topline=true,
innertopmargin=0.5ex,
innerbottommargin=2.5ex,
innerrightmargin=2pt,
innerleftmargin=2ex,
skipabove=0.87\baselineskip,
skipbelow=0.62\baselineskip,
}
\makeatother
\newmdenv[style=digressionarrows,digressiontitle=Info]{info}
\newmdenv[style=digressionarrows,digressiontitle=Side note]{sidenote}
\begin{document}
\begin{sidenote}[mytitle=A side note 1]
\lipsum[3]
\end{sidenote}
\begin{info}[mytitle=My frame]
\lipsum[1]
\lipsum
\end{info}
\end{document}