2

I'm using \marginpar and \captionof to have figures appearing in the margins of my documents, including figure captions. This works well. But now I want to change to font size of the captions appearing in the margins (including the "Figure 1" text), but not the captions of the figures appearing in the main body (Figure 2).

How can I achieve this?

Minimal working example:

\documentclass[a4paper]{article}
\usepackage[demo]{graphicx}
\usepackage{caption,lipsum}


\begin{document}

\section{Introduction}

\lipsum[1]
\marginpar{
    \includegraphics[width=\marginparwidth]{demo.pdf}
    \captionof{figure}{Change this.}
}
\lipsum[1]

\begin{figure}[h]
\centering \includegraphics[scale=1]{}
\caption{Not change this.}
\end{figure}

\end{document}
4

If you want the caption of all margin figures to be smaller, you can create a custom \marginpar command which embed a custom caption setup. Like this:

\documentclass[a4paper]{article}
\usepackage[demo]{graphicx}
\usepackage{caption,lipsum}

\newcommand{\mymarginpar}[1]{\marginpar{\captionsetup{font=footnotesize}#1}} %new code
\begin{document}

\section{Introduction}

\lipsum[1]
\mymarginpar{                                   %modified code
    \includegraphics[width=\marginparwidth]{demo.pdf}
    \captionof{figure}{Change this.}
}
\lipsum[1]

\begin{figure}[h]
\centering \includegraphics[scale=1]{}
\caption{Not change this.}
\end{figure}

\end{document}

enter image description here

  • Thanks for the reply! The minimal working example above works great. But when I tried this on my final document, it did not work. I located the conflict, and it won't work when I include this piece of code, even if I put it above the new command definition: \captionsetup[figure]{labelfont={sf,bf},margin=1cm,font=sf} Any solutions for this? – eivindml May 7 '14 at 10:44
  • @eivindml I cannot reproduce this problem, when I put your code into the newcommand definition it still works fine. – Nico Vecchio May 7 '14 at 10:52
  • Probably bad wording from my side. This reproduces the problem: writelatex.com/1043352nrxmxb#/2438143 – eivindml May 7 '14 at 10:54
  • @eivindml when I put your captionsetup[figure] inside the newcommand it works also in writeLaTeX: writelatex.com/1043352nrxmxb#/2438143 – Nico Vecchio May 7 '14 at 11:01
  • Yes, but I do not want to have that inside! I want to have same styling for both (sffamily and bold), but have additional styling of the margin caption (footnotesize). Like the writeLaTeX link I linked above. – eivindml May 7 '14 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.