使用该mdframed
包,可以在文本的左侧或右侧绘制漂亮的线条。例如:
\documentclass[a4paper,twoside,11pt]{article}
\usepackage[framemethod=TikZ]{mdframed}
\mdfdefinestyle{MDFStyGrayBar}{%
linecolor=gray,
backgroundcolor=white,
%
outerlinewidth=5pt,
%
topline=false,
bottomline=false,
rightline=false,
leftline=true,
%
innertopmargin=4pt, %\baselineskip
innerbottommargin=8pt,
innerrightmargin=3pt,
innerleftmargin=3pt,
%
skipabove=\topskip,
skipbelow=\topskip
}
\begin{document}
\noindent Some normal text.
\begin{mdframed}[style=MDFStyGrayBar]
Some text with a vertical bar on the left.
\end{mdframed}
\end{document}
看起来像这样:
但是如果我想让这条线内双面文档中的“twoside”是什么?即,在右页中位于左侧,在左页中位于右侧?当框架延伸到多页时,这也应该有效。使用 mdframed 包可以实现吗?
感谢您的帮助!
答案1
mdframed
检测它是否在 twoside 模式中使用。如果是,您可以通过innermargin
和调整长度outermargin
。下面的 hack 在原始定义中添加了一些选项。如果您在奇数页上,则\mdfsetup{hidealllines=true,leftline=true}
使用该设置。另一方面,\mdfsetup{hidealllines=true,rightline=true}
使用。
\documentclass[a4paper,twoside,11pt]{article}
\usepackage[framemethod=TikZ]{mdframed}
\makeatletter
\newrobustcmd*\if@mdf@pageodd@bar{%
\zref@refused{mdf@pagelabel-\the\value{mdf@zref@counter}}%
\ifodd\zref@extract{mdf@pagelabel-\the\value{mdf@zref@counter}}%
{mdf@pagevalue}%
\setlength\mdf@rightmargin@length{\mdf@outermargin@length}%
\setlength\mdf@leftmargin@length{\mdf@innermargin@length}%
\mdfsetup{hidealllines=true,leftline=true}%
\else
\setlength\mdf@rightmargin@length{\mdf@innermargin@length}%
\setlength\mdf@leftmargin@length{\mdf@outermargin@length}%
\mdfsetup{hidealllines=true,rightline=true}%
\fi%
}
\newrobustcmd*\changepageodd{\let\if@mdf@pageodd\if@mdf@pageodd@bar}
\makeatother
\mdfdefinestyle{MDFStyGrayBar}{%
linecolor=gray,
backgroundcolor=white,
%
outerlinewidth=5pt,
%
topline=false,
bottomline=false,
rightline=false,
leftline=true,
%
innertopmargin=4pt, %\baselineskip
innerbottommargin=8pt,
innerrightmargin=3pt,
innerleftmargin=3pt,
%
skipabove=\topskip,
skipbelow=\topskip,
settings={\changepageodd}
}
\usepackage{showframe,lipsum}
\begin{document}
\noindent Some normal text.
\begin{mdframed}[style=MDFStyGrayBar]
\lipsum
\end{mdframed}
\end{document}