贪婪换行符为 2 行

贪婪换行符为 2 行

我有一些文本需要排版,这些文本足够短,可以容纳 1 或 2 行。我正在使用\raggedright

我想设置如下参数,\hyphenpenalty以便将尽可能多的内容放在第一行,而不会创建未满或过满的水平框。如果可以对单词进行连字符连接(这会在第一行产生更多文本),则应在最后可能的位置对其进行连字符连接。

我尝试更改许多设置,包括\pretolerance-1,但无法使其工作。

例如这里:

\documentclass{article}
\usepackage{t1enc}
\begin{document}
\hrule width137pt height 1pt
\vbox{\hsize137pt\parindent0pt\sf\raggedright\par
  Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\break\'al\-lo\-m\'as \par}
\bigskip
\vbox{\hsize137pt\parindent0pt\sf\raggedright\par
  Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\'al\-lo-\break m\'as \par}
\vbox{\hsize137pt\parindent0pt\sf\raggedright
  \pretolerance-1
  \hyphenpenalty1
  \exhyphenpenalty2
  \par
  Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\'al\-lo\-m\'as \par}
\end{document}

,可以适应艺术雕塑,自动车-到第一行,但如果 LaTeX 自动换行,那么它只会艺术品,那里(见最后\vbox)。我怎样才能把尽可能多的内容放到第一行?

我知道 TeX 的换行算法会全局优化段落,并且几乎不可能对其进行配置以使其贪婪,但当文本首先到达 1 或 2 行时,也许有一个简单的解决方案。

我知道我可以在本地切换到“贪婪”的证明算法吗?\linebylinepar在它的回答中https://tex.stackexchange.com/a/131275/820,但即使这样也不会放艺术雕塑,自动车-到第一行。

答案1

解决这个问题是该包的主要目的ragged2e,请参见最后添加的示例:

在此处输入图片描述

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{ragged2e}
\begin{document}
\hrule width137pt height 1pt
\vbox{\hsize137pt\parindent0pt\sf\raggedright\par
  Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\break\'al\-lo\-m\'as \par}
\bigskip
\vbox{\hsize137pt\parindent0pt\sf\raggedright\par
  Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\'al\-lo-\break m\'as \par}

\vbox{\hsize137pt\parindent0pt\sf\raggedright
  \pretolerance-1
  \hyphenpenalty1
  \exhyphenpenalty2
  \par
  Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\'al\-lo\-m\'as \par}


\bigskip
\hrule
\bigskip

\vbox{\hsize137pt\sf\RaggedRight
  \par
  Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\'al\-lo\-m\'as \par}

\end{document}

相关内容