TransWikia.com

One subcaption for two subfigures

TeX - LaTeX Asked on December 20, 2020

I have the following code which outputs one subcaption for each subfigure:

begin{figure}[]
  centering
  subcaptionbox{image 1}%
    {includegraphics{image1.png}hspace{0.5cm}
  subcaptionbox{image 2}%
    {includegraphics{image2.png}}%

bigskip

  subcaptionbox{image 3}}%
    {includegraphics{image3.png}}hspace{0.5cm}
  subcaptionbox{image 4}%
    {includegraphics{image4.png}}%
  caption{Four images.}
end{figure}

Is it possible to modify it to have one subcaption for images 1 and 2 and another subcaption for images 3 and 4?

2 Answers

Yes, just place two images in each subcaptionbox.

enter image description here

documentclass{article}
usepackage[demo]{graphicx} % the demo option replace images with black boxes
usepackage{subcaption}
begin{document}
begin{figure}
  centering
  subcaptionbox{image 1 and 2}%
    {includegraphics{image1.png}hspace{0.5cm}includegraphics{image2.png}}%

bigskip

  subcaptionbox{image 3 and 4}%
    {includegraphics{image3.png}hspace{0.5cm}includegraphics{image4.png}}%
  caption{Four images.}
end{figure}
end{document}

Correct answer by Torbjørn T. on December 20, 2020

I think an easier method is to start a subfigure environment and just put the caption after the first and second image instead of making subcaption box.

begin{figure}[h]
  centering
  begin{subfigure}{textwidth}
        includegraphics[width=0.49textwidth]{image1.png}
        hspace{1cm}
        includegraphics[width=0.49textwidth]{image2.png}
        caption{Image 1 and 2}
        label{fig:1-2}
  end{subfigure}
 hspace{0.5cm}
  begin{subfigure}{textwidth}
        includegraphics[width=0.49textwidth]{image3.png}
        hspace{1cm}
        includegraphics[width=0.49textwidth]{image4.png}
        caption{Image 3 and 4}
        label{fig:3-4}
  end{subfigure}
end{figure}

Answered by Himanshu Maheshwari on December 20, 2020

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