我写了一个小命令,这样我就不必继续创建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}