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?
9 Answers
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`.
-
10I 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. Aug 23, 2014 at 9:37 -
4Nice! However, I also had problems with getting the caption top-aligned. Adding dummy lines (as suggested by @Jack Aidley) didn't help either :( Please let me know if you have any other advice for the vertical alignment issue.– SobiDec 12, 2015 at 23:01
-
1Yes, it is so robust that I can use it in the
subfigure
environment; the other the other two most voted solutions fail. It would be great, however, if someone may fix the problem @JackAidley mentioned about the top/top alignment. Jan 6, 2016 at 12:58 -
6I tried your solution, but I get the caption underneath the figure, not on its side. I wish to place them on the left side of it. What am I doing wrong? Can it be a problem since I'm using revtex4-1? Dec 14, 2016 at 12:10
-
9@Sobi This question suggests adding
\vspace{0pt}
as the first item in eachminipage[t]
for top-top alignment. Basically, the[t]
will assign the minipage's reference point to the baseline of its content's topmost line. The\vspace{0pt}
adds a zero-height line at the top, so that's where the reference point will be. Jun 20, 2017 at 3:38
Use the sidecap package.
\usepackage{sidecap}
\begin{SCfigure}
\includegraphics{fig}
\caption{Foo bar}
\end{SCfigure}
See vertical position of sidecap figure w.r.t. top aligned caption
-
5
-
\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}
-
4I 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) Sep 22, 2011 at 6:20
-
2And I would never use package
float
and if I usesidecap
there is no need for usingfloatrow
too! And if I usefloatrow
I wouldn't usesidecap
! Long speech short sense: If one doesn't needfloatrow
thensidecap
is the better choice!– user2478Sep 22, 2011 at 7:33 -
@Herbert: just out of curiosity, why do you say you would never use the
float
package? Sep 22, 2011 at 18:39 -
1@GonzaloMedina: too many problems when I forget that I shouldn't use
\restylefloat
. Everything can be done with the packages caption and/or floatrow– user2478Sep 22, 2011 at 18:51 -
3
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.
-
1AFAIK
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 usetopbeside
instead ofbottombeside
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? Nov 7, 2011 at 12:06
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:
- ODD page:
- 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}
Somehow I cannot post it as a comment. This solution is basically what Igor Kotelnikov suggested above with the follow-up comments. It was convoluted a bit to get everything right, so I decided to post it. Go upvote the initial suggestion!
\newcommand{\sidebysidecaption}[4]{%
\RaggedRight%
\begin{minipage}[t]{#1}
\vspace*{0pt}
#3
\end{minipage}
\hfill%
\begin{minipage}[t]{#2}
\vspace*{0pt}
#4
\end{minipage}%
}
With usage:
\begin{figure}[tb]
\sidebysidecaption{0.555\linewidth}{0.42\linewidth}{%
\includegraphics[width=1\linewidth]{saica13/images/cam_mounting.png}%
}{%
\caption[Photograph of camera mounting]{Camera mounted between two
projections screens. Note that while the view direction can be
modified, the up vector of the camera is fixed.}
\label{fg:cam-mounting}
}
\end{figure}
-
1Welcome to the site! You need 50 reputation points to be able to comment, I believe. Aug 27, 2017 at 15:14
-
I changed
\RaggedRight
to\captionsetup{justification=raggedright}
, but that is probably because I use thecaption
package. I really like the\vspace*{0pt}
gimmick. Just what I was looking for.– thymaroSep 11, 2019 at 19:45
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.
-
2I don't think, that usability of XeTeX is a special memoir feature. Even the standard classes allow you to use XeTeX. Nov 7, 2011 at 12:10
None of these is robust enough to work with the beamerposter class within an environment such as the following:
\begin{frame}%
\begin{columns}%
\begin{column}{\colCWidth}%
\tcbox[title=MOTIVATION]%
{\begin{minipage}[t][.1\textheight][t]
...
\end{minipage}%
}%
\end{column}%
\end{columns}%
\end{frame}