![使用自定义命令时如何修复水平盒子未满的问题?](https://linux22.com/image/418435/%E4%BD%BF%E7%94%A8%E8%87%AA%E5%AE%9A%E4%B9%89%E5%91%BD%E4%BB%A4%E6%97%B6%E5%A6%82%E4%BD%95%E4%BF%AE%E5%A4%8D%E6%B0%B4%E5%B9%B3%E7%9B%92%E5%AD%90%E6%9C%AA%E6%BB%A1%E7%9A%84%E9%97%AE%E9%A2%98%EF%BC%9F.png)
我写了一个小命令,这样我就不必继续创建minipage
s。该命令定义如下:
\newcommand{\itemimage}[3][]{%
\begin{minipage}{\linewidth}
\item #2
\centering
\includegraphics[#1]{#3}
\end{minipage}
}%
每次我使用这个功能时,它似乎都会生成一个警告,“段落中的 \hbox(badness 10000)未满”
\begin{enumerate}[topsep=0pt]
%...
\itemimage[width=300px]{This is just some text.}{img001.png}
%...
\end{enumerate}
但是,如果我不使用该命令,而是使用该命令,则不会生成任何警告。
\begin{enumerate}[topsep=0pt]
%...
\begin{minipage}{\linewidth}
\item This is just some text.
\centering
\includegraphics[width=300px]{img001.png}
\end{minipage}
%...
\end{enumerate}
我的命令中缺少什么\itemimage
来防止这些警告发生?
最小示例:
\documentclass[letterpaper,12pt]{extreport}
\usepackage{mathtools}
\usepackage{enumitem}
\edef\restoreparindent{\parindent=\the\parindent\relax}
\usepackage{parskip}
\restoreparindent
\newcommand{\itemimage}[3][]{%
\begin{minipage}{\linewidth}
\item #2
\centering
\includegraphics[#1]{#3}
\end{minipage}
}%
\begin{document}
\begin{sloppypar}
\begin{enumerate}[topsep=0pt]
\itemimage[width=300px]{This is just some text.}{img001.png}
\begin{minipage}{\linewidth}
\item This is just some text.
\centering
\includegraphics[width=300px]{img001.png}
\end{minipage}
\end{enumerate}
\end{sloppypar}
\end{document}
答案1
不要忘记省略行尾的空格,您生成的行只有一个单词空格,该空格无法延伸以填充该行,因此会出现未满的框。(请注意,您可以example-image
在示例中使用,因为这些图像是为此类测试而分发的)
\documentclass[letterpaper,12pt]{extreport}
\usepackage{mathtools}
\usepackage{enumitem}
\edef\restoreparindent{\parindent=\the\parindent\relax}
\usepackage{parskip}
\restoreparindent
\newcommand{\itemimage}[3][]{%
\begin{minipage}{\linewidth}
\item #2
\centering
\includegraphics[#1]{#3}
\end{minipage}%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}%
\begin{document}
\begin{sloppypar}
\begin{enumerate}[topsep=0pt]
\itemimage[width=300px]{This is just some text.}{example-image.png}
\begin{minipage}{\linewidth}
\item This is just some text.
\centering
\includegraphics[width=300px]{example-image.png}
\end{minipage}
\end{enumerate}
\end{sloppypar}
\end{document}