我创建了一个文档,但遇到了问题。文本应该完全左右对齐,而且大部分内容也确实如此。但是,文档中有几次文本超出了右边距。我该如何告诉 LaTeX(或者更具体地说是 XeLaTeX)这不正常?
答案1
这个例子
我可以重现您的示例(使用不同的字体,但无关紧要):
\documentclass{article}
\usepackage[textwidth=7.6in]{geometry}
\usepackage{mathpazo}
\begin{document}
A review of relevant literature indicates that researchers are evaluating
the four factors identified previously using experiment-based empirical
trials (Nunamaker et al.\ 2011). While these efforts yield critical insights,
experiment participants tasked with deceiving and avoiding detection likely
have no knowledge of the system that they are encountering. Consequently,
these experiments often lack elements of ecological validity as the adoption
and use of such a system publicly would mean that potential interviewees
would possess knowledge concerning its capabilities. Interviewees with
knowledge of the system can then attempt to avoid detection by employing
strategic behaviors designed to mitigate specific technologies and sensors
used by the system; these behaviors are often referred to as
countermeasures.
\end{document}
问题分析
TeX 不会对带有连字符的单词进行连字符处理,除非在连字符本身(复合词)处。虽然这看起来很糟糕,但实际上却很好:拆分组合词需要判断以避免歧义。自由连字符命令\-
可以提供帮助。
补救
等到文档的文本定稿后,\-
在需要的地方添加任意连字符会更容易。如果行数较多,应该只有少数情况需要注意。在这种情况下,我会尝试使用
基于实验
但要避免在 后面使用随意连字符ex
。
\documentclass{article}
\usepackage[textwidth=7.6in]{geometry}
\usepackage{mathpazo}
\begin{document}
A review of relevant literature indicates that researchers are evaluating
the four factors identified previously using experi\-ment-based empirical
trials (Nunamaker et al.\ 2011). While these efforts yield critical insights,
experiment participants tasked with deceiving and avoiding detection likely
have no knowledge of the system that they are encountering. Consequently,
these experiments often lack elements of ecological validity as the adoption
and use of such a system publicly would mean that potential interviewees
would possess knowledge concerning its capabilities. Interviewees with
knowledge of the system can then attempt to avoid detection by employing
strategic behaviors designed to mitigate specific technologies and sensors
used by the system; these behaviors are often referred to as
countermeasures.
\end{document}
如何知道连字点?
有几种方法。最简单的方法是放置
\showhyphens{experiment}
在文档底部,就在 之前\end{document}
;然后你会在文件中找到这个.log
:
Underfull \hbox (badness 10000) in paragraph at lines 18--18
[] \OT1/ppl/m/n/10 ex-per-i-ment
该Underfull \hbox
消息是由于\showhyphens
命令的工作方式(它故意构建一个未满的框,将显示可能的连字符)。所以我们知道在美式英语中连字符点应该是
ex-per-i-ment
不过,连字算法并非万无一失,所以如果有疑问,也许查一下字典会更好。牛津词典中的 AmEn 确实给出了ex|per|i|ment
或者,在文档中的某处键入内容(结尾是好的)
\parbox{0pt}{\hspace{0pt}experiment}
你会得到
因为 TeX 会尽力避免框过满,但它无法在 0pt 内容纳单词。
自动解决方案
有自动解决方案,但我不推荐它们。例如,请参阅 cfr 的答案这里。在英语中,这个问题很少见。如果您想要更好的解决方法,请看最后。
另一种可能性是使用复合词命令,比如
\newcommand{\comp}{\hspace{0pt}\nolinebreak-\hspace{0pt}}
然后输入
experiment\comp based
你会得到
您可能\comp
希望使用babel
简写;请参阅babel:将德语简写添加到英语作为主要文档语言但结果并不完全在控制范围内。例如,experiment-related
你可能会得到
实验相关
这比盒子太满更糟糕。
一般建议
加载microtype
包,效果很好;例如,与之前相同的文档
\documentclass{article}
\usepackage[textwidth=7.6in]{geometry}
\usepackage{microtype}
\usepackage{mathpazo}
\begin{document}
A review of relevant literature indicates that researchers are evaluating
the four factors identified previously using experiment-based empirical
trials (Nunamaker et al.\ 2011). While these efforts yield critical insights,
experiment participants tasked with deceiving and avoiding detection likely
have no knowledge of the system that they are encountering. Consequently,
these experiments often lack elements of ecological validity as the adoption
and use of such a system publicly would mean that potential interviewees
would possess knowledge concerning its capabilities. Interviewees with
knowledge of the system can then attempt to avoid detection by employing
strategic behaviors designed to mitigate specific technologies and sensors
used by the system; these behaviors are often referred to as
countermeasures.
\end{document}
会给
无需任何干预。加载microtype
肯定会最大限度地减少最终修订过程中的手动更正。
最后的建议:在文件定稿之前,不要担心这些问题。措辞的改变很可能会破坏解决箱子过满问题的工作,并且根据墨菲定律,会产生其他问题。
答案2
对我来说,解决方案是在序言中调用\sloppy
。我远不是 LaTeX 专家,我无法解释为什么这样做有效。