1

I'm trying to place a figure and a table side by side so that the baselines, rather than the captions, of both are aligned:

The answer to this question does this \stackunder with minipages, but uses a table with a bottom caption. I tweaked the code, but I can't seem to get the minipage [b]s and [t]s right. I want the bottom of the table to be exactly at the bottom of the image:

1

Here's the code that produces the image above:

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{stackengine}

\begin{document}
\stackunder{
    \begin{minipage}[b]{0.49\textwidth}\vspace{0pt}
      \centering
      \includegraphics[width=\textwidth]{example-image-a.pdf}
    \end{minipage}
}
{
    \begin{minipage}[]{0.49\textwidth}\vspace{0pt}
    \captionof{figure}{A figure with a long caption. A figure with a long caption. A figure with a long caption.}
    \end{minipage}
}
\hfill
\stackunder{
    \begin{minipage}[b]{0.49\textwidth}\vspace{0pt}
    \captionof{table}{A table with a long caption. A table with a long caption. A table with a long caption.
    A table with a long caption. A table with a long caption. A table with a long caption. }
    \end{minipage}
}
{
    \begin{minipage}[]{0.49\textwidth}\vspace{0pt}
    \centering
    \begin{tabular}[b]{|c|c|c|}\hline
        a & b & c\\\hline
        1 & 2 & 3\\
        4 & 5 & 6\\
        7 & 8 & 9\\\hline                 
    \end{tabular}
    \end{minipage}
}
\end{document}

2 Answers 2

1

The MWE requires only small changes. For the tabular, you used \stackunder{<caption>}{<tabular} which associates the overall baseline with the <caption>. Instead, use \stackon{<tabular>}{<caption>} so that the tabular is associated with the baseline. Then, to get the proper baseline alignment of the tabular, you need to make the surrounding minipage bottom-aligned, with the [b] option.

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{stackengine}

\begin{document}
\stackunder{
    \begin{minipage}[b]{0.49\textwidth}\vspace{0pt}
      \centering
      \includegraphics[width=\textwidth]{example-image-a.pdf}
    \end{minipage}
}
{
    \begin{minipage}[]{0.49\textwidth}\vspace{0pt}
    \captionof{figure}{A figure with a long caption. A figure with a long caption. A figure with a long caption.}
    \end{minipage}
}
\hfill
\stackon{
    \begin{minipage}[b]{0.49\textwidth}\vspace{0pt}
    \centering
    \begin{tabular}[b]{|c|c|c|}\hline
        a & b & c\\\hline
        1 & 2 & 3\\
        4 & 5 & 6\\
        7 & 8 & 9\\\hline                 
    \end{tabular}
    \end{minipage}
}{    \begin{minipage}[b]{0.49\textwidth}\vspace{0pt}
    \captionof{table}{A table with a long caption. A table with a long caption. A table with a long caption.
    A table with a long caption. A table with a long caption. A table with a long caption. }
    \end{minipage}
}

\end{document}

enter image description here

0

This is an approach based on package xcoffins.

It is a package created to facilitate the precise layout of stuff on the page: text, tables, images, graphics, etc., in a very simple but precise way. Zero guessing.

Handy to construct cover and title pages according to specifications.

There are three steps:

(1) Fill in the content in 4 special boxes (\Figurex , \Tablex, \CaptionTablex and \CaptionFigurex ). Please note that exactly your content was used.

You can think of them as minipages with the advantage that they have many predefined points to attach to each other.

(2) Assemble the boxes together. In this simple case just the left/right-top/bottom corner of a box with the left/right-top/bottom corner of the previous box. (The first box is an empty box \Framex).

For example \JoinCoffins\Framex[\Figurex-r,\Figurex-b]\Tablex[l,b](1em,0pt) will join the right-bottom corner of the figure with the left-bottom corner of the table (as specified) with a added x-offset of 1em.

(3) Typeset the whole set.

See https://tex.stackexchange.com/a/576386/161015 for a more extensive explanation.

a

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}

\usepackage{xcoffins} % added  <<<<

\NewCoffin\Framex
\NewCoffin\Figurex
\NewCoffin\Tablex
\NewCoffin\CaptionTablex
\NewCoffin\CaptionFigurex

\begin{document}

% Set the content in boxes  
\SetVerticalCoffin\Figurex{0.48\textwidth}{%
\noindent\includegraphics[width=0.48\textwidth]{example-image-a.pdf}    
}   

\SetVerticalCoffin\Tablex{0.48\textwidth}{%
\centering\begin{tabular}[b]{|c|c|c|}\hline
    a & b & c\\\hline
    1 & 2 & 3\\
    4 & 5 & 6\\
    7 & 8 & 9\\\hline                 
\end{tabular}
}   

\SetVerticalCoffin\CaptionTablex{0.48\textwidth}{%  
    \captionof{table}{A table with a long caption. A table with a long caption. A table with a long caption.
    A table with a long caption. A table with a long caption. A table with a long caption. }    
}

\SetVerticalCoffin\CaptionFigurex{0.48\textwidth}{%
\captionof{figure}{A figure with a long caption. A figure with a long caption. A figure with a long caption.}
}   

% Join the boxes
\JoinCoffins\Framex[l,t]\Figurex[l,t]
\JoinCoffins\Framex[\Figurex-r,\Figurex-b]\Tablex[l,b](1em,0pt)% x offset = 1em to the right
\JoinCoffins\Framex[\Figurex-l,\Figurex-b]\CaptionFigurex[l,t](0pt, -2ex) %y offset = 2ex down
\JoinCoffins\Framex[\Tablex-l, \Tablex-t]\CaptionTablex[l,b]

% Typeset the assembly
\noindent\TypesetCoffin\Framex

\end{document}

You must log in to answer this question.

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