131

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?

lockstep
  • 250,273
Nelly
  • 1,321
  • 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

9 Answers9

163

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`.

  • 10
    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 09:37
  • 4
    Nice! 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. – Sobi Dec 12 '15 at 23:01
  • 1
    Yes, 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. – loved.by.Jesus Jan 06 '16 at 12:58
  • 6
    I 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? – user1611107 Dec 14 '16 at 12:10
  • 9
    @Sobi This question suggests adding \vspace{0pt} as the first item in each minipage[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. – Evgeni Sergeev Jun 20 '17 at 03:38
  • 1
    I agree this method is better because it does not require extra packages and miniboxes are so useful in other contexts as well. – mathreadler Jul 12 '17 at 10:16
  • 1
    Also adding "[.3\textwidth]" as prescribed height before the width argument and "\vfill\hfill" at the bottom of the minipage will fill it out so that caption starts at top. At least if working with a square size box. – mathreadler Jul 12 '17 at 10:27
  • Looks like the smartest solution to me – Johannes Schaub - litb Sep 02 '17 at 21:17
  • This method is the best, it worked with me in LyX ert (insert tex code) very easily and perfect – Dr Adel Nov 24 '18 at 09:28
  • @user1611107 Make sure not to add any blank lines in the figure environment – Vincent Oct 10 '21 at 10:44
  • The advantage of the suggestion by @EvgeniSergeev is also that one can adjust the size of the vertical space above the columns if needed - for example, I was able to use \vspace{-4pt} to move one of the columns slightly higher. – Brunox13 Mar 14 '22 at 18:00
  • It cannot break new lines. – GoingMyWay Apr 15 '22 at 03:38
68

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}

enter image description here

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}

enter image description here

Gonzalo Medina
  • 505,128
25

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

20
\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}

enter image description here

8

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:

Odd Page

  1. EVEN page, via the same commands:

Even Page

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}
8

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.

  • 1
    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 07 '11 at 12:06
6

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.

N.N.
  • 36,163
  • 3
    I don't think, that usability of XeTeX is a special memoir feature. Even the standard classes allow you to use XeTeX. – Schweinebacke Nov 07 '11 at 12:10
6

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}

an example

  • 1
    Welcome to the site! You need 50 reputation points to be able to comment, I believe. – Torbjørn T. Aug 27 '17 at 15:14
  • I changed \RaggedRight to \captionsetup{justification=raggedright}, but that is probably because I use the caption package. I really like the \vspace*{0pt} gimmick. Just what I was looking for. – thymaro Sep 11 '19 at 19:45
1

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}
OD IUM
  • 140