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}

1 Answer 1

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

7
  • 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
    Commented May 7, 2014 at 10:44
  • @eivindml I cannot reproduce this problem, when I put your code into the newcommand definition it still works fine.
    – d-cmst
    Commented May 7, 2014 at 10:52
  • Probably bad wording from my side. This reproduces the problem: writelatex.com/1043352nrxmxb#/2438143
    – eivindml
    Commented May 7, 2014 at 10:54
  • @eivindml when I put your captionsetup[figure] inside the newcommand it works also in writeLaTeX: writelatex.com/1043352nrxmxb#/2438143
    – d-cmst
    Commented May 7, 2014 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
    Commented May 7, 2014 at 11:04

You must log in to answer this question.

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