0

I've written a small command so that I don't have to keep creating minipages. The command is defined as such:

\newcommand{\itemimage}[3][]{%
    \begin{minipage}{\linewidth}
        \item #2
        
        \centering
        \includegraphics[#1]{#3}
    \end{minipage}
}%

Any time I use this, it seems to generate a warning for "Underfull \hbox (badness 10000) in paragraph"

\begin{enumerate}[topsep=0pt]
    %...
    \itemimage[width=300px]{This is just some text.}{img001.png}
    %...
\end{enumerate}

However, if I don't use the command, and instead use what the command is, then no warning is generated.

\begin{enumerate}[topsep=0pt]
    %...
    \begin{minipage}{\linewidth}
        \item This is just some text.
        
        \centering
        \includegraphics[width=300px]{img001.png}
    \end{minipage}
    %...
\end{enumerate}

What am I missing from my \itemimage command to prevent these warnings from occurring?

Minimal example:

\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}

Code & Warning

4
  • 1
    Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code.
    – user30471
    Commented Jul 30, 2020 at 20:07
  • Hi @Andrew, sorry about that, I've included a working example to reproduce the issue.
    – ChrisMM
    Commented Jul 30, 2020 at 20:14
  • Your MWE gives two overfull hboxes, one for each minipage. The problem is that your image is too wide. If you make the width 300px, for example, there are no overfull hboxes.
    – user30471
    Commented Jul 30, 2020 at 20:41
  • @Andrew, changed it to 300px widths for the images, and the overfull is gone, but the underfull is still there.
    – ChrisMM
    Commented Jul 30, 2020 at 20:43

1 Answer 1

1

Don't forget to omit spaces at ends of lines, you were generating a line with just a word space which can not stretch to fill the line hence the underfull box. (note you can use example-image in examples as these images are distributed for such tests)

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .