3

I'm putting sets of graphics (i.e. figures and graphs) aligned in sets of rows using caption and subcaption packages. As figures and graphs doesn't have same with/height ratio the captions in rows are misaligned (objects and their captions are aligned to the middle)

MWE:

\documentclass[a4paper]{article}
\usepackage{graphicx}
\graphicspath{{img/}{img/png/}}
\usepackage{float,multicol,pdflscape}
\usepackage{amsmath,amssymb,gensymb}

\usepackage{caption,subcaption}
\addto\captionsenglish{\renewcommand{\figurename}{Fig}}
\addto\captionsenglish{\renewcommand{\tablename}{Tab}}

\begin}{document}
\begin{figure}[H]\centering
\begin{subfigure}{.3\textwidth} % to have 3 figures on the line
\includegraphics[width=\textwidth]{fig1-1}
\caption{~}\label{fig1-1}
\end{subfigure}
\begin{subfigure}{.3\textwidth}
\includegraphics[width=\textwidth]{fig1-2}
\caption{~}\label{fig1-2}
\end{subfigure}
\begin{subfigure}{.3\textwidth}
\includegraphics[width=\textwidth]{graph1}
\caption{~}\label{graph1}
\end{subfigure}
%
\begin{subfigure}{.3\textwidth}
\includegraphics[width=\textwidth]{fig2-1}
\caption{}\label{fig2-1}
\end{subfigure}
\begin{subfigure}{.3\textwidth}
\includegraphics[width=\textwidth]{fig2-2}
\caption{}\label{fig2-2}
\end{subfigure}
\begin{subfigure}{.3\textwidth}
\includegraphics[width=\textwidth]{graph2}
\caption{}\label{graph2}
\end{subfigure}
%
\caption{Caption.}
\end{figure}
\end{document}

How can I read the height of, for example, fig1-1 to be able to pass it to \rule{0pt}{<height-of-fig1-1>}, or there's (more) elegant way to make it "nice" (the ultimate result is figures/graphs aligned to the middle, captions aligned to the top)?

0

1 Answer 1

4

This seems to do what you want, unless you want text in your subcaptions.

\documentclass[a4paper]{article}
\usepackage{graphicx}

\usepackage{caption,subcaption}

\newcommand{\figurerow}[6]{%
  \sbox{0}{\includegraphics[width=.3\textwidth]{#1}}%
  \sbox{2}{\includegraphics[width=.3\textwidth]{#3}}%
  \sbox{4}{\includegraphics[width=.3\textwidth]{#5}}%
  \dimen0=\ht0
  \ifdim\ht2>\dimen0 \dimen0=\ht2 \fi
  \ifdim\ht4>\dimen0 \dimen0=\ht4 \fi
  \advance\dimen0\abovecaptionskip
  \advance\dimen0\baselineskip
  \figurerowfigure{0}{#2}
  \figurerowfigure{2}{#4}
  \figurerowfigure{4}{#6}\par
}
\newcommand{\figurerowfigure}[2]{%
  \begin{subfigure}[b][\dimen0][s]{.3\textwidth}
  \vfill
  \box#1
  \vfill
  \caption{}\label{#2}
  \end{subfigure}%
}

\begin{document}
\begin{figure}
\centering
\figurerow
  {example-image.pdf}{label1}
  {example-image-golden.pdf}{label2}
  {example-image-golden-upright.pdf}{label3}

\bigskip

\figurerow
  {example-image-golden.pdf}{label4}
  {example-image-golden-upright.pdf}{label5}
  {example-image.pdf}{label6}

\caption{Caption.}
\end{figure}
\end{document}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .