TransWikia.com

How to move subcaptions in a subfigure environments

TeX - LaTeX Asked on December 3, 2021

I am using the subfigure environment to show 4 figures, 2 in each line. Now, the problem is that the caption of each figure goes over two lines. I want the caption to be written in one line, but at the same time keep the dimensions of my figures small. Here is how I have included my figures:

begin{figure}[t!]
    centering
    begin{subfigure}{.3textwidth}
        includegraphics[width=linewidth]{imgs/first_figure.png}
        vspace*{.2cm}
        caption{My first subcaption.}
    end{subfigure}hspace*{3cm}
    begin{subfigure}{.3textwidth}
        includegraphics[width=linewidth]{imgs/second_figure.png}
        vspace*{.2cm}
        caption{second subcaption is slightly longer.}
    end{subfigure} \vspace*{.5cm}
    begin{subfigure}{.3textwidth}
        includegraphics[width=linewidth]{imgs/third_figure.png}
        vspace*{.2cm}
        caption{third subcaption is slightly longer.}
    end{subfigure}hspace*{3cm}
    begin{subfigure}{.3textwidth}
        includegraphics[width=linewidth]{imgs/fourth_figure.png}
        vspace*{.2cm}
        caption{fourth subcaption is slightly longer.}
    end{subfigure}
    vspace*{.5cm}
    caption{Four figures.}
end{figure}

I tried putting an additional hspace*{-2cm} in front of each subcaption, but it litterally had no effect at all. That’s strange as the vspace*{.2cm} is doing exactly what I intended. Any suggestions?

One Answer

Since you have 4 subfigures, you can easily use up to 0.5textwidth for each. You just need to shrink the images.

documentclass{article} 
usepackage{graphicx}
usepackage{subcaption}
begin{document}
begin{figure}[t]
    advanceabovecaptionskip  by 0.2cm
    centering
    begin{subfigure}{.5textwidth}
        centering
        includegraphics[width=0.6linewidth]{example-image-a}
        caption{My first subcaption.}
    end{subfigure}%
    begin{subfigure}{.5textwidth}
        centering
        includegraphics[width=0.6linewidth]{example-image-b}
        caption{second subcaption is slightly longer.}
    end{subfigure}
    
    begin{subfigure}{.5textwidth}
        centering
        includegraphics[width=0.6linewidth]{example-image-c}
        caption{third subcaption is slightly longer.}
    end{subfigure}%
    begin{subfigure}{0.5textwidth}
        centering
        includegraphics[width=0.6linewidth]{example-image}
        caption{fourth subcaption is slightly longer.}
    end{subfigure}
    vspace{.3cm}% plus 0.2
    caption{Four figures.}
end{figure}
end{document}

demo

Answered by John Kormylo on December 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP