为什么我的线条断得不正确?

为什么我的线条断得不正确?

我对文档中的换行符感到困惑,我觉得 LaTeX 会随机决定何时正确换行,何时不正确。请参见下面三个块之间的区别。

\documentclass[11pt, oneside, a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{fontspec}
\setmainfont[BoldFont=Calibri, ItalicFont=CalibriLightItalic]{Calibri Light}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage[normalem]{ulem}
\newcommand{\eolyemph}[1]{\textcolor{blue}{\emph{#1}}}
\usepackage[hidelinks]{hyperref}

\begin{document}
\textbf{\underline{This is too long:}}

Code was written with the help of \href{https://tex.stackexchange.com}{\uline{tex.stackexchange.com}} (all hail \emph{StackExchange}). There, many friendly people from the community are helping each other out on all sorts of computer-related problems.

\textbf{\underline{But this is fine:}}

Code was written with the help of \href{https://tex.stackexchange.com}{\uline{tex.stackexchange.com}} (all hail \emph{TexStackExchange}). There, many friendly people from the community are helping each other out on all sorts of computer-related problems.

\textbf{\underline{This works, too:}}

This document was written with the help of \href{https://tex.stackexchange.com}{\uline{tex.stackexchange.com}} (all hail \emph{StackExchange}). There, many friendly people from the community are helping each other out on all sorts of computer-related problems.

\end{document}

为什么它有时候能正常断裂,有时候却不能?


编辑:添加屏幕截图

答案1

其实没什么奇怪的。如果我尝试\showhyphens{StackExchange}回答

Stack-Ex-change

这些是 TeX 唯一愿意断行的点。第一次尝试时,在 之后断行x会产生一行,其中单词之间的空格被拉长很多。在其他两种情况下不会发生这种情况。这是您的代码的略微修改版本(我没有 Calibri Light,但添加一毫米可以\textwidth忠实地重现您的问题),其中在 之后断行的效果x

\documentclass[11pt, oneside, a4paper]{article}

\usepackage{fontspec}
\usepackage[normalem]{ulem}
\usepackage{hyperref}

\setmainfont{Calibri}

\addtolength{\textwidth}{0.1cm}

\begin{document}
\textbf{\underline{This is overfull:}}

Code was written with the help of 
\href{https://tex.stackexchange.com}{\uline{tex.stackexchange.com}} 
(all hail \emph{StackExchange}). There, many friendly people from the community 
are helping each other out on all sorts of computer-related problems.

\textbf{\underline{This is how it would be:}}

Code was written with the help of 
\href{https://tex.stackexchange.com}{\uline{tex.stackexchange.com}} 
(all hail \emph{StackEx-\linebreak change}). There, many friendly people from the community 
are helping each other out on all sorts of computer-related problems.

\textbf{\underline{But this is fine:}}

Code was written with the help of 
\href{https://tex.stackexchange.com}{\uline{tex.stackexchange.com}} 
(all hail \emph{TexStackExchange}). There, many friendly people from the community 
are helping each other out on all sorts of computer-related problems.

\textbf{\underline{This works, too:}}

This document was written with the help of 
\href{https://tex.stackexchange.com}{\uline{tex.stackexchange.com}} 
(all hail \emph{StackExchange}). There, many friendly people from the community 
are helping each other out on all sorts of computer-related problems.

\end{document}

在此处输入图片描述

TeX 不会生成非常糟糕的行,而是倾向于输出过满的行并发出警告,这样您就可以检查有问题的段落并重新措辞以使其适合。

然而,添加microtype可能会非常有帮助。

\documentclass[11pt, oneside, a4paper]{article}

\usepackage{fontspec}
\usepackage[normalem]{ulem}
\usepackage{microtype}
\usepackage{hyperref}

\setmainfont{Calibri}

\addtolength{\textwidth}{0.1cm}

\begin{document}
\textbf{\underline{This is acceptable:}}

Code was written with the help of 
\href{https://tex.stackexchange.com}{\uline{tex.stackexchange.com}} 
(all hail \emph{StackExchange}). There, many friendly people from the community 
are helping each other out on all sorts of computer-related problems.


\microtypesetup{protrusion=false,expansion=false}

\textbf{\underline{This is how it would be without microtype:}}

Code was written with the help of 
\href{https://tex.stackexchange.com}{\uline{tex.stackexchange.com}} 
(all hail \emph{StackEx-\linebreak change}). There, many friendly people from the community 
are helping each other out on all sorts of computer-related problems.

\end{document}

在此处输入图片描述

相关内容