除了添加换行符之外,真的没有更好的方法来解决“Overfull \hbox”问题吗?

除了添加换行符之外,真的没有更好的方法来解决“Overfull \hbox”问题吗?

我正在阅读一本相当长的书来解决 Overfull \hbox 问题。以下是一个例子:

varies greatly from organization to organization, team to team, and
manager to manager. Innovation is exceptional only because so many <<<<this too long
organizations fail to act on and to capture the benefit of good ideas.

“many”这个词不能用连字符连接,而且它报告说这一行是0.77357pt too wide——数量太少了。我真的只想让它把它换到下一行——这个词不是很大,而且额外的空白也没什么。文档(https://texfaq.org/FAQ-overfull) 表示添加换行符,如下所示:

varies greatly from organization to organization, team to team, and
manager to manager. Innovation is exceptional only because so \linebreak
many organizations fail to act on and to capture the benefit of good ideas.

通过在其中放置一个硬换行符,它会将其换行。但是稍后,如果我编辑该作品前面的段落,它可能不再需要换行符,但硬换行符无论如何都会导致它这样做。如果段落发生变化,以至于它不再位于行的最右边缘,那么我不想在那时换行。我该怎么办?

有没有办法说“如果它会导致溢出,则将这个词包装起来,否则正常包含它”???

“many”这个词其实不算长。我不介意在特定情况下特别标记个别单词,但\linebreak无论我是否需要,使用 permanent 都会导致换行。我希望它仅在出现溢出情况时才换行。

另一个解决方案是增加\pretolerance值。我怎么知道现在的值是多少?我需要知道这个,这样我才能将它设置为稍高的值。有没有办法将它增加 10%。像“many”这样的词并不是特别长的作品,我有很多这样的问题。我希望它能自动处理这些情况。

更新

以下是显示该问题的 MWE:

\documentclass[paper=6in:9in,10pt,twoside,pagesize=pdftex,openright,headings=twolinechapter,chapterprefix=true]{scrbook}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{xcolor}
\usepackage{makeidx}
\makeindex
\voffset=0in
\topmargin = 0in
\headheight = 12pt
\headsep = 25pt
\textheight = 7in
\footskip = 30pt
\hoffset=0in
\marginparwidth = 0pt
\marginparsep = 0pt
\textwidth = 4.5in
\oddsidemargin = 0pt
\marginparpush = 0pt
\usepackage[inner=0.75in,outer=0.75in,top=1.0in, bottom=1.0in, footnotesep=.4in]{geometry}
\usepackage{fontspec}
\fontspec{Alegreya Sans SC Light}
\fontspec{Palatino Linotype}
\setmainfont[Ligatures={Common,TeX}, Numbers={OldStyle}]{Palatino Linotype}
\linespread{1.05}         % Palatino needs more leading (space between lines)
\addtokomafont{footnote}{\footnotesize\sffamily}
\deffootnote{1.5em}{1em}{% modified example from page 83
  \makebox[1.5em][l]{\textsuperscript{\thefootnotemark}}}
\renewcommand*\chapterheadstartvskip{\vspace*{.1\textheight}}
\renewcommand*\chapterheadendvskip{\vspace*{.1\textheight}}
\addtokomafont{chapter}{\fontspec{Alegreya Sans SC Light}}
\addtokomafont{chapterprefix}{\fontspec{Alegreya Sans SC Light}\Huge}
\addtokomafont{chapterprefix}{\raggedleft}
\renewcommand*{\chapterformat}{%
   \mbox{\scalebox{1}{\chapappifchapterprefix{\nobreakspace}}%
   \scalebox{4}{\color{gray}\thechapter}\enskip}}
\pdfpagewidth=\paperwidth
\pdfpageheight=\paperheight
\begin{document}
\frontmatter
\title{Innovation Management Challenge}
\author{Keith D Swenson, Jim Farris}
\date{\today}
\maketitle
\tableofcontents
\mainmatter
\chapter{Innovation Management Challenge}
\section{Innovators}
\begin{itemize}
\item Innovation Everywhere - Surprisingly, innovation is both exceptional and commonplace.  Good ideas are the product of intelligence, and all people at all levels are intelligent.  The ability to act on good ideas varies greatly from organization to organization, team to team, and manager to manager.   Innovation is exceptional only because so many organizations fail to act on and to capture the benefit of good ideas.
\end{itemize}
\end{document}

搜索过多的 \hbox 建议,大多数示例都是关于连字的。如果是连字问题,我可以手动将 放在\-所需位置并强制连字。这个例子很不寻常,因为这个单词many只有 4 个字母,永远不会被拆分。它很短。整个单词需要转到下一行。出于这个原因,我\hyphenate{}什么也做不\-了。

我尝试使用\sloppy有效的方法(意味着单词被包裹下来并且相关段落看起来不错),但却引起了旁观者的厌恶,他们说这根本“不应该这样做”。

有人建议尝试一下\linebreak[3],显然这意味着这是一种并不总是会中断的换行符,但具体何时以及为什么会中断的规则尚不清楚。是否只有当它后面的工作将一小部分点插入边距时才会中断?我没有尝试,因为完全不清楚这会在我想要时中断,而在单词合适时不会中断。

我尝试过\usepackage{microtype},但没有任何效果...单词many仍然停留在行尾,并且溢出了水平盒子。

我试过了\setlength{\emergencystretch}{2pt},效果很好。显然紧急拉伸默认为 0。当遇到过满的情况时,如果如果紧急拉伸大于 0,则它会放宽该行的要求,并允许稍微大一点的单词向下换行。这可能是最好的解决方案,但我仍然很好奇为什么像“many”这样的小单词首先需要如此特殊的处理。

有人告诉我\begin{sloppypar}\end{sloppypar}你把段落放在了外面,这样整个文档就不会受到混乱格式的影响。当其他方法似乎都行不通时,这至少是一种解决单点问题的方法。

我收到了一条关于更改可打印区域确定方式的长回复。这是个好建议,但并没有解决根本问题:为什么像“many”这样的短单词没有被换行到下一行,而它却延伸到了边距的 0.78 点。

在我看来,换行算法完全是错误的。有人说这可能是字体问题,但有人知道如何证明这一点吗?如何获取驱动换行算法的设置的当前值,以显示临界值太小(小于单词“many”的长度)

答案1

还有很多更好的解决方案。以下是一些简短的建议。

  1. 每行增加字符数是最简单的解决方案之一。每行应以 60 个字符为起点。例如,超过 70 个字符可以极大地改善段落的外观。

  2. 如果您可以容忍偶尔出现的过长空格,则可\sloppy解决大部分问题。 \sloppy意思是\tolerance 9999 \emergencystretch 3em\relax,因此可以接受非常丑陋的段落。 因此,它更适合局部使用,例如固定段落。

  3. 如果你可以使用pdftex,而不是原始的TeX引擎,那么封装microtype是一个非常好的解决方案。

答案2

这是对您更新的问题中提出的具体问题的回答,即现在我们有了 MWE。

首先,您是否要使用 KOMA?在我看来,如果您不同意手册第 2 章中列出的设计原则 - 或者如果您不被允许遵守这些原则 - 那么最好选择另一个类。这些原则是 KOMA 存在的理由,老实说,如果有人不想或多或少地按照这些原则来布局他们的文档,我不明白为什么他们会使用该类。当然,这并不是说这做不到。显然这是可以做到的。相反,我认为结果会更差,制作文档的过程会更加痛苦。

其次,您的序言使用了三种相互竞争(因此是冲突的)的方法来指定和计算页面尺寸:

  • typearea,加载者scrbook
  • 手册规格\setlength
  • geometry

挑选。显然,这与第一点有关,因为如果您使用scrbook,您就不得不加载typearea。因此,如果您更喜欢其他方法之一,我认为您应该重新考虑您的课程选择。

第三,内边距和外边距相等。这在双面文档中是不常见的,因为当打开书时,中间的空白将是文本块左右两边空白的两倍宽。但是,装订可能需要额外的宽度。我假设这里的情况就是这样。

以下代码近似于 3/4" 水平边距规范。两个规范对此负责。一个是BCOR将绑定偏移量设置为 3/4" 的一半的值。另一个是DIV将内容排列为外边距为 3/4" 且内边距等于绑定偏移量的值。当包含偏移量时,这会产生 3/4" 的总内边距。(也就是说,水平布局应该与您的大致相同。)

typearea然后根据第 2 章中解释的公式计算剩余的页面尺寸。这方面有变化 - 有关详细信息,请参阅文档。

然而,行距的改变会削弱这些计算的有效性。特别是,它可能导致文本块高度的行数不为整数。因此,要求 KOMA 在行距改变后重新进行计算。

我假设您希望根据拼写使用美式连字符模式。如果不是,请用 代替britishamerican我在这里使用了babel,但您可能更喜欢,polyglossia因为您使用的是 XeTeX。(在这种情况下,不需要添加babel来消除过满的框,但总的来说,它会给您带来更好的结果。)

\documentclass[paper=6in:9in,BCOR=9.5mm,DIV=14,10pt,twoside,pagesize=pdftex,openright,headings=twolinechapter,chapterprefix=true,american]{scrbook}
\usepackage{babel}
\usepackage{xcolor}
\usepackage{fontspec}
\setmainfont[Ligatures={Common,TeX}, Numbers={OldStyle}]{Palatino Linotype}
\linespread{1.05}%  Palatino needs more leading (space between lines)
\KOMAoptions{DIV=last}% make sure that an integer number of lines fits in the text block (p 35); this is necessary because the leading has been changed
\addtokomafont{footnote}{\footnotesize\sffamily}
\deffootnote{1.5em}{1em}{% modified example from page 83
  \makebox[1.5em][l]{\textsuperscript{\thefootnotemark}}}
\renewcommand*\chapterheadstartvskip{\vspace*{.1\textheight}}
\renewcommand*\chapterheadendvskip{\vspace*{.1\textheight}}
\addtokomafont{chapter}{\fontspec{Alegreya Sans SC Light}}
\addtokomafont{chapterprefix}{\fontspec{Alegreya Sans SC Light}\Huge}
\addtokomafont{chapterprefix}{\raggedleft}
\renewcommand*{\chapterformat}{%
  \mbox{\scalebox{1}{\chapappifchapterprefix{\nobreakspace}}%
    \scalebox{4}{\color{gray}\thechapter}\enskip}}
\begin{document}
  \frontmatter
  \title{Innovation Management Challenge}
  \author{Keith D Swenson, Jim Farris}
  \date{\today}
  \maketitle
  \tableofcontents
  \mainmatter
  \chapter{Innovation Management Challenge}
  \section{Innovators}
  \begin{itemize}
    \item Innovation Everywhere - Surprisingly, innovation is both exceptional and commonplace.  Good ideas are the product of intelligence, and all people at all levels are intelligent.  The ability to act on good ideas varies greatly from organization to organization, team to team, and manager to manager.   Innovation is exceptional only because so many organizations fail to act on and to capture the benefit of good ideas.
  \end{itemize}
\end{document}

使用此代码,我在编译时不会得到任何过满的框。

这是页面尺寸的比较。

首先,在您最初的序言结尾处获得的尺寸:

* driver: xetex
* paper: <default>
* layout: <same size as paper>
* layoutoffset:(h,v)=(0.0pt,0.0pt)
* modes: twoside showframe
* h-part:(L,W,R)=(54.2025pt, 325.215pt, 54.2025pt)
* v-part:(T,H,B)=(72.26999pt, 505.89001pt, 72.26999pt)
* \paperwidth=433.62pt
* \paperheight=650.43pt
* \textwidth=325.215pt
* \textheight=505.89001pt
* \oddsidemargin=-18.06749pt
* \evensidemargin=-18.06749pt
* \topmargin=-37.0pt
* \headheight=12.0pt
* \headsep=25.0pt
* \topskip=10.0pt
* \footskip=30.0pt
* \marginparwidth=0.0pt
* \marginparsep=0.0pt
* \columnsep=10.0pt
* \skip\footins=28.90755pt
* \hoffset=0.0pt
* \voffset=0.0pt
* \mag=1000
* \@twocolumnfalse
* \@twosidetrue
* \@mparswitchtrue
* \@reversemarginfalse
* (1in=72.27pt=25.4mm, 1cm=28.453pt)

现在,修订后的序言末尾获得的值:

* \paperwidth=433.62pt
* \paperheight=650.43pt
* \textwidth=319.4635pt
* \textheight=514.00146pt
* \oddsidemargin=-16.19775pt
* \evensidemargin=-14.18573pt
* \topmargin=-60.46082pt
* \headheight=15.75005pt
* \headsep=18.90005pt
* \topskip=10.0pt
* \footskip=44.10013pt
* \marginparwidth=43.56319pt
* \marginparsep=12.8401pt
* \columnsep=10.0pt
* \skip\footins=9.0pt plus 4.0pt minus 2.0pt
* \hoffset=0.0pt
* \voffset=0.0pt
* \mag=1000
* \@twocolumnfalse
* \@twosidetrue
* \@mparswitchtrue
* \@reversemarginfalse
* (1in=72.27pt=25.4mm, 1cm=28.453pt)

请注意,在这种情况下,文本块实际上略窄,但也略高。垂直布局的其他变化是 KOMA 使用的公式的功能。

我没有包括它,microtype因为在这种情况下,使用默认选项加载它实际上会导致框溢出。这可能是因为默认值不适合 Palatino。可以手动纠正此问题,或者通过检查在为 Palatino 或 TeX-Gyre Pagella 加载标准字体包时使用的值来获得最佳效果。但是,由于此引擎的微排版功能非常有限,因此可能不值得担心。(如果您想要这些功能的好处,最好使用 pdfTeX 或 LuaTeX。)

添加 7 页左右的康德进行测试后,我仍然没有得到任何过满的盒子。

KOMA 设计的书籍

答案3

以下是根据您的其他问题之一给出的示例:

\documentclass[paper=6in:9in,10pt,twoside,pagesize=pdftex,openright]{scrbook}
\usepackage{kantlipsum}

\begin{document}
  \kant[1-20]
\end{document}

这给了我 2 个溢出的框(用于 10 页文本)。而且这个文本中有很多奇怪的康德术语,这可能不是 TeX 连字机制的最佳输入。

对于以下内容,我没有收到过多的抱怨(我认为这大致是您正在使用的类型区域):

\documentclass[paper=6in:9in,DIV=12,10pt,twoside,pagesize=pdftex,openright]{scrbook}
\usepackage{kantlipsum}

\begin{document}
  \kant[1-20]
\end{document}

那是 Computer Modern。这是 Palatino:

\documentclass[paper=6in:9in,DIV=12,10pt,twoside,pagesize=pdftex,openright]{scrbook}
\usepackage{kantlipsum}
\usepackage{tgpagella}

\begin{document}
  \kant[1-20]
\end{document}

仍然没有满箱。

添加

\usepackage{microtype}

将提高输出质量并有助于避免框过满,尽管它不完全支持/不完全支持 XeTeX。(它最大程度地支持/支持 pdfTeX,并且对 LuaTeX 有很大支持,但在最坏的情况下,它仍然会有所帮助并且不会造成伤害。)

我认为,使用babel适当的选项或polyglossia将确保加载正确的连字模式并帮助 TeX 找到合适的连字点。

如果您收到很多这样的信息,并且您没有排版窄列文本,那么肯定有问题。由于我在您的任何问题(我检查过的问题)中都找不到 MWE,因此当然不可能说太多。这就是 MWE 如此重要的原因。

相关内容