我该如何在示例环境旁边添加一条垂直线,就像这篇文章中一样:示例环境?。我没有从那篇文章中复制环境的原因是,不可能(至少据我所知)标记和引用该环境。
\documentclass{memoir}
\usepackage[most]{tcolorbox}
\newcounter{testexample}
\usepackage{xparse}
\usepackage{lipsum}
\def\exampletext{Eksempel} % If English
\NewTColorBox[use counter=testexample]{testexamplebox}{O{}o}{%
% Example Frame Start
empty,% Empty previously set parameters
title={\exampletext\ \thetcbcounter: #1},% use \thetcbcounter to access the
% Attaching a box requires an overlay
attach boxed title to top left,
% Ensures proper line breaking in longer titles
minipage boxed title,
% (boxed title style requires an overlay)
boxed title style={empty,size=minimal,toprule=0pt,top=4pt,left=3mm,overlay=
{}},
coltitle=colexam,fonttitle=\bfseries, before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=3mm,right=0mm,top=2pt,breakable,pad at break=0mm,
before upper=\csname @totalleftmargin\endcsname0pt, % Use instead of
parbox=true. %This ensures parskip is inherited by box.
% Handles box when it exists on one page only
overlay unbroken={\draw[colexam,line width=5pt] ([xshift=-0pt]title.north
west) -- ([xshift=-0pt]frame.south west); },
% Handles multipage box: first page
overlay first={\draw[colexam,line width=5pt] ([xshift=-0pt]title.north west)
-- ([xshift=-0pt]frame.south west); },
% Handles multipage box: middle page
overlay middle={\draw[colexam,line width=5pt] ([xshift=-0pt]frame.north west)
-- ([xshift=-0pt]frame.south west); },
% Handles multipage box: last page
overlay last={\draw[colexam,line width=5pt] ([xshift=-0pt]frame.north west) -
- ([xshift=-0pt]frame.south west); },%
IfValueTF={#2}{#2}{},
}
\NewDocumentEnvironment{testexample}{O{}O{}}
{%
\colorlet{colexam}{red!55!black} % Global example color
\begin{testexamplebox}[#1][#2]
}{\end{testexamplebox}\endlist}
\begin{document}
\lipsum[1]
\begin{testexample}[Latin Text][label=ex:latintext]
\lipsum[2]
\end{testexample}
I'm here refering to example \ref{ex:latintext}
\end{document}
我想补充的是:
答案1
后面有一个拼写错误
parbox=true.
应该.
是一个,
直到找到选项后的下一个代码后,才会执行其余代码,
,因为第一个覆盖规范适用于未破损的框,而示例不在破损的框中,因此永远不会执行此代码。
更好的变体是使用borderline
密钥,我稍后会更新。
\documentclass{memoir}
\usepackage[most]{tcolorbox}
\newcounter{testexample}
\usepackage{xparse}
\usepackage{lipsum}
\def\exampletext{Eksempel} % If English
\NewTColorBox[use counter=testexample]{testexamplebox}{O{}o}{%
% Example Frame Start
empty,% Empty previously set parameters
%enhanced,
title={\exampletext\ \thetcbcounter: #1},% use \thetcbcounter to access the
% Attaching a box requires an overlay
attach boxed title to top left,
% Ensures proper line breaking in longer titles
minipage boxed title,
% (boxed title style requires an overlay)
boxed title style={empty,size=minimal,toprule=0pt,top=4pt,left=3mm,overlay={}},
coltitle=colexam,
fonttitle=\bfseries,
before=\par\medskip\noindent,
boxsep=0pt,left=3mm,
right=0mm,top=2pt,
breakable,
pad at break=0mm,
before upper=\csname @totalleftmargin\endcsname0pt, % Use instead of
parbox=true, %This ensures parskip is inherited by box.
% Handles box when it exists on one page only
overlay unbroken={\draw[colexam,line width=5pt] ([xshift=-0pt]title.north
west) -- ([xshift=-0pt]frame.south west);
},
%Handles multipage box: first page
overlay first={\draw[colexam,line width=5pt] ([xshift=-0pt]title.north west)
-- ([xshift=-0pt]frame.south west); },
%Handles multipage box: middle page
overlay middle={\draw[colexam,line width=5pt] ([xshift=-0pt]frame.north west)
-- ([xshift=-0pt]frame.south west); },
% Handles multipage box: last page
overlay last={\draw[colexam,line width=5pt] ([xshift=-0pt]frame.north west) -
- ([xshift=-0pt]frame.south west); },%
IfValueTF={#2}{#2}{},
}
\NewDocumentEnvironment{testexample}{O{}O{}}
{%
\colorlet{colexam}{red!55!black} % Global example color
\begin{testexamplebox}[#1][#2]
}{\end{testexamplebox}\endlist}
\begin{document}
\lipsum[1]
\begin{testexample}[Latin Text][label=ex:latintext]
\lipsum[2]
\end{testexample}
I'm here refering to example \ref{ex:latintext}
\end{document}