Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

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}
share|improve this answer
    
I've found that it works also without blindtext. –  Ramy Al Zuhouri Mar 18 at 18:30

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.