5

I am trying to stack three images horizontally. The images have the same size, I want to align them without any vertical gap. I followed the instructions that I found on this answer:

\blindtext

    \begin{figure}[!htb]
        \minipage{0.32\textwidth}
        \includegraphics[width=\linewidth]{Immagini/teiera-ambientale.png}
        \caption{Componente ambientale}
        \label{fig:Componente ambientale}
        \endminipage\hfill
        \minipage{0.32\textwidth}
        \includegraphics[width=\linewidth]{Immagini/teiera-diffusa.png}
        \caption{Componente ambientale e diffusa}
        \label{fig:Componente ambientale e diffusa}
        \endminipage\hfill
        \minipage{0.32\textwidth}
        \includegraphics[width=\linewidth]{Immagini/teiera-speculare.png}
        \caption{Componente ambientale, diffusa e speculare}
        \label{fig:Componente ambientale, diffusa e speculare}
        \endminipage
    \end{figure}

    \blindtext      

But that's the result I get:

enter image description here

I suppose it's because the captions have different length. But I can't change the title in the caption, is there a way to make the gap go away?

2 Answers2

6

The minipages are not aligned. minipage have some optional arguments:

\begin{minipage}[pos(c,t,b)][height][contentpos(c,t,b,s)]{width}
    Minipage content
\end{minipage}

The longer caption in Figure 3 extends the margins of the minipage in both upwards and downwards direction. So if you want the minipages to align, you have to align them at the bottom or at the top - maybe something like

\documentclass[draft]{article}

\usepackage{graphicx}
\usepackage{blindtext}

\begin{document}

\blindtext

    \begin{figure}[!htb]
        \minipage[t][][t]{0.32\textwidth}
        \includegraphics[width=\linewidth]{Immagini/teiera-ambientale.png}
        \caption{Componente ambientale}
        \label{fig:Componente ambientale}
        \endminipage\hfill
        \minipage[t][][t]{0.32\textwidth}
        \includegraphics[width=\linewidth]{Immagini/teiera-diffusa.png}
        \caption{Componente ambientale e diffusa}
        \label{fig:Componente ambientale e diffusa}
        \endminipage\hfill
        \minipage[t][][t]{0.32\textwidth}
        \includegraphics[width=\linewidth]{Immagini/teiera-speculare.png}
        \caption{Componente ambientale, diffusa e speculare}
        \label{fig:Componente ambientale, diffusa e speculare}
        \endminipage
    \end{figure}

    \blindtext 


\end{document}
Holene
  • 6,920
2

The subcaption package offers \subcaptionbox command, which automatically aligns the sub-figures by their very first caption line.

Its syntax is:

\subcaptionbox[<listentry>]{<heading>}[<width>][<inner-pos>]{<contents>}
\subcaptionbox*{<heading>}[<width>][<inner-pos>]{<contents>}

The heading is used for caption. For further details, see subcaption documentation page 6.

Code:

\documentclass{article}

\usepackage{graphicx}    
\usepackage{blindtext}
\usepackage{subcaption}

\begin{document}

\blindtext

    \begin{figure}[!htb]
        \subcaptionbox{Componente ambientale\label{fig:Componente ambientale}}[0.32\textwidth][t]{%
        \includegraphics[width=0.32\linewidth]{example-image-a}
        }\hfill
        \subcaptionbox{Componente ambientale e diffusa\label{fig:Componente ambientale e 
                  diffusa}}[0.32\textwidth][t]{%
        \includegraphics[width=0.32\linewidth]{example-image-b}
        }\hfill
        \subcaptionbox{Componente ambientale, diffusa e speculare some text to fill\label{fig:Componente ambientale,
                  diffusa e speculare}}[0.32\textwidth][t]{%
        \includegraphics[width=0.32\linewidth]{example-image-c}
        }
    \end{figure}

    \blindtext


\end{document}

enter image description here