如何最干净地为文章中定理类环境之前的段落设置 \emergencystretch?

如何最干净地为文章中定理类环境之前的段落设置 \emergencystretch?

喂食

\documentclass{article}
\newtheorem{theorem}{Theorem}
\begin{document}
Averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword.
\begin{theorem}
  Lots of stuff in several lines. Lots of stuff in several lines. Lots of stuff in several lines.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
A paragraph following the theorem.
\begin{theorem}
  Lots of other stuff.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
\end{document}

产生pdflatex一个 para,其中第二行过多:

第二行太满

为了避免第二行出现过满的情况,您应\emergencystretch在第一段中尽可能局部地将其设置为一个较小的正值。但是,您还必须稍后将其设置\emergencystretch为零,以避免对后续流程产生不良影响。实际上,

\documentclass{article}
\pagestyle{empty}
\newtheorem{theorem}{Theorem}
\begin{document}
\setlength{\emergencystretch}{1.02em}%
Averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword.
\begin{theorem}\setlength{\emergencystretch}{0em}%%% this is local
  Lots of stuff in several lines. Lots of stuff in several lines. Lots of stuff in several lines.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
\setlength{\emergencystretch}{0em}%%% this is global
A paragraph following the theorem.
\begin{theorem}
  Lots of other stuff.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
\end{document}

产量

输出效果良好,没有多余的线条和额外的效果

输出结果不错,但显然,在三个不同的地方设置相同的变量(不必在 LaTeX 编辑器的同一屏幕上)容易出错。有没有更好的方法,不会引入额外的垂直空间或多余的首行缩进?

答案1

您可以\emergencystretch仅为定理之前的一个段落结尾进行本地设置:

\documentclass{article}
\pagestyle{empty}
\newtheorem{theorem}{Theorem}
\begin{document}
Averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword.{\setlength{\emergencystretch}{1.02em}%

}
\begin{theorem}
  Lots of stuff in several lines. Lots of stuff in several lines. Lots of stuff in several lines.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
A paragraph following the theorem.
\begin{theorem}
  Lots of other stuff.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
\end{document}

虽然我不会这么做\sloppy\emergencystrech是调整的好工具默认为难以设置内容的段落设置换行符,但对于调整特定段落的换行符来说,这是一种有些生硬的工具。在这里,查看原始设置,您知道要强制换行的位置,因此我只需这样做,而不是猜测哪个值\emergencystretch会在那里换行,而不会更改段落的其余部分。

\documentclass{article}
\pagestyle{empty}
\newtheorem{theorem}{Theorem}
\begin{document}
Averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-averylongword-\\averylongword.
\begin{theorem}
  Lots of stuff in several lines. Lots of stuff in several lines. Lots of stuff in several lines.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
A paragraph following the theorem.
\begin{theorem}
  Lots of other stuff.\hfill\rule{1ex}{1ex}%%% a halmos.
\end{theorem}%
\end{document}

相关内容