使用 ragged2e 尽量减少连字符

使用 ragged2e 尽量减少连字符

几乎每个 LaTeX 指南都建议使用\RaggedRightragged2e而不是内置的\raggedright。但我总是对 中带连字符的单词太多感到沮丧\RaggedRight。我知道我会得到一些(其中\raggedright没有),但我得到的太多了。

我决定与完全对齐进行比较\RaggedRight,并始终发现使用完全对齐得到的连字符\RaggedRight比使用完全对齐得到的连字符多,这是我意想不到的。在下面的例子中,使用完全对齐时我只得到一个连字符(并且这只是在手动创建的连字符点处解决overfull \hbox),但使用 时我得到了七个\RaggedRight。(文本来自 Moby Dick,属于公共领域。)

我可以减少连字符的数量,\RaggedRight以便与完全对齐的结果相媲美吗?

\documentclass{article}
\usepackage[textwidth=4.0in]{geometry}
\usepackage{ragged2e}

% 1 hyphenated word with no ragged right
% 7 hyphenated words with \RaggedRight from ragged2e

\begin{document}
\RaggedRight
Call me Ishmael. Some years ago---never mind how long
precise\-ly---having little or no money in my purse, and nothing
particular to interest me on shore, I thought I would sail about a
little and see the watery part of the world. It is a way I have of
driving off the spleen and regulating the circulation. Whenever I
find myself growing grim about the mouth; whenever it is a damp,
drizzly November in my soul; whenever I find myself involuntarily
pausing before coffin warehouses, and bringing up the rear of
every funeral I meet; and especially whenever my hypos get such an
upper hand of me, that it requires a strong moral principle to
prevent me from deliberately stepping into the street, and
methodically knocking people's hats off---then, I account it high
time to get to sea as soon as I can. This is my substitute for
pistol and ball. With a philosophical flourish Cato throws himself
upon his sword; I quietly take to the ship. There is nothing
surprising in this. If they but knew it, almost all men in their
degree, some time or other, cherish very nearly the same feelings
towards the ocean with me.
\end{document}

答案1

关于换行的一些话。TeX 根据每行中粘连的拉伸量为每行分配一个坏度。在不规则的右侧设置中,只有右侧 ( \rightskip) 处有可拉伸的粘连,这会导致此粘连(如果是有限的)通常会拉伸得比规定的更多。 的默认值\RaggedRight具有最多 2 em 的“最佳”拉伸,但行很可能无法在右边距附近达到这个值,因此预计会有较高的坏度。使用默认值\hyphenpenalty50,为了最小化总缺点,TeX 会发现更便宜的做法是将连字符连接得更靠近边距。

如果我们使连字变得不那么方便,那么粘连拉伸对总缺点的影响将比连字要小。

请注意,在标准\raggedright设置下,连字永远不会发生(好吧,几乎不会发生),因为\rightskip具有无限拉伸(0pt plus 1fil),所以行将具有零坏度并且缺点只会从中添加\linepenalty,所以 TeX 只会最小化行数。

找到一个好的折衷方案并不容易:增加的拉伸\rightskip可能会让 TeX 更愿意设置更短的行。我建议增加\hyphenpenalty,与microtype这一起通常会对段落设置产生相当好的影响。

\documentclass{article}
\usepackage[textwidth=4.0in]{geometry}
\usepackage{microtype}
\usepackage{ragged2e}

\begin{document}
\newcommand\incipit{Call me Ishmael. Some years ago---never mind how long
precise\-ly---having little or no money in my purse, and nothing
particular to interest me on shore, I thought I would sail about a
little and see the watery part of the world. It is a way I have of
driving off the spleen and regulating the circulation. Whenever I
find myself growing grim about the mouth; whenever it is a damp,
drizzly November in my soul; whenever I find myself involuntarily
pausing before coffin warehouses, and bringing up the rear of
every funeral I meet; and especially whenever my hypos get such an
upper hand of me, that it requires a strong moral principle to
prevent me from deliberately stepping into the street, and
methodically knocking people's hats off---then, I account it high
time to get to sea as soon as I can. This is my substitute for
pistol and ball. With a philosophical flourish Cato throws himself
upon his sword; I quietly take to the ship. There is nothing
surprising in this. If they but knew it, almost all men in their
degree, some time or other, cherish very nearly the same feelings
towards the ocean with me.}

\RaggedRight

\noindent With \texttt{microtype}

\bigskip

\noindent\texttt{\string\hyphenpenalty=50}

\incipit

\bigskip

\noindent\texttt{\string\hyphenpenalty=500}

\hyphenpenalty=500

\incipit

\end{document}

在此处输入图片描述

结果:在默认连字惩罚下,三个单词被连字;在增加连字惩罚后,只有一个单词被连字。

同样没有microtype

在此处输入图片描述

结果是:在默认连字惩罚下,有七个单词被连字;在增加连字惩罚后,只有两个单词被连字。

在所有情况下,precisely由于存在破折号,连字符是不可避免的。

答案2

的“粗糙度”\RaggedRight可以通过长度 来配置\RaggedRightRightskip,当 TeX 拆分段落时,它会插入到行的右端。默认值为0pt plus 2em,这意味着行可以是满的,也可以是短的,右侧最多有 2em 的空白。

增加该值可将2.8em连字符数减少为一个,但代价是段落右侧的字符更加不规则。

\documentclass{article}
\usepackage[textwidth=4.0in]{geometry}
\usepackage{ragged2e}

\setlength{\RaggedRightRightskip}{0pt plus 2.8em}

\begin{document}
\RaggedRight
Call me Ishmael. Some years ago---never mind how long
precise\-ly---having little or no money in my purse, and nothing
particular to interest me on shore, I thought I would sail about a
little and see the watery part of the world. It is a way I have of
driving off the spleen and regulating the circulation. Whenever I
find myself growing grim about the mouth; whenever it is a damp,
drizzly November in my soul; whenever I find myself involuntarily
pausing before coffin warehouses, and bringing up the rear of
every funeral I meet; and especially whenever my hypos get such an
upper hand of me, that it requires a strong moral principle to
prevent me from deliberately stepping into the street, and
methodically knocking people's hats off---then, I account it high
time to get to sea as soon as I can. This is my substitute for
pistol and ball. With a philosophical flourish Cato throws himself
upon his sword; I quietly take to the ship. There is nothing
surprising in this. If they but knew it, almost all men in their
degree, some time or other, cherish very nearly the same feelings
towards the ocean with me.
\end{document}

结果

相关内容