我被要求在用 定义的环境中缩进第一段mdframed
。
我看过这个问题mdframed 环境中的段落缩进,虽然它提供了一种解决方法,但实际上必须有一种更巧妙的方法来做到这一点。(我在手册中找不到任何迹象表明提供了此功能;像这样的选项[indentfirst = true]
真的很好。)
这是测试文件:
\documentclass[11pt]{amsbook}
\usepackage{tikz}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{etoolbox}
% define (using mdframed) a highlighted block with a double line on the
% left along the (inside) edge of the text block.
%
\mdfdefinestyle{twolined}{%
leftline=true,rightline=false,topline=false,bottomline=false,%
outerlinewidth=.7pt,innerlinewidth=.7pt,middlelinewidth=2pt,%
outerlinecolor=black,innerlinecolor=black,middlelinecolor=white,%
innerleftmargin=6pt,innerrightmargin=0pt,%
innertopmargin=0pt,innerbottommargin=0pt,%
% splittopskip=0pt,splitbottomskip=0pt.%
skipabove=.5\baselineskip,skipbelow=.5\baselineskip
}
\newmdenv[%
leftline=true,rightline=false,topline=false,bottomline=false,%
outerlinewidth=.7pt,innerlinewidth=.7pt,middlelinewidth=2pt,%
outerlinecolor=black,innerlinecolor=black,middlelinecolor=white,%
innerleftmargin=6pt,innerrightmargin=0pt,%
innertopmargin=0pt,innerbottommargin=0pt,%
% splittopskip=0pt,splitbottomskip=0pt.%
% skipabove=.5\baselineskip,skipbelow=.5\baselineskip%
skipabove=1\baselineskip,skipbelow=.5\baselineskip%
]{linedintro}
% patch the command on which linedintro is based, to try to restore the
% paragraph indentation on the first line.
%
\makeatletter
\patchcmd\mdf@lrbox
{\parindent\z@}{\parindent\normalparindent\relax}{}{}
\makeatother
\begin{document}
\thispagestyle{empty}
\noindent Some unindented random text.
\begin{linedintro}
First paragraph within the lined environment.
Add some text to make it two lines long.
Second paragraph within the lined environment. Make it two lines long.
\end{linedintro}
\noindent Some more unindented random text.
\end{document}
输出:
我尝试重置其他实例\parindent
,但没有效果。(我可能只是在错误的地方寻找,但不清楚是什么是正确的地方。
如果我将定义中的环境重命名为xlinedintro
并添加“衍生”环境
\newenvironment{linedintro}{%
\begin{xlinedintro}
\parindent\normalparindent
\hspace*{\normalparindent}\ignorespaces
}{%
\end{xlinedintro}%
}
这将强制在第一段缩进。但实际情况要复杂得多,有时marginnote
在环境的开头和实际文本之间必须有其他东西(a),因此需要小心输入以避免出现多余的不必要的空间。
是有没有更好的地方应用补丁?或者有其他更巧妙的方法来实现缩进?
答案1
我可以为其提供一个补丁,linedintro
以便依次进行修补\mdf@lrbox
并\mdf@trivlist
(本地)添加所需的缩进。
\documentclass[11pt]{amsbook}
\usepackage{tikz}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{etoolbox}
% define (using mdframed) a highlighted block with a double line on the
% left along the (inside) edge of the text block.
%
\mdfdefinestyle{twolined}{%
leftline=true,rightline=false,topline=false,bottomline=false,%
outerlinewidth=.7pt,innerlinewidth=.7pt,middlelinewidth=2pt,%
outerlinecolor=black,innerlinecolor=black,middlelinecolor=white,%
innerleftmargin=6pt,innerrightmargin=0pt,%
innertopmargin=0pt,innerbottommargin=0pt,%
% splittopskip=0pt,splitbottomskip=0pt.%
skipabove=.5\baselineskip,skipbelow=.5\baselineskip
}
\newmdenv[%
leftline=true,rightline=false,topline=false,bottomline=false,%
outerlinewidth=.7pt,innerlinewidth=.7pt,middlelinewidth=2pt,%
outerlinecolor=black,innerlinecolor=black,middlelinecolor=white,%
innerleftmargin=6pt,innerrightmargin=0pt,%
innertopmargin=0pt,innerbottommargin=0pt,%
% splittopskip=0pt,splitbottomskip=0pt.%
% skipabove=.5\baselineskip,skipbelow=.5\baselineskip%
skipabove=1\baselineskip,skipbelow=.5\baselineskip%
]{linedintro}
% patch the command on which linedintro is based, to try to restore the
% paragraph indentation on the first line.
%
\makeatletter
\newcommand{\indentforlinedintro}{%
\patchcmd\mdf@lrbox{\parindent\z@}{\parindent\normalparindent\relax}{}{}%
\patchcmd\mdf@trivlist{\itemindent\z@}{\itemindent\normalparindent}{}{}%
}
\patchcmd{\linedintro}{\begin}{\indentforlinedintro\begin}{}{}
\makeatother
\begin{document}
\thispagestyle{empty}
Some random text.
Some random text.
Some random text.
Some random text.
Some random text.
Some random text.
Some random text.
Some random text.
\begin{linedintro}
First paragraph within the lined environment.
Add some text to make it two lines long.
Second paragraph within the lined environment. Make it two lines long.
\end{linedintro}
\noindent Some more unindented random text.
\end{document}
钥匙indent=
也许确实非常有用。