TransWikia.com

How can I ensure that two adjacent figures and captions are horizontally aligned?

TeX - LaTeX Asked by hun on February 25, 2021

The images do not share a horizontal bottom line, and neither do the captions when using:

centering
begin{minipage}{.48textwidth}
  centering
  includegraphics[width=linewidth]{Figures/im1}
  captionof{figure}{Long caption ..........................................................................................................................}
  label{fig:im1}
end{minipage}
hfill
begin{minipage}{.48textwidth}
  centering
  includegraphics[width=linewidth]{Figures/im2}
  captionof{figure}{Long caption ...........................................................................................................................}
  label{fig:im2}
end{minipage}
end{figure}

Is there a way I can make the base of the image, and the top of the captions aligned horizontally?

3 Answers

Quite simple with the floatrow package:

documentclass{article}
usepackage[margin=2cm]{geometry}
usepackage{erewhon}
usepackage{graphicx}
usepackage{caption}
usepackage{floatrow}

begin{document}

begin{figure}
centering
begin{floatrow}
ffigbox[FBwidth]{caption{Meret Oppenheim – Schoolgirl’s Notebook}}{ includegraphics[width=linewidth]{cahier}}
hfill
ffigbox[FBwidth]{caption{Meret Oppenheim – My Nurse}}{includegraphics[width=0.8linewidth]{magouvernante}}
end{floatrow}
end{figure}

end{document} 

enter image description here

Correct answer by Bernard on February 25, 2021

enter image description here

documentclass{article}
usepackage{graphicx}
usepackage{caption}
begin{document}

begin{figure}
centering
begin{minipage}[b]{.48textwidth}
  includegraphics[width=linewidth]{example-image}
end{minipage}
hfill
begin{minipage}[b]{.48textwidth}
  includegraphics[width=linewidth]{example-image-16x9}
end{minipage}
begin{minipage}[t]{.48textwidth}
  caption{Long caption long caption long caption long caption long caption long caption long caption long caption long caption long caption label{fig:im1}}
end{minipage}
hfill
begin{minipage}[t]{.48textwidth}
  caption{Long caption long caption long caption long caption long caption long caption label{fig:im2}}
end{minipage}
end{figure}

end{document}

Answered by leandriis on February 25, 2021

two methods -- measure the width of the figure and save it in a sbox --or align the minipages at the bottom by using the [b] option -- result for both is the same

with the savebox option

enter image description here

or with minipages bottom aligned and captionsetup = linewidth

enter image description here

MWE

documentclass[10pt,a4paper]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{amsmath}
usepackage{amsfonts}
usepackage{amssymb}
usepackage{graphicx}
usepackage{caption}
usepackage{blindtext}

begin{document}
    begin{figure}[!ht]
    begin{minipage}[b]{.48textwidth}
        centering
        sbox0{includegraphics[width=linewidth]{example-image}}% measure width}
        begin{minipage}{wd0}
            usebox0
            caption{blindtext}
        end{minipage}
        label{fig:im1}
    end{minipage}
    hfill
    begin{minipage}[b]{.48textwidth}
        centering
        sbox0{includegraphics[width=linewidth]{example-image-16x9}}
        begin{minipage}{wd0}
            usebox0
            caption{blindtext}
        end{minipage}
        label{fig:im2}
    end{minipage}
end{figure}

    begin{figure}[!ht]
    begin{minipage}[b]{.48textwidth}
        centering
                captionsetup{width=linewidth}
        includegraphics[width=linewidth]{example-image}
                    caption{blindtext}
            label{fig:im1}
    end{minipage}
    hfill
    begin{minipage}[b]{.48textwidth}
        centering
                        captionsetup{width=linewidth}
        includegraphics[width=linewidth]{example-image-16x9}
                    caption{blindtext}
            label{fig:im2}
    end{minipage}
end{figure}
end{document}

Answered by js bibra on February 25, 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