防止 LaTeX 阻止连字

防止 LaTeX 阻止连字

所以我知道,在排版中,避免在换行符处出现连字符的一种常用技巧是稍微调整单词和字母的间距。直到今天我才知道 LaTeX 会这样做,但现在它给我带来了麻烦。

编辑:添加标签后,我发现这种字母间距现象被称为“跟踪”。

我正在写一份家庭作业,其部分内容如下:

\textbf{a.} \hspace{5 pt} {\color{NavyBlue} Does the above tweak work? If yes, then 
prove it, if not, then provide a counter example.}

\textbf{b.} \hspace{5 pt} {\color{NavyBlue} Implement the above version of the Bakery
algorithm in Java, and dependent on your answer to part (a) either show a set of 
(say 4) threads reciting the declaration of independence cohesively, or else not.}

问题在于“Does”和“Implement”彼此不对齐,因为看起来我上面提到的间距问题将“Implement”的位置推得更靠前了。以下是屏幕截图:

在此处输入图片描述

是否有一个命令可以用来允许连字符而不是调整间距,以便开头正确排列?

以下是 MWE:

\documentclass[a4 paper,11pt]{article}
\usepackage{amsmath, amsfonts, amssymb, parskip, dsfont, amsthm, wasysym, mathrsfs}
\usepackage{graphicx}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{mathrsfs}
\usepackage[normalem]{ulem}
\usepackage[breaklinks=true]{hyperref}
\usepackage{soul, color} % for highlighting
\usepackage{pifont} % for cool symbols in text mode
\usepackage{changepage} % for block quotes -- \begin{addmargin}[left][right]

\begin{document}

\textbf{a.} \hspace{5 pt} {\color{NavyBlue} Does the above tweak work? If yes, then 
prove it, if not, then provide a counter example.}

\textbf{b.} \hspace{5 pt} {\color{NavyBlue} Implement the above version of the Bakery
algorithm in Java, and dependent on your answer to part (a) either show a set of 
(say 4) threads reciting the declaration of independence cohesively, or else not.}

\end{document}

答案1

LaTeX 是连字符。问题是您在 enumerate 的开头为 LaTeX 提供了空格,该空格可以拉伸(默认空格)。删除开头的空格,问题就解决了。顺便说一句,如果 LaTeX 不认识该单词或者您想要不同的断字符,您可以使用\-例如ans\-wer

\documentclass[a4 paper,11pt]{article}
\usepackage{amsmath, amsfonts, amssymb, parskip, dsfont, amsthm, wasysym, mathrsfs}
\usepackage{graphicx}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{mathrsfs}
\usepackage[normalem]{ulem}
\usepackage[breaklinks=true]{hyperref}
\usepackage{soul, color} % for highlighting
\usepackage{pifont} % for cool symbols in text mode
\usepackage{changepage} % for block quotes -- \begin{addmargin}[left][right]

\begin{document}

\textbf{a.}\hspace{5pt}{\color{NavyBlue}Does the above tweak work? If yes, then 
prove it, if not, then provide a counter example.}

\textbf{b.}\hspace{5pt}{\color{NavyBlue}Implement the above version of the Bakery
algorithm in Java, and dependent on your ans\-wer to part (a) either show a set of 
(say 4) threads reciting the declaration of independence cohesively, or else not.}

\end{document}

在此处输入图片描述

答案2

最好使用enumerate列表来完成你正在做的事情。

如果要重现完全相同的输出,请加载enumitem并使用以下设置

leftmargin=0pt,align=left,labelsep=10pt,itemindent=*,label={\bfseries\alph*.}

梅威瑟:

\documentclass[a4 paper,11pt]{article}
\usepackage{amsmath, amsfonts, amssymb, parskip, dsfont, amsthm, wasysym, mathrsfs}
\usepackage{graphicx}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{mathrsfs}
\usepackage[normalem]{ulem}
\usepackage[breaklinks=true]{hyperref}
\usepackage{soul, color} % for highlighting
\usepackage{pifont} % for cool symbols in text mode
\usepackage{changepage} % for block quotes -- \begin{addmargin}[left][right]

