TransWikia.com

How to control the positions of multiple captions under images?

TeX - LaTeX Asked by CeibaM on February 22, 2021

I am new to latex and want to make good format pictures with captions, like this one.

enter image description here

After some search, I was able to generate similar captions with

 begin{figure}
        begin{minipage}[b]{0.49linewidth}
            includegraphics{figure1.pdf} 
            begin{center} figure1 end{center}
        end{minipage}
        begin{minipage}[b]{0.49linewidth}
            includegraphics{figure2.pdf}
            begin{center} figure2 end{center}
        end{minipage}
        caption{figure1 vs. figure2 }
  end{figure} 

However, there is a large space between the text.
In general, how can I have more control over the position of text?

2 Answers

There are all kinds of options here, the simplest of which is to set the "sub-figure" construction inside a tabular:

enter image description here

documentclass{article}

usepackage{graphicx}

begin{document}

begin{figure}
  mbox{}hfill
  begin{tabular}[b]{c}
    includegraphics[width=5em]{example-image-a} \
    figure1
  end{tabular}hfill
  begin{tabular}[b]{c}
    includegraphics[width=7em]{example-image-b} \
    figure2
  end{tabular}hfill
  mbox{}
  caption{figure1 vs. figure2}
end{figure} 

end{document}

Since you're using tabular, just change the space by adding an optional <len> argument to the tabular line break \[<len>]. If you have multi-line "sub-figure" captions, then one could figure out something different:

enter image description here

documentclass{article}

usepackage{graphicx}

begin{document}

begin{figure}
  mbox{}hfill
  includegraphics[width=5em]{example-image-a}hfill
  makebox[12em]{includegraphics[width=7em]{example-image-b}}hfill
  mbox{}par
  %vspace{<len>} to increase the space
  mbox{}hfill
  makebox[5em]{figure1}hfill
  begin{tabular}[t]{@{}p{12em}@{}}
    This is a beautiful figure that needs more descriptive words
  end{tabular}hfill
  mbox{}
  caption{figure1 vs. figure2}
end{figure} 

end{document}

Of course, in a general setting, I'd recommend using subcaption; you should find sufficient examples within the subcaption documentation.

Correct answer by Werner on February 22, 2021

I would use subigure defined in the subcaption package and write text belos images with caption*{...}:

enter image description here

documentclass{article}
usepackage{graphicx}
usepackage{caption, subcaption}
captionsetup{skip=1ex, font=small}
captionsetup[sub]{skip=-1ex}

begin{document}

begin{figure}
    centering
    setkeys{Gin}{width=linewidth}
begin{subfigure}[b]{0.4linewidth}
    includegraphics{example-image-a} \
    caption*{figure 1}
end{subfigure}%
hfil
begin{subfigure}[b]{0.4linewidth}
    includegraphics{example-image-B} \
    caption*{figure 2}
end{subfigure}%
  caption{figure1 vs. figure2}
  label{fig:comparison}
end{figure}

end{document}

Answered by Zarko on February 22, 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