我正在尝试使用 mdframed 包定义的“示例环境”,如下所示(取自 StackExchange 上的另一个答案):
\newmdtheoremenv[
hidealllines=true,
leftline=true,
innerbottommargin=6pt,
linewidth=4pt,
linecolor=gray!40,
leftmargin=0pt,
innertopmargin=-6pt,
innerrightmargin=0pt,
]{example}{Example}
但是,当我使用它时,它会缩进。我希望它不缩进,并且我希望文本“示例 #”加粗。我该如何修改环境来实现这一点?
非常感谢!
答案1
我认为“缩进”的意思是环境内的文本宽度小于\textwidth
文档的宽度;调整leftmargin
将得到您想要的结果。标题“练习 #”已经以粗体显示:
\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}
\newmdtheoremenv[
hidealllines=true,
leftline=true,
innerbottommargin=6pt,
linewidth=4pt,
linecolor=gray!40,
leftmargin=-14pt,
innertopmargin=0pt,
innerbottommargin=0pt,
innerrightmargin=0pt,
]{example}{Example}
\begin{document}
\lipsum[4]
\begin{example}
\lipsum[2]
\end{example}
\end{document}
结果:
作为替代方案,我建议你使用tcolorbox
:
\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\newtcolorbox[auto counter]{texample}[1][]{
breakable,
boxsep=0pt,
leftrule=4pt,
rightrule=0pt,
toprule=0pt,
bottomrule=0pt,
top=0pt,
bottom=0pt,
before skip=\topsep,
after skip=\topsep,
arc=0pt,
outer arc=0pt,
colback=white,
colframe=gray!40,
oversize,
title={Example~\thetcbcounter},
fonttitle=\normalfont\bfseries,
coltitle=black,
fontupper=\itshape,
detach title,before upper={\tcbtitle\hspace{0.5em}}
}
\begin{document}
\lipsum[4]
\begin{texample}
\lipsum[2]
\end{texample}
\end{document}
结果: