6

How to change the vertical position of a sidecap figure with respect to its top aligned caption? I want the caption to be right from the figure but align like in the attached mockup.

\documentclass{article}

\usepackage[demo]{graphicx}

\usepackage{sidecap}
\sidecaptionvpos{figure}{t}

\begin{document}

\begin{SCfigure}
    \includegraphics{graphs/dataset17b.pdf}
  \caption{Foo bar}
\end{SCfigure}

\end{document}

enter image description here

verbatimbox's addvbuffer fails for long captions:

addvbuffer

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

\usepackage{sidecap}
\sidecaptionvpos{figure}{t}

\begin{document}

\begin{SCfigure}
    \includegraphics{graphs/dataset17b.pdf}
    \caption{\addvbuffer[5ex 0ex]{Foo bar}}
\end{SCfigure}

\begin{SCfigure}
    \includegraphics{graphs/dataset17b.pdf}
    \caption{\addvbuffer[5ex 0ex]{Foo bar Foo bar Foo bar Foo bar Foo
        bar Foo bar Foo bar Foo bar Foo bar}}
\end{SCfigure}

\end{document}
Stefan Pinnow
  • 29,535
Somebody
  • 1,217
  • Please, add some information about your problem. The example is surely not enough to do anything that shots in the dark: how do you produce the text above the image? – egreg May 13 '13 at 12:21

3 Answers3

8

EDIT: Solution revised to handle long captions. Place a vertical rule at the beginning of the caption:

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

\usepackage{sidecap}
\sidecaptionvpos{figure}{t}

\begin{document}

\begin{SCfigure}
    \includegraphics{graphs/dataset17b.pdf}
    \caption{\protect\rule{0ex}{5ex}Foo bar Foo bar Foo bar Foo bar Foo bar Foo bar Foo bar }
\end{SCfigure}

\end{document}

enter image description here

3

Simply add the following to your preamble after loading the sidecap package:

\sidecaptionvpos{figure}{t}

Or for center alignment:

\sidecaptionvpos{figure}{c}

It's an undocumented feature.

dwitvliet
  • 133
  • This is really the best answer to the question (though maybe it wasn't implemented at time of OP?). I wonder why this is undocumented... Is there an option to pass to the alignment to a specific figure instead of setting and unsetting the option globally? – MrArsGravis Nov 23 '20 at 19:40
0

Put the includegraphics in a minipage of matching width and insert an negative vspace.

\documentclass{article}

\usepackage[demo]{graphicx}

\usepackage{sidecap}
\sidecaptionvpos{figure}{t}

\begin{document}

\begin{SCfigure}
  \begin{minipage}{0.5\linewidth}
    \vspace{-\baselineskip}
    \includegraphics{graphs/dataset17b.pdf}
  \end{minipage}
  \caption{Foo bar}
\end{SCfigure}

\end{document}

Or use trim without clip in the includegraphics.

Xavier
  • 13,947
Somebody
  • 1,217
  • Hmmm.... this shouldn't be done; it can produce undesired results with the surrounding text: see the result of this simple example using your code: `\documentclass{article} \usepackage[demo]{graphicx} \usepackage{sidecap} \sidecaptionvpos{figure}{t}

    \begin{document}

    aaaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaa \begin{SCfigure}[][!ht] \begin{minipage}{0.5\linewidth} \vspace{-\baselineskip} \includegraphics{graphs/dataset17b.pdf} \end{minipage} \caption{Foo bar} \end{SCfigure} aaaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaa

    \end{document}`

    – Gonzalo Medina May 09 '13 at 18:16
  • @GonzaloMedina I agree. Any idea how to do better? – Somebody May 09 '13 at 18:42
  • Exactly which is the desired alignment? – Gonzalo Medina May 09 '13 at 18:44
  • I have a figure with a rule on the top but also some text above. I want to do align the caption text with the rule leaving the text in the figure a bit higher. – Somebody May 10 '13 at 06:47
  • Please edit your question and add an example of the actual code you are using, showing how you are producing the rule. – Gonzalo Medina May 10 '13 at 12:49