0

I am trying to put two figures (separately stored in two .pdf files) vertically in a one-column style. \subfigure is not allowed, and below is my code:

\documentclass{article}
\usepackage{subfig}
\usepackage{float}
\usepackage[export]{adjustbox}

\begin{document}

\begin{figure}[H]
    \centering
    \subfloat[1]{
        \begin{minipage}[t]{1\linewidth}
            \includegraphics[width = 1\linewidth]{1.pdf}
        \end{minipage}
        \label{1}
    }
    \\
    \subfloat[2]{
        \begin{minipage}[t]{1\linewidth}
            \includegraphics[width = 1\linewidth]{2.pdf}
        \end{minipage}
        \label{2}
    }
    \caption{0}
    \label{0}
\end{figure}

\end{document}

However, I got the warning of Overfull \hbox (10.77068pt too wide)LaTeX. I searched and found the \adjustbox can solve it with the following code:

\documentclass{article}
\usepackage{subfig}
\usepackage{float}
\usepackage[export]{adjustbox}

\begin{document}

\begin{figure}[H]
    \centering
    \begin{adjustbox}{width=\linewidth}
    \subfloat[1]{
        \begin{minipage}[t]{1\linewidth}        
            \includegraphics[width = 1\linewidth]{1.pdf}
        \end{minipage}
        \label{1}
    }
    \end{adjustbox}
    \\
    \begin{adjustbox}{width=\linewidth}
    \subfloat[2]{
        \begin{minipage}[t]{1\linewidth}
            \includegraphics[width = 1\linewidth]{2.pdf}
        \end{minipage}
        \label{2}
    }
    \end{adjustbox}
    \caption{0}
    \label{0}
\end{figure}

\end{document}

But I thought it kind of sophisticated to duplicate the adjustbox, and tried with this way:

\documentclass{article}
\usepackage{subfig}
\usepackage{float}
\usepackage[export]{adjustbox}

\begin{document}

\begin{figure}[H]
    \centering
    \adjustbox{width=\linewidth}{
    \subfloat[1]{
        \begin{minipage}[t]{1\linewidth}        
            \includegraphics[width = 1\linewidth]{1.pdf}
        \end{minipage}
        \label{1}
    }
    \\
    \subfloat[2]{
        \begin{minipage}[t]{1\linewidth}
            \includegraphics[width = 1\linewidth]{2.pdf}
        \end{minipage}
        \label{2}
    }
    }
    \caption{0}
    \label{0}
\end{figure}

\end{document}

to set the whole figure at one time, but got the error of Something's wrong--perhaps a missing \item. in the \\ in front of \subfloat[2]{

enter image description here

So is there anyway to solve the problem easily?

2
  • Welcome to TexSE :) // Your question is clear. However, I'd like to ask you to ad the preamble and the \begin{document} .. \end{document} statements. On one hand it makes clear, which packages you use or did not, but should, use. On the other hand we simply can copy and run your code. Thanks
    – MS-SPO
    Apr 18, 2022 at 12:10
  • 1
    @MS-SPO, thanks for your reminder, and I have added them as required.
    – yangtzech
    Apr 18, 2022 at 12:23

1 Answer 1

2

Eliminate the Overfull by inserting % after \subfloat, \label and \end{minipage} to eliminate the extra spaces.

(Updated after @David Carlisle comment)

\documentclass{article}
\usepackage{subfig}
\usepackage{float}
\usepackage[export]{adjustbox}

\usepackage{showframe} % ONLY to show the margins <<<<<<<<<<
\usepackage{graphicx} % to add example-image


\begin{document}

Some text.

\begin{figure}[H]       
    \centering
    \subfloat[1]{% <<<<<<<<<<<<
    \begin{minipage}[t]{1\linewidth}
        \includegraphics[width = 1\linewidth,height=150pt]{example-image}
          \end{minipage}%<<<<<<<<<<<<
        \label{1}% <<<<<<<<<<<<
    }
    \\
    \subfloat[2]{% <<<<<<<<<<<<
    \begin{minipage}[t]{1\linewidth}
        \includegraphics[width = 1\linewidth,height=150pt]{example-image}
          \end{minipage}%<<<<<<<<<<<<
        \label{2}% <<<<<<<<<<<<
    }
    \caption{0}
    \label{0}
\end{figure}
    
\end{document}

a

The simplest code:

\begin{figure}[H]       
    \centering
    \subfloat[1\label{1}]{% label here 
        \includegraphics[width = 1\linewidth,height=150pt]{example-image}%      
     }
    \\
    \subfloat[2]{%
        \includegraphics[width = 1\linewidth,height=150pt]{example-image}%
        \label{2}%   or label here
    }
    \caption{0}
    \label{0}
\end{figure
4
  • there is no difference beween minipage and \parbox here. You fixed the issue as you removed the spurious white space by adding % Apr 18, 2022 at 15:05
  • @DavidCarlisle, and Simon Dispa, thanks for your help. Adding the % did solve the problem. But why? Adding % seems to comment out the space before and after the figure?
    – yangtzech
    Apr 19, 2022 at 2:02
  • @yangtzech \fbox{ x } is wider than \fbox{x} you were making a box wih an inner box ha was \linewidth wide, with a space before and after, so two spaces wider than you want. Apr 19, 2022 at 6:44
  • @DavidCarlisle Got it.
    – yangtzech
    Apr 19, 2022 at 7:09

You must log in to answer this question.

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