\usepackage{enumitem}

\begin{document}

\noindent Your output

\textbf{a.} \hspace{5 pt} {\color{NavyBlue} Does the above tweak work? If yes, then
prove it, if not, then provide a counter example.}

\textbf{b.} \hspace{5 pt} {\color{NavyBlue} Implement the above version of the Bakery
algorithm in Java, and dependent on your answer to part (a) either show a set of
(say 4) threads reciting the declaration of independence cohesively, or else not.}

\bigskip
\noindent Output with \texttt{enumerate}

\begin{enumerate}[leftmargin=0pt,align=left,labelsep=10pt,itemindent=*,label={\bfseries\alph*.}]
\item  {\color{NavyBlue} Does the above tweak work? If yes, then
prove it, if not, then provide a counter example.}

\item  {\color{NavyBlue} Implement the above version of the Bakery
algorithm in Java, and dependent on your answer to part (a) either show a set of
(say 4) threads reciting the declaration of independence cohesively, or else not.}
\end{enumerate}

\end{document} 

输出:

在此处输入图片描述

答案3

仅使用该enumitem包似乎可以解决问题:

在此处输入图片描述


如果不使用enumerate类型环境,您可以使用来\mbox确保获得一致的间距 - 尽管我不推荐这样做:

在此处输入图片描述


代码:\enumitem

\documentclass[a4 paper,11pt]{article}
\usepackage{amsmath, amsfonts, amssymb, parskip, dsfont, amsthm, wasysym, mathrsfs}
\usepackage{graphicx}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{mathrsfs}
\usepackage[normalem]{ulem}
\usepackage[breaklinks=true]{hyperref}
\usepackage{soul, color} % for highlighting
\usepackage{enumitem}
\begin{document}

\begin{enumerate}[label={\bfseries\alph*.}]
\item {\color{NavyBlue} Does the above tweak work? If yes, then 
prove it, if not, then provide a counter example.}

\item {\color{NavyBlue} Implement the above version of the Bakery
algorithm in Java, and dependent on your answer to part (a) either show a set of 
(say 4) threads reciting the declaration of independence cohesively, or else not.}
\end{enumerate}
\end{document}

代码:\mbox

\documentclass[a4 paper,11pt]{article}
\usepackage{amsmath, amsfonts, amssymb, parskip, dsfont, amsthm, wasysym, mathrsfs}
\usepackage{graphicx}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{mathrsfs}
\usepackage[normalem]{ulem}
\usepackage[breaklinks=true]{hyperref}
\usepackage{soul, color} % for highlighting
\usepackage{pifont} % for cool symbols in text mode
\usepackage{changepage} % for block quotes -- \begin{addmargin}[left][right]

\begin{document}

\mbox{\textbf{a.}\hspace{5 pt}}{\color{NavyBlue} Does the above tweak work? If yes, then 
prove it, if not, then provide a counter example.}

\mbox{\textbf{b.}\hspace{5 pt}}{\color{NavyBlue} Implement the above version of the Bakery
algorithm in Java, and dependent on your answer to part (a) either show a set of 
(say 4) threads reciting the declaration of independence cohesively, or else not.}

\end{document}

答案4

只是想补充@Tahtisilma 的答案,您还可以使用它\hyphenation{wo-rd, w-ord}来手动设置文档中特定单词的连字模式。

此外,将表现得好像打印了“word”,但实际上并非如此。这是一个很棒的小技巧,可用于在无效的\phantom{word}地方对间距进行最后的微调(注意:在此特定情况下无效)。\hspace{}

但是,大多数情况下我建议使用定义的环境(如枚举)并且不要尝试覆盖 *tex,除非您有特殊的原因。

相关内容