[Tex/LaTex] Change font size of caption, only in marginpar

captionsgraphicsmarginpar

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}

Best Answer

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