# Caption on the side of a figure

Can anyone tell me how to get my caption on side of my figure, and at the same time aligned with the top of my figure?

-
Could you give us an idea how wide the figure is, and how wide the caption is? E.g., does the caption consist of just a word or two, or could it be several lines long? –  Mico Sep 21 '11 at 21:27

You can use the \floatbox and \capbeside commands provided by the floatrow package:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{floatrow}

\begin{document}

\begin{figure}
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,top},capbesidewidth=4cm}}]{figure}[\FBwidth]
{\caption{A test figure with its caption side by side}\label{fig:test}}
{\includegraphics[width=5cm]{name}}
\end{figure}

\begin{figure}
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={right,top},capbesidewidth=4cm}}]{figure}[\FBwidth]
{\caption{A test figure with its caption side by side}\label{fig:test}}
{\includegraphics[width=5cm]{name}}
\end{figure}

\end{document}


You could also be interested in the tufte document classes:

\documentclass{tufte-book}
\usepackage[demo]{graphicx}
\usepackage{lipsum}

\begin{document}

\lipsum[1]
\begin{figure}
\centering
\includegraphics[width=5cm]{name}
\caption{\protect\lipsum[1]}
\end{figure}

\end{document}


-

Here is a direct and robust method:

\begin{figure}
\begin{minipage}[c]{0.67\textwidth}
\includegraphics[width=\textwidth]{2011-03-03}
\end{minipage}\hfill
\begin{minipage}[c]{0.3\textwidth}
\caption{
Температура перехода в ионизованное состояние
атомарного водорода в зависимости от плотности газа.
} \label{fig:03-03}
\end{minipage}
\end{figure}


Perhaps, this way is less smart compared to packages sidecap and floatrow mentioned in other answers, but I use it for many years because of its simplicity. Widths of images and captions are fully controllable through arguments of minipage environment (parbox also works) and \includegraphics. Vertical alignment is controlled through optional argumants [c], [t] or [b] of minipage.

-
I found this much the best method. However, there is an issue with the behaviour of minipage and getting the alignment desired between the two elements (I wanted top/top) but this was fixed by adding a dummy line \mbox{}\\[-\baselineskip] immediately inside each minipage so it had a line to hang the alignment on. –  Jack Aidley Aug 23 '14 at 9:37
\documentclass[twoside,a5paper]{article}
\usepackage[demo]{graphicx}
\usepackage[outercaption]{sidecap}
\begin{document}

\begin{SCfigure}
\includegraphics[width=5cm]{name}
\caption{A test figure with its caption side by side}\label{fig:testA}
\end{SCfigure}

\begin{SCtable}
\caption{A test figure with its caption side by side}\label{fig:testB}
\includegraphics[width=5cm]{name}
\end{SCtable}

\clearpage

\begin{SCtable}
\caption{A test figure with its caption side by side}\label{fig:testB}
\includegraphics[width=5cm]{name}
\end{SCtable}
\end{document}


-
I would not use package sidecap because it is incompatible with package float (and floatrow) and the author itself suggests to use alternatives (I remember such a discussion on dctt) –  Matthias Pospiech Sep 22 '11 at 6:20
And I would never use package float and if I use sidecap there is no need for using floatrow too! And if I use floatrow I wouldn't use sidecap! Long speech short sense: If one doesn't need floatrow then sidecap is the better choice! –  Herbert Sep 22 '11 at 7:33
@Herbert: just out of curiosity, why do you say you would never use the float package? –  Gonzalo Medina Sep 22 '11 at 18:39
@GonzaloMedina: too many problems when I forget that I shouldn't use \restylefloat. Everything can be done with the packages caption and/or floatrow –  Herbert Sep 22 '11 at 18:51
@Herbert: I agree about using caption and/or floatrow instead. Thanks for answering. –  Gonzalo Medina Sep 22 '11 at 18:56

Another possibility is to use koma script with 'captionbeside'

\KOMAoptions{captions=bottombeside} % topbeside
\begin{figure}[H]
\begin{captionbeside}%
[Example of captionbeside]%
{Example of captionbeside, with inside caption.
Suspendisse justo purus, lacinia et, iaculis ac, sagittis at, enim. Nulla placerat, massa iaculis imperdiet tristique, dolor libero laoreet risus, ac sollicitudin enim sem vel ante.}%
[i][0.8\linewidth][2em]
\includegraphics[width=0.4\textwidth]{images/latex}
\end{captionbeside}
\label{fig:maincls.captionbeside}
\end{figure}


which has a similar command structure to floatrow.

-
AFAIK captions=topbeside would align top line of the caption to the baseline. The baseline of the graphics is at the bottom of the graphic. So, if you use topbeside instead of bottombeside you have to change the baseline of the graphics, e.g., using \raisebox{\dimexpr\ht\strutbox-\totalheight\relax}{\includegraphics...}. Maybe you could add a second example using this? –  Schweinebacke Nov 7 '11 at 12:06

Or you can take the lazy way out (also robust) and use the \sidecaption environment defined by the Memoir class

\begin{sidecaption}[fortoc]{title}[label]
the body of the float
\end{sidecaption}


Memoir also provides width, separation and margin location macros without forcing you to use Tufte or Koma design/layout solutions, and it allows you to use e.g. XeTeX.

-
I don't think, that usability of XeTeX is a special memoir feature. Even the standard classes allow you to use XeTeX. –  Schweinebacke Nov 7 '11 at 12:10

