我在一个环境中有一些文本\texttt
,事实证明,乳胶在这些环境中有时会正确地断行,有时则不会。
一个最小工作示例
\documentclass{scrartcl}
\begin{document}
\section{Test}
This is some text text and even more text \texttt{and some variable names which are written in typewriter font
\end{document}
还有一个不工作的(导致过满\hbox
)
\documentclass{scrartcl}
\begin{document}
\section{Test}
This is some text text and even more text \texttt{and some variable names which are writtenin typewriter font}
\end{document}
好像如果行末的单词太长,LaTeX 就无法设置正确的换行符?我发现了 中一些类似的换行符问题\texttt
,但问题总是出在 中没有空格\texttt
,这肯定不是这里的问题。
有办法解决这个问题吗?
答案1
LaTeX 不支持 tt 字体连字符,这使得设置段落变得困难。
您可以使用sloppypar
允许空白进一步延伸来进行补偿,或者您可以重置 tt 字体的连字符(这是一个全局更改,会影响文档其余部分的 tt)。
\documentclass{scrartcl}
\begin{document}
\section{Test1}
This is some text text and even more text \texttt{and some variable names which are writtenin typewriter font}
\section{Test2}
\begin{sloppypar}
This is some text text and even more text \texttt{and some variable names which are writtenin typewriter font}
\end{sloppypar}
\section{Test3}
{{\ttfamily \hyphenchar\the\font=`\-}%
This is some text text and even more text \texttt{and some variable names which are writtenin typewriter font}\par}
\end{document}
答案2
由于 LaTeX 不会对以“电传打字机”字体(又称打字机字体、等宽字体)排版的单词进行连字符处理,因此您可能需要放弃对相关段落进行完全对齐。相反,您可能希望以\raggedright
模式排版。为了将本地范围限制\raggedright
在一个段落内,请务必将其括在花括号中,并确保\par
在结束花括号之前插入。
\documentclass{scrartcl}
\begin{document}
\section{Test}
{\raggedright
This is some text text and even more text \texttt{and some variable names
which are writtenin typewriter font}.
\par}
\end{document}