TransWikia.com

Center two images with different heights/widths vertically aligned by the center with captions at the bottom

TeX - LaTeX Asked on November 9, 2021

I want to center two images side by side, that are vertically aligned by the center with the captions at the bottom. I managed to do everything, except to center them.
Here is the picture:

example

Here is my code:

usepackage{caption,floatrow}
DeclareCaptionSubType[alph]{figure}
captionsetup[figure]{labelsep=colon}
captionsetup[subfigure]{labelformat=brace,labelsep=space,labelfont=bf}
floatsetup[subfigure]{capposition=bottom,heightadjust=object,valign=c}

begin{document}
begin{figure}[ht]
ffigbox[hsize]
{begin{subfloatrow}
    ffigbox
        {includegraphics[height=.6hsize]{radar.png}}
        {caption{Feature radar}label{fig:radar}}
    ffigbox
        {includegraphics[height=1.2hsize]{map.png}}
        {caption{Map}label{fig:map}}
    end{subfloatrow}}
    {caption{Set plot}}
end{figure}
end{document}

And before that:

documentclass{article}
usepackage{verbatim}
usepackage{lipsum}
usepackage[utf8]{inputenc}
usepackage{amsfonts}
usepackage{graphicx,url}
graphicspath{ {./Figures/} }
usepackage{subcaption}
usepackage{flushend}
usepackage{xspace} % for new command space
usepackage{hyperref} % alternatively use url
usepackage{tikz}
usepackage{siunitx}
usepackage{booktabs}
usepackage{multirow}
usepackage{systeme}
usepackage[ruled,vlined]{algorithm2e}
usepackage[export]{adjustbox}% http://ctan.org/pkg/adjustbox | align figures
usepackage{caption,floatrow}

2 Answers

Another approach, achieved by

  • adjusting the vertical alignment of first (also shorter) figure to its center (with the option align=c from graphbox package), and
  • inserting a vertically centered zero-width box with height of second (also taller) figure.
documentclass{article}
usepackage{graphbox} % it depends on "graphicx" package
usepackage{subcaption}

begin{document}
begin{figure}
centering
subcaptionbox{A catlabel{cat}}
  {%
    includegraphics[width=3cm,align=c]{example-image}%
    vphantom{includegraphics[width=6cm,align=c]{example-image}}%
  }qquad
subcaptionbox{An elephantlabel{elephant}}
  {includegraphics[width=6cm]{example-image}}
caption{Two animals}label{animals}
end{figure}
end{document}

enter image description here

Answered by muzimuzhi Z on November 9, 2021

Here's how I managed to make it work:

begin{figure}[ht]
centering
    ffigbox[hsize]
        {begin{subfloatrow}
            ffigbox[.5hsize]
                {includegraphics[width=FBwidth]{radar.png}}
                {caption{Feature radar}label{fig:radar}}
            ffigbox[1.4hsize]
                {includegraphics[width=FBwidth]{map.png}}
                {caption{Map}label{fig:map}}
        end{subfloatrow}}
    {caption{Set plot}}
end{figure}

And the result with the bounding boxes around the images working example

Answered by leosole on November 9, 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