3

Following the advice by G. Medina in question Figure with two side-by-side subfigures that is wider than textwidth, I get the desired figure: enter image description here

The trouble is that longer captions de-align the figures:

enter image description here

Code:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\usepackage{lipsum}

\begin{document}

\begin{figure}
  \makebox[\linewidth][c]{%
    \begin{subfigure}[b]{.654\textwidth}
    \centering
    \includegraphics[width=.95\textwidth]{../assets/20180403_all_animal_feed_spectra.pdf}
    \caption{
        short caption short caption short caption short caption short caption 
    }
    \label{fig:all_animal_feed_spectra}
    \end{subfigure}%
    \begin{subfigure}[b]{.6\textwidth}
    \centering
    \includegraphics[width=.95\textwidth]{../assets/20180403_pls_baseline_rmsecv.pdf}
    \caption{
      10-fold RMSECV of the baseline PLS model with varying dimension of the latent space, trained on the raw data.
    }
    \label{fig:rmsecv_baseline}
    \end{subfigure}%
  }
\end{figure}

\end{document}

I guess that the figure needs to be split into two rows: first row to align the images, and second row to align the captions. Furthermore, there should be some free space between the captions.

2
  • 1
    Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – Skillmon
    Commented Apr 6, 2018 at 10:13
  • Perhaps this is helpfull: tex.stackexchange.com/a/353640/44572
    – gebruiker
    Commented Apr 6, 2018 at 10:16

2 Answers 2

1

An alternative using caption package and minipages:

Edit: (and caption package but see @Skillmon's comment)

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

\begin{document}
\lipsum[2]
\begin{figure}[!htb]
  \makebox[\linewidth][c]{%
    \begin{minipage}[t]{.26\textwidth}
    \centering
     \includegraphics[width=\textwidth]{example-image-a}
    \captionof{figure}{
        short caption short caption short caption short caption short caption 
    }
    \label{fig:all_animal_feed_spectra}
    \end{minipage}\begin{minipage}[b]{0.15\textwidth}\phantom{.}\end{minipage}
    \begin{minipage}[t]{1.2\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-b}
    \captionof{figure}{
      10-fold RMSECV of the baseline PLS model with varying dimension of the latent space, trained on the raw data.
    }
    \label{fig:rmsecv_baseline}
    \end{minipage}%
  }
\end{figure}
\end{document}

Output with [t] for minipages:

enter image description here

Output with [b] for minipages:

enter image description here

Output with [c] for minipages: enter image description here

2
  • 1
    If you use caption just for the \captionof command, consider loading capt-of instead (as the caption documentation also suggests). capt-of is much smaller (33 lines compared to 1796).
    – Skillmon
    Commented Apr 6, 2018 at 19:13
  • Thasnks @Skillmon... I will add the info in the post....
    – koleygr
    Commented Apr 6, 2018 at 19:24
2

You should use the [t] option of subfigure if you want top-alignment. You used [b] so you got bottom-alignment.

\documentclass[]{article}

\usepackage[]{graphicx}
\usepackage{duckuments}
\usepackage{subcaption}

\begin{document}
\begin{figure}
  \makebox[\linewidth][c]{%
    \begin{subfigure}[t]{.45\textwidth}
    \centering
    \includegraphics[width=.95\textwidth]{example-image-duck}
    \caption{
        short caption short caption short caption short caption short caption 
    }
    \label{fig:all_animal_feed_spectra}
    \end{subfigure}%
    \hfill
    \begin{subfigure}[t]{.45\textwidth}
    \centering
    \includegraphics[width=.95\textwidth]{example-image-duck}
    \caption{
      10-fold RMSECV of the baseline PLS model with varying dimension of the latent space, trained on the raw data.
    }
    \label{fig:rmsecv_baseline}
    \end{subfigure}%
  }
\end{figure}
\end{document}

enter image description here

2
  • 1
    +1 for ducks :-)
    – Zarko
    Commented Apr 6, 2018 at 19:28
  • @Zarko since I wrote that package I use it in every answer where appropriate :)
    – Skillmon
    Commented Apr 6, 2018 at 19:29

You must log in to answer this question.