在同一行中如何處理“underfull \hbox”和“overfull \hbox”?

在同一行中如何處理“underfull \hbox”和“overfull \hbox”?

我最近仔細閱讀了我的\jobname.log文件以發現排版錯誤。

我遇過這個:

Overfull \hbox (6.8925pt too wide) in paragraph at lines 650--651
[][]\T1/cmtt/m/n/10 plot([][][]<functie>[], []col=<kleur>[], []lwd=<breedte van
 de geplotte lijn>[], []type=<type plot,
 []


Underfull \hbox (badness 10000) in paragraph at lines 650--651
\T1/cmtt/m/n/10 zie hierboven>[], []xlab="<eenheid op de x-as>"[], []ylab="<een
heid op de y-as>"[], []main=[]
 []

在文件中,文件的這一部分看起來像

這個(連結)

在這種情況下,我有三個選擇:

  1. 使用\linebreak 的一部分\textcolor{orange}{main=...
  2. 在(當前解決方案)\linebreak中間使用。main=...
  3. 不要使用任何換行符。

所有三種解決方案都會產生 hbox 未滿和過滿的訊息。

有沒有辦法鼓勵 LaTeX 在環境中進行換行以修復至少一個這些錯誤?或縮放文字、調整字元框等。

我已經閱讀了現有的問題,它們都建議換行。在這種環境下,這可能要求太多,但我至少想探索在特殊情況下解決此問題的可能性(如果有這樣的特殊解決方案 - 祈禱)。

答案1

這是因為打字機字體 ( \ttfamily) 沒有任何字間拉伸或收縮。因此,它通常不能很好地獲得合理的外觀。 Stefan 在 TeXblog 上寫了一篇不錯的部落格文章:帶有打字機字體的完整理由。為了完整起見,我將在這裡重複討論:

在此輸入影像描述

\documentclass[a4paper,10pt]{article}
\renewcommand*\familydefault{\ttdefault}
\begin{document}
\begin{description}
  \item[slant] \the\fontdimen1\font
  \item[inter-word space] \the\fontdimen2\font
  \item[inter-word stretch] \the\fontdimen3\font
  \item[inter-word shrink] \the\fontdimen4\font
  \item[extra space] \the\fontdimen7\font
  \item[xspaceskip] \the\xspaceskip
  \item[hyphenchar] \the\hyphenchar\font
\end{description}
\end{document}

注意0.0pt詞間的伸縮。

建議添加一些字間拉伸/收縮,並且您可能通常希望針對lines程式碼螢幕截圖中的環境執行此操作。但是,如果您不了解如何lines編寫,我只能建議您將以下內容添加到環境的開頭:

\fontdimen3\font=0.2em% inter-word stretch
\fontdimen4\font=0.1em% inter-word shrink

或許還可以嘗試價值觀。

答案2

\documentclass{article}
\usepackage[english]{babel}
\usepackage{geometry,blindtext}
\usepackage{everysel}
\renewcommand*\familydefault{\ttdefault}
\begin{document}
\section{Default typesetting}
\blindtext

\section{With hyphenation}
\hyphenchar\font=`\-% to allow hyphenation
\blindtext

\section{With hyphenation and justification}
%\EverySelectfont{%
\fontdimen2\font=0.4em% interword space
\fontdimen3\font=0.2em% interword stretch
\fontdimen4\font=0.1em% interword shrink
\fontdimen7\font=0.1em% extra space
%\hyphenchar\font=`\-% to allow hyphenation
%}
\blindtext
\end{document}

在此輸入影像描述

相關內容