I am aware that this has been solved, however, I thought I would contribute what I use to address this problem.

I Create two new commands, as follows:

%----------------------------------------
%COMMAND FOR DOING SIDE CAPTION.
%----------------------------------------
\newcommandx{\mycaptionminipage}[3][3=c,usedefault]{%
\begin{minipage}[#3]{#1}%
\ifthenelse{\equal{#3}{b}}{\captionsetup{aboveskip=0pt}}{}
\ifthenelse{\equal{#3}{t}}{\captionsetup{belowskip=0pt}}{}
\vspace{0pt}\centering\captionsetup{width=\textwidth} %Temporarily set caption width
#2%
\end{minipage}%
}%
\newcommandx{\mysidecaption}[4][4=c,usedefault]{%
\checkoddpage%
\ifoddpage%
%CASE ODD PAGES
\mycaptionminipage{\dimexpr\linewidth-#1\linewidth-\intextsep\relax}{#3}[#4]%
\hfill%
\mycaptionminipage{#1\linewidth}{#2}[#4]%
\else%
%CASE EVEN PAGES
\mycaptionminipage{#1\linewidth}{#2}[#4]%
\hfill%
\mycaptionminipage{\dimexpr\linewidth-#1\linewidth-\intextsep\relax}{#3}[#4]%
\fi%
}%


These latter command take an argument representing the content along the outer margin (right hand side for odd page, left hand side for even page), content for inner margin, fraction of line taken up by the outer content, and, the alignment between the inner and outer content.

Usage is as follows:

\mysidecaption{<LINE FRACTION OF OUTER CONTENT>}{<OUTER CONTENT>}{<INNER CONTENT>}[<VERTICAL ALIGNMENT, c(default), b or t>]


Here are Some Sample Outputs:

1. ODD page:

1. EVEN page, via the same commands:

Full Working Example as Follows:

\documentclass[10pt]{article}
\usepackage[left=2cm,right=2cm,top=3cm,bottom=3cm]{geometry}
\usepackage{xargs,lipsum,caption,changepage,ifthen}
\usepackage[demo]{graphicx}

%----------------------------------------
%COMMAND FOR DOING SIDE CAPTION.
%----------------------------------------
\newcommandx{\mycaptionminipage}[3][3=c,usedefault]{%
\begin{minipage}[#3]{#1}%
\ifthenelse{\equal{#3}{b}}{\captionsetup{aboveskip=0pt}}{}
\ifthenelse{\equal{#3}{t}}{\captionsetup{belowskip=0pt}}{}
\vspace{0pt}\centering\captionsetup{width=\textwidth} %Temporarily set caption width
#2%
\end{minipage}%
}%
\newcommandx{\mysidecaption}[4][4=c,usedefault]{%
\checkoddpage%
\ifoddpage%
%CASE ODD PAGES
\mycaptionminipage{\dimexpr\linewidth-#1\linewidth-\intextsep\relax}{#3}[#4]%
\hfill%
\mycaptionminipage{#1\linewidth}{#2}[#4]%
\else%
%CASE EVEN PAGES
\mycaptionminipage{#1\linewidth}{#2}[#4]%
\hfill%
\mycaptionminipage{\dimexpr\linewidth-#1\linewidth-\intextsep\relax}{#3}[#4]%
\fi%
}%

%DUMMY TEXT.
\def\t{Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo. Namlacus libero, pretium at, lobortis vitae, ultricies et, tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna, vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis. Suspendisse ut massa. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna, vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis. Suspendisse ut massa.}

\begin{document}
\section{Examples on ODD Page}
\subsection{Image Outer, Caption Inner, Center Aligned}
\mysidecaption{0.5}{%
\includegraphics[width=\linewidth,height=2cm]{name}%
}{%
\captionof{figure}{\t}%
}[c]%
\subsection{Image Inner, Caption Outer, Center Aligned}
\mysidecaption{0.5}{%
\captionof{figure}{\t}%
}{%
\includegraphics[width=\linewidth,height=2cm]{name}%
}[c]%
\subsection{Image Inner, Caption Outer, BOTTOM Aligned}
\mysidecaption{0.5}{%
\captionof{figure}{\t}%
}{%
\includegraphics[width=\linewidth,height=2cm]{name}%
}[b]%
\subsection{Image Inner, Caption Outer, TOP Aligned}
\mysidecaption{0.5}{%
\captionof{figure}{\t}%
}{%
\includegraphics[width=\linewidth,height=2cm]{name}%
}[t]%

\clearpage
\section{Examples on EVEN Page}
\subsection{Image Outer, Caption Inner, Center Aligned}
\mysidecaption{0.5}{%
\includegraphics[width=\linewidth,height=2cm]{name}%
}{%
\captionof{figure}{\t}%
}[c]%
\subsection{Image Inner, Caption Outer, Center Aligned}
\mysidecaption{0.5}{%
\captionof{figure}{\t}%
}{%
\includegraphics[width=\linewidth,height=2cm]{name}%
}[c]%
\subsection{Image Inner, Caption Outer, BOTTOM Aligned}
\mysidecaption{0.5}{%
\captionof{figure}{\t}%
}{%
\includegraphics[width=\linewidth,height=2cm]{name}%
}[b]%
\subsection{Image Inner, Caption Outer, TOP Aligned}
\mysidecaption{0.5}{%
\captionof{figure}{\t}%
}{%
\includegraphics[width=\linewidth,height=2cm]{name}%
}[t]%

\end{document}
`
-