21

I'm writing my master thesis and have run into trouble with the layout of captions in relation to the margins. I have two main questions:

  1. How can I make the caption text of an figure placed in a marginpar be written within the margin and how can I make the fontsize smaller, I'm trying to do it with the following snippet of tex:

    \marginpar{
    \includegraphics[width=\marginparwidth]{Carl_Friedrich_Gauss.jpg}
    \captionof{figure}{Carl Friedrich Gauss, født 1777, er bedst kendt for normalfordelingen}
    }
    

    but as you can see from the following screenshot the text is placed all wrong and the font is too large:

    enter image description here

  2. When working with wrapfigures I've place them so that the figure is floated into the margin, this is the tex I use:

    \begin{wrapfigure}{r}{0.3\textwidth}  
    \centering  
    \vspace{-20pt}  
      \subfloat[Giveaway pr. beholder i procent]  {\label{lbl1}\includegraphics[width=0.5\textwidth]{fig1.png}}  
    \vspace{-12pt}  
      \newline  
      \subfloat[Giveaway pr. beholder i gram]{\label{lbl2}\includegraphics[width=0.5\textwidth]{fig2.png}}  
    \vspace{-12pt}  
      \newline  
      \subfloat[Optimal-ratio]{\label{lbl3}\includegraphics[width=0.5\textwidth]{fig3.png}}  
      \caption{Resultater for testsæt 1}  
    \vspace{-20pt}  
    \end{wrapfigure}
    

    but the width of caption of the figure is too narrow, I would like it to float into the margin like the caption for each of the subfigures do:

    enter image description here

P.S. I tried using the tufte-book class referenced in the question Margin Figures/Captions, but without luck.

1
  • Great question, helps me a lot
    – MadyYuvi
    Jun 27, 2023 at 7:54

2 Answers 2

34

welcome here. Before getting to your problem, first a gentle and well-meaning reminder (actually two):

  1. Please provide a fully worked minimal example with all submissions. Code fragments such as yours don't cut it since they leave room to keep people guessing, hopping in wrong directions, and wasting very precious time.
  2. Please provide only one problem per question. The danger you run into if you don't (as I'm sure has happened here), is that i) you double the work for answer-providers, and ii) the quality of the answers you'll receive will be limited to the quality of the best joint answer, which might very well be lower than the quality you'll get for separate answers (take note, my answer might fall into that category too!).

OK, with that out of the way, here are solutions to your problems.

Problem 1 -- a) Badly behaved margin figures captions and b) caption fontsize smaller

I couldn't reproduce your misbehaved margin figures captions, probably because I automatically used the caption and graphicx packages whereas you might not have done so. Nevertheless, without seeing the code you used, I'm at a loss to explain why your work turned out the way it did.

Setting the caption fontsize smaller (and many, many useful things besides) can be achieved with the \captionsetup command from the caption package.

Here's an example of the output my code produces (code included below):

alt text

Problem 2 -- Subfig caption in wrapfig environment constrained to typeblock

Because you wanted subfigures to protrude into the margins, you created 0.3\textwidth-wide wrapfigure environments and then proceeded to place 0.5\textwidth-wide figures into them. This gives the effect you want with your figures -- they spill nicely into the margins -- but, unfortunately, LaTeX wraps the overall figure caption to the page typeblock, giving you the most visually unappealing caption "clipping" effect that you see.

The solution's simple enough, if not entirely obvious. Use the optional 'overhang' argument with each invocation of wrapfigure. (I set the margin protrusion to [3cm] in the code below). Note also that to avoid overfull hboxes, I set the wrapfigure environment width a little larger than the contained object width: 0.46\textwidth to 0.45\textwidth, respectively, below.)

Tidying up your code, I recommend:

  1. passing \vspace (negative) heights specified in terms of \baselineskip rather than absolute pointsize dimensions when it comes to aligning objects with lines of text (this is just habit in this case, absolute dimensions will be fine),
  2. instructing wrapfigure to use an exact number of lines (in our case [33]) to force it to more exactly meet your needs, and
  3. setting the typeblock-to-wrapfigure distance explicitly, e.g., with something like \setlength\columnsep{\marginparsep}.

Here's the output from the code below:

alt text

Solution code

\documentclass[twoside]{article}

\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}
\usepackage{caption}[2008/04/01]
\usepackage{wrapfig}
\usepackage{subfig}

\usepackage{lipsum}  % to provide "filler" text

\captionsetup{
  justification=raggedright,
  labelfont={color=Maroon,bf},
  font=small}

\begin{document}
\lipsum[1-2]

% Three marginpar figures to see how this looks in
% the left and right margins of twoside docs...
\marginpar{\includegraphics[width=0.95\marginparwidth]{Carl_Friedrich_Gauss.jpg}
 \captionof{figure}{Carl Friedrich Gauss, født 1777, er bedst kendt for normalfordelingen}}
\lipsum[1-2]
\marginpar{\includegraphics[width=0.95\marginparwidth]{Carl_Friedrich_Gauss.jpg}
 \captionof{figure}{Carl Friedrich Gauss, født 1777, er bedst kendt for normalfordelingen}}
\lipsum[1-4]
\marginpar{\includegraphics[width=0.95\marginparwidth]{Carl_Friedrich_Gauss.jpg}
 \captionof{figure}{Carl Friedrich Gauss, født 1777, er bedst kendt for normalfordelingen}}
\lipsum[5-6]

\lipsum[2]
\setlength\columnsep{\marginparsep}
\begin{wrapfigure}[33]{r}[3cm]{0.46\textwidth}
\vspace{-1.5\baselineskip}
\subfloat[Giveaway pr. beholder i procent]{\label{lbl1}
  \includegraphics[width=0.45\textwidth]{test.png}}\par
\subfloat[Giveaway pr. beholder i procent]{\label{lbl2}
  \includegraphics[width=0.45\textwidth]{test.png}}
\caption{Resultater for testsæt 1 blah blah blah blah blah blah blah.}
\end{wrapfigure}
\lipsum[11-14]

\end{document}
5
  • 3
    Great answer: good advice both on asking questions and the problems in hand!
    – Joseph Wright
    Nov 19, 2010 at 8:47
  • 1
    Thank you very much for your thorough answer which solved both of my problems :) My first problem was indeed due to to captionsetup, the template that I'm using had specified format=hang in the setup which was the problem. The \setlength\columnsep{\marginparsep} solved my margin problems with wrapfigure. Thank you for the general advice aswell, I'll remember including minimal examples and keeping to one question pr. post. Nov 19, 2010 at 8:51
  • your solution is good but there is a possibility a page contains 3 figures and a fraction of the last figure at the bottom crossing the page boundry. This frequently happens when a paragraph is not so long enough. I replaced your 2 paragraph lipsum call with a single paragraph lipsum call, the issue came out. Dec 2, 2010 at 10:25
  • @GeoffreyJones What a great solution ! However when I use your code the paragraphs below the wrapped figures are not back to their normal width as in the OP image. As if \setlength\columnsep{\marginparsep} was not back its normal size. I tried a \setlength\columnsep{\textwidth} with no success :/
    – JeT
    Oct 18, 2020 at 17:56
  • Such a nice suggestion, it helps me too
    – MadyYuvi
    Jun 27, 2023 at 7:54
3

Use the tufte-book class marginfigure.

1
  • your information is useful for me. :) Dec 3, 2010 at 1:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .