1

I am trying to to get the smaller images in the second row to center align with the bigger images in the first row: (this using MS word) Fig_word

I tried the following code:

\begin{figure*}[h]
\centering
\subcaptionbox{} [4em] {\includegraphics[width=8em]{4a.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=8em]{4b.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=8em]{4c.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=8em]{4d.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=8em]{4e.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=8em]{4f.png}}\\

\subcaptionbox{} [4em] {\includegraphics[width=4em]{4g.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=4em]{4h.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=4em]{4i.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=4em]{4j.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=4em]{4k.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=4em]{4l.png}}
        \caption {My caption}
\end{figure*}

This gives: Fig_latex

But, as you see, I have to manually adjust the hspace values to make each of the smaller images center aligned with their corresponding bigger images. How should I go about it?

2

Rather use the subcaption package which allows you to specify the width of the sub-figure block. Here's an example with \subcaptionbox{<caption>}[<width>]{<stuff>}:

enter image description here

\documentclass{article}

\usepackage{subcaption,graphicx}

\begin{document}

\begin{figure}
  \centering
  \subcaptionbox{}[4em]{\includegraphics[width=4em,angle=90]{example-image-a}}
  \subcaptionbox{}[4em]{\includegraphics[width=4em,angle=90]{example-image-b}}
  \subcaptionbox{}[4em]{\includegraphics[width=4em,angle=90]{example-image-c}}
  \subcaptionbox{}[4em]{\includegraphics[width=4em,angle=90]{example-image-b}}
  \subcaptionbox{}[4em]{\includegraphics[width=4em,angle=90]{example-image-a}}

  \subcaptionbox{}[4em]{\includegraphics[width=4em]{example-image-a}}
  \subcaptionbox{}[4em]{\includegraphics[width=4em]{example-image-b}}
  \subcaptionbox{}[4em]{\includegraphics[width=4em]{example-image-c}}
  \subcaptionbox{}[4em]{\includegraphics[width=4em]{example-image-b}}
  \subcaptionbox{}[4em]{\includegraphics[width=4em]{example-image-a}}

  \caption{My caption}
\end{figure}

\end{document}

If you're sold on (the obsolete) subfigure, you can measure the width of your widest element and then use that as the width for the less-wide images:

\newlength{\widestimg}

\begin{figure}
  \centering
  \settowidth{\widestimg}{\includegraphics{4a.png}}% Measure width of widest image
  \subfigure[]{\includegraphics{4a.png}}
  \subfigure[]{\includegraphics{4b.png}}
  \subfigure[]{\includegraphics{4c.png}}
  \subfigure[]{\includegraphics{4d.png}}
  \subfigure[]{\includegraphics{4e.png}}
  \subfigure[]{\includegraphics{4f.png}}

  \subfigure[]{\makebox[\widestimg]{\includegraphics{4g.png}}}
  \subfigure[]{\makebox[\widestimg]{\includegraphics{4h.png}}}
  \subfigure[]{\makebox[\widestimg]{\includegraphics{4i.png}}}
  \subfigure[]{\makebox[\widestimg]{\includegraphics{4j.png}}}
  \subfigure[]{\makebox[\widestimg]{\includegraphics{4k.png}}}
  \subfigure[]{\makebox[\widestimg]{\includegraphics{4l.png}}}

  \caption{My caption}
\end{figure}
  • As you see (in the edited post), the problem remains. I cannot get the smaller figures and captions to align at the same time. – n.gaurav Nov 2 '18 at 20:19
  • @n.gaurav: I used 4em because that is the width of the widest image I worked with. If you don't know the width of the widest image, add \newlength{\widestimg} somewhere in your preamble and set it using \settowidth{\widestimg}{\includegraphics{<widest image>}}. Then, instead of 4em, use \widestimg (in the second row of smaller images). – Werner Nov 2 '18 at 20:28
  • That worked, fantastic! As you said, all I needed to do was to find the width of the images in the first row (which are all of same width), and set the subcaption box width for all 12 figures to this width. Thanks! – n.gaurav Nov 2 '18 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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