我想要一个可破坏的环境,它可以缩进内容并在其左侧放置一个括号(或至少是它的角),如下图所示:
至关重要的是嵌套环境也是可破坏的,因此使用像tcolorbox
或这样的工具mdframed
不是一个选择,因为它们不幸不支持可破坏的嵌套框架。
我已经尝试按照如下方式进行操作:
\documentclass[a4paper,12pt,fleqn]{article}
\usepackage{tikz}
\usepackage{changepage}
\usepackage{setspace}
\usepackage{lipsum}
\onehalfspacing
\setlength{\parindent}{0cm}
\setlength{\parskip}{\medskipamount}
\newenvironment{inBrackets}
{
\begin{adjustwidth}{0.75em}{0pt}
\vspace{1ex}
\begin{tikzpicture}[overlay,remember picture,line width=.7pt,lightgray,shift={(-0.625em,0)}]
\draw ((0,\baselineskip-0.5ex)--(0.625em,\baselineskip-0.5ex);
\draw ((0,\baselineskip-0.5ex)--(0,0);
\end{tikzpicture}
\hspace{-1em}\vspace{0.5ex}
}
{
\par\vspace{-\baselineskip}
\begin{tikzpicture}[overlay,remember picture,line width=.7pt,lightgray,shift={(-0.625em,-1.5ex)}]
\draw ((0,0)--(0,\baselineskip);
\draw ((0,0)--(0.625em,0);
\end{tikzpicture}
\vspace{1ex}
\end{adjustwidth}
}
\begin{document}
\paragraph{This is how it should look like:}
\lipsum[1]
\begin{inBrackets}
\lipsum[2]
\begin{inBrackets}
\lipsum[2]
\end{inBrackets}
\lipsum[2]
\end{inBrackets}
\lipsum[4]
\begin{inBrackets}
\lipsum[2]
\end{inBrackets}
\lipsum[4]
\pagebreak
\paragraph{This unfortunately happens:}
\lipsum[4]
\begin{inBrackets}
\lipsum[2]
\begin{inBrackets}
\lipsum[2]
\begin{inBrackets}
\lipsum[4]
\end{inBrackets}
\end{inBrackets}
\end{inBrackets}
\pagebreak
\paragraph{Instead, I would like it to behave like this:}
\lipsum[4]
\begin{inBrackets}
\lipsum[2]
\begin{inBrackets}
\lipsum[2]
\begin{inBrackets}
Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus tincidunt ultrices. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In hac habitasse platea dictumst. Integer tempus convallis augue. Etiam facilisis. Nunc elementum fermentum wisi. Aenean placerat. Ut imperdiet, enim sed gravida sollicitudin, felis odio placerat quam, ac pulvinar elit purus eget enim. Nunc vitae tortor. Proin tem-
\pagebreak
pus nibh sit amet nisl. Vivamus quis tortor vitae risus porta vehicula.
\end{inBrackets}
\end{inBrackets}
\end{inBrackets}
\end{document}
但是,每当分页符恰好位于几个嵌套环境的末尾(以下角为标记)之间或环境内内容的末尾与其下角之间时,一些下角就会单独出现在下一侧,看起来很丑陋(参见我的 MWE 中的第二个示例)。
相反,在这种情况下,我希望环境在环境内内容的最后一行之前放置一个分页符(参见第三个示例)。编辑:换句话说,我想防止页面以关闭的下角开始,而是希望它们以一行文本或打开的下角开始。
如何实现这一点?
答案1
这是一个解决方案。inBrackets
环境有可选参数(缩进)可供使用
\begin{inBrackets}[<indent>]
bla bla
\begin{inBrackets}
平均能量损失
\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\newcommand*{\bmt}{%
\begin{tikzpicture}[line width=.7pt,lightgray]
\draw ((0,\baselineskip-0.5ex)--(0.625em,\baselineskip-0.5ex);
\draw ((0,\baselineskip-0.5ex)--(0,0);
\end{tikzpicture}}
\newcommand*{\emt}{%
\begin{tikzpicture}[line width=.7pt,lightgray]
\draw ((0,0)--(0,\baselineskip);
\draw ((0,0)--(0.625em,0);
\end{tikzpicture}}
\makeatletter
\newenvironment{inBrackets}[1][.5cm]
{\list{}{\leftmargin#1
\labelwidth0pt \itemindent0pt \labelsep\leftmargin
\def\makelabel##1{\rlap{##1}}}%
\item[\bmt]}
{\@itempenalty\@M\item[\emt]\vskip-\baselineskip\endlist}
\makeatother
\begin{document}
\lipsum[1]
\begin{inBrackets}
\lipsum[1]
\begin{inBrackets}
\lipsum[1-5]
\end{inBrackets}
\lipsum[1]
\end{inBrackets}
\end{document}
答案2
同时,我发现添加一个简单的\widowpenalties 2 -9999 0
就可以产生所需的行为。以下是环境的代码:
\documentclass[a4paper,12pt,fleqn]{article}
\usepackage{tikz}
\usepackage{changepage}
\usepackage{setspace}
\onehalfspacing
\setlength{\parindent}{0cm}
\setlength{\parskip}{\medskipamount}
\newenvironment{inBrackets}
{
\begin{adjustwidth}{0.75em}{0pt}
\vspace{1ex}
\begin{tikzpicture}[overlay,remember picture,line width=.7pt,lightgray,shift={(-0.625em,0)}]
\draw ((0,\baselineskip-0.5ex)--(0.625em,\baselineskip-0.5ex);
\draw ((0,\baselineskip-0.5ex)--(0,0);
\end{tikzpicture}
\hspace{-1em}\vspace{0.5ex}
\widowpenalties 2 -9999 0
}
{
\par\vspace{-\baselineskip}
\begin{tikzpicture}[overlay,remember picture,line width=.7pt,lightgray,shift={(-0.625em,-1.5ex)}]
\draw ((0,0)--(0,\baselineskip);
\draw ((0,0)--(0.625em,0);
\end{tikzpicture}
\vspace{1ex}
\end{adjustwidth}
}