how to make subfigures to have same width and height in latex

Viewed 28

Hello I have 7 figures in latex. I want to make all those figures to have the same width and height, Here is what I have tried till now. However as you can see in the result, the figures have not the same height and width. I appreciate if anyone can help me.

\begin{figure*}
        \centering
        %\vspace{-2\baselineskip}
        \begin{subfigure}[b]{0.3\textwidth}
        %\baselineskip
        %\includegraphics[height=8cm, width=18cm]{out_1.png}
                \includegraphics[height=8cm\hskip, width=18cm]{out_1.png}
        \end{subfigure}
        %\quad
        \begin{subfigure}[b]{0.3\textwidth}
                \includegraphics[height=8cm\hskip, width=18cm]{out_2.png}
        \end{subfigure}
        \vspace{-11\baselineskip}
        %\quad
        \begin{subfigure}[b]{0.3\textwidth}
                \includegraphics[height=8cm\hskip, width=18cm]{out_3.png}
        \end{subfigure}
        \begin{subfigure}[b]{0.3\textwidth}
                \includegraphics[height=8cm\hskip, width=18cm]{out_4.png}
        \end{subfigure}
        %\quad
        \vspace{-11\baselineskip}
         \begin{subfigure}[b]{0.3\textwidth}
                \includegraphics[height=8cm, width=18cm]{out_5.png}
        \end{subfigure}
        %\quad
         \begin{subfigure}[b]{0.3\textwidth}
                \includegraphics[height=8cm, width=18cm]{out_6.png}
        \end{subfigure}
      
        %\vspace{-11\baselineskip}
        \begin{subfigure}[b]{0.3\textwidth}
                \includegraphics[height=8cm, width=18cm]{out_7.png}
        \end{subfigure}
        
 \end{figure*}

enter image description here

1 Answers

I usually prefer to define the size of figures, subfigures and tables not in absolute terms (i.e. with 'cm' or 'pt') but in terms relative to the size of the page geometry. This prevents tables from overshooting the page size and/or overlapping. So, if I want to render three figures on the same line, I define the size of the subfigure one third of the linewidth. In a similar way I set the width of the image to the full width of the 'column' generated by subfigure. Thus, I refactor your code as below:

\begin{figure*}
    \centering

    \begin{subfigure}[b]{0.3\textwidth}
            \includegraphics[width=\textwidth]{img.jpg}
    \end{subfigure}
    %\quad
    \begin{subfigure}[b]{0.3\textwidth}
            \includegraphics[width=\textwidth]{img.jpg}
    \end{subfigure}
    \vspace{1\baselineskip}
    %\quad
    \begin{subfigure}[b]{0.3\textwidth}
            \includegraphics[width=\textwidth]{img.jpg}
    \end{subfigure}
    \begin{subfigure}[b]{0.3\textwidth}
            \includegraphics[width=\textwidth]{img.jpg}
    \end{subfigure}
    %\quad
    \vspace{1\baselineskip}
     \begin{subfigure}[b]{0.3\textwidth}
            \includegraphics[width=\textwidth]{img.jpg}
    \end{subfigure}
    %\quad
     \begin{subfigure}[b]{0.3\textwidth}
            \includegraphics[width=\textwidth]{img.jpg}
    \end{subfigure}
  
    \begin{subfigure}[b]{0.3\textwidth}
            \includegraphics[width=\textwidth]{img.jpg}
    \end{subfigure}
        
 \end{figure*}

result

Related