[Tex/LaTex] Caption beside image in minipage

captionsgraphicsminipage

What i'm trying to achieve:

Have two images in one page, one image on the top half of the page and the other the bottom half. Ive managed to do this by:

\vbox{
  \begin{minipage}[t][0.45\textheight][t]{\textwidth}
    \centering
    \includegraphics[height=0.5\textheight]{image1}
  \end{minipage}

  \nointerlineskip
  \begin{minipage}[b][0.45\textheight][t]{\textwidth}
    \vspace{0.4in}
    \centering
    \includegraphics[height=0.45\textheight]{image2}
  \end{minipage}
}

But i would like to have a caption beside the image so that it doesn't use up too much space. Ive tried a few ways but i always get the 'not in outer par mode' error.

Any way of doing this?

Best Answer

One option using \captionof from the caption package (the capt-of package also offers this feature) to provide the captions:

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

\begin{document}

\clearpage
\noindent\begin{minipage}[t][0.45\textheight][t]{.45\textwidth}
  \centering
  \includegraphics[height=0.5\textheight,width=\linewidth]{example-image-a}
\end{minipage}\hfill
\begin{minipage}[b]{.45\textwidth}
\captionof{figure}{here's the caption for the first figure and some more text for the example}
\label{fig:testa}
\end{minipage}
\vfill

\noindent\begin{minipage}[t][0.45\textheight][t]{.45\textwidth}
  \centering
  \includegraphics[height=0.45\textheight,width=\linewidth]{example-image-b}
\end{minipage}\hfill
\begin{minipage}[b]{.45\textwidth}
\captionof{figure}{here's the caption for the second figure and some more text for the example}
\label{fig:testb}
\end{minipage}
\clearpage

\end{document}

enter image description here

Adjust the lengths and alignments used according to your needs.