更改字体后,如何修复坏框过满 \hbox?

更改字体后,如何修复坏框过满 \hbox?

我正在尝试创建一个环境,让我可以更改字体来表示一种算法,但出现了 Bad Box overfull \hbox 错误。

梅威瑟:

\documentclass{article}
\usepackage{enumerate, lipsum}

\newenvironment{aparts}{\begin{enumerate}[{(}a{)}]}{\end{enumerate}}

\newenvironment{algo}[3] % function name and parameters, input, output
{
\fontfamily{cmtt}\selectfont

\underline{#1}

Input: #2

Output: #3

\bigskip
}
{\bigskip}

\textheight=9in
\textwidth=6.5in
\topmargin=-.75in
\oddsidemargin=0.25in
\evensidemargin=0.25in

\begin{document}

\begin{aparts}

\item
{\fontfamily{cmtt}\selectfont

\underline{function eval(a[$a_0, a_1, ..., a_n$], x)}

Input: An array of constant coefficients a[$a_0, a_1, ..., a_n$] and a quantity to plug into the polynomial expression determined by the coefficients x

Output: The solution to the polynomial expression determined by the coefficients when x is plugged in as the variable

\bigskip

$p = a_0$

if $i >= 1$:

    \quad for $i = n$ to 1:
    
        \qquad $p = p + a_i$
        
         \qquad $p = p * x$
    
return $p$
}

\bigskip

\item
{\fontfamily{cmtt}\selectfont

\underline{function eval(a[$a_0, a_1, ..., a_n$], x)}

Input: An array of constant coefficients a[$a_0, a_1, ..., a_n$] and a quantity to

\quad plug into the polynomial expression determined by the coefficients x

Output: The solution to the polynomial expression determined by the

\quad coefficients when x is plugged in as the variable

\bigskip

$p = a_0$

if $i >= 1$:

    \quad for $i = n$ to 1:
    
        \qquad $p = p + a_i$
        
        \qquad $p = p * x$
    
return $p$
}

\bigskip

\item

\begin{algo}{function eval(a[$a_0, a_1, ..., a_n$], x)}
{An array of constant coefficients a[$a_0, a_1, ..., a_n$] and a quantity to plug into the polynomial expression determined by the coefficients x}
{The solution to the polynomial expression determined by the coefficients when x is plugged in as the variable}

$p = a_0$

if $i >= 1$:

    \quad for $i = n$ to 1:
    
        \qquad $p = p + a_i$
        
         \qquad $p = p * x$
    
return $p$

\end{algo}

\item
\lipsum[50]

\end{aparts}

\end{document}

我收到以下错误:

段落第 35-36 行的 \hbox 过满(4.20915pt 太宽)[]\OT1/cmtt/m/n/10 输入:常数系数数组 a[$\OML/cmm/m/it/10 a[]; a[]; :::; a[]$\OT1/cmtt/m/n/10 ] 以及要插入到 [] 中的数量

段落第 37-38 行的 \hbox 超满(太宽了 10.0188pt) []\OT1/cmtt/m/n/10 输出:当 x [] 时,由系数确定的多项式表达式的解

段落第 88-88 行的 \hbox 过满(4.20915pt 太宽)[]\OT1/cmtt/m/n/10 输入:常数系数数组 a[$\OML/cmm/m/it/10 a[]; a[]; :::; a[]$\OT1/cmtt/m/n/10 ] 以及要插入 [] 的数量

段落第 88-88 行的 \hbox 超满(太宽 10.0188pt) []\OT1/cmtt/m/n/10 输出:当 x [] 时,由系数确定的多项式表达式的解

如您所见,第一个方法不起作用,但我通过强制换行解决了这个问题。当然,我不想每次都这样做,如果我把它放在环境的参数中,那就更烦人了。此外,我认为这与字体有关的原因是常规文本看起来很难找,如 (d) 所示。

我该如何解决这个问题?非常感谢。

相关内容