# Trouble changing font size in figure legends

I'm trying to set the font size smaller in the legends for all of my figures and tables. The way I was trying to do this was using \AtBeginEnvironment but that doesn't seem to do anything at all. This is a minimal example of what is failing:

\documentclass[a4paper, 12pt]{report}

\usepackage{etoolbox}
\usepackage{relsize}

\AtBeginEnvironment{figure}{\smaller}

\begin{document}
\begin{figure}
\caption{whatever}
Text
\end{figure}

Outside text
\end{document}


Now that should, I think, make 'Text' appear smaller than 'Outside text' exactly as it would if you put the \smaller inside the figure environment. But it doesn't. I tried using the floatrow package instead but it messes up the ordering of the figure caption and the legend text and \captionsetup will only alter the caption itself not the legend text.

Any help? Why does \AtBeginEnvironment not work?

-

One of the last things the figure enviroment does is issuing the internal command \@floatboxreset whose definition is

\def\@floatboxreset{%
\reset@font
\normalsize
\@setminipage
}


and this is why the \smaller declaration has no effect, because the tokens in \AtBeginEnvironment are found earlier.

You should instead change the meaning of \@floatboxreset

\makeatletter
\AtBeginEnvironment{figure}{%
\def\@floatboxreset{\reset@font\small\@setminipage}%
}
\makeatother


The change will not leak outside the environment.

In case you're using setspace, something more should be done, as the package patches \@xfloat to issue again \normalsize, which is an error, in my opinion, as \selectfont would suffice.

\documentclass[a4paper, 12pt]{report}

\usepackage{etoolbox}
\usepackage{setspace}

\makeatletter
\AtBeginEnvironment{figure}{%
\def\@floatboxreset{\reset@font\small\@setminipage}%
}
\patchcmd{\@xfloat}{\normalsize}{\selectfont}{}{}
\makeatother

\begin{document}
\begin{figure}
\caption{whatever}
Text
\end{figure}

Outside text
\end{document}

-
Thank you, egreg. However, while that works perfectly in the minimal test environment, it fails to work in my real document. Do you know if any packages would interfere with it? –  Jack Aidley Jul 24 '12 at 12:31
Right, I found the responsible package - setspace stops it working - now I just need to figure out why –  Jack Aidley Jul 24 '12 at 12:39
Well, it seems that setspace messes with the float setup functions so that \@floatboxreset never gets called. By altering your suggestion so that instead of redefining \@floatboxreset it does \apptocmd{\@xfloat}{\small}{}{} I was able to get it to work. –  Jack Aidley Jul 24 '12 at 12:54
@JackAidley I've added a better patch than yours (which would affect also the table environment). –  egreg Jul 24 '12 at 13:00
@JackAidley To begin with, the patch is simpler; moreover it will do what setspace should be doing in the first place. –  egreg Jul 24 '12 at 13:40

One way might be to redeclare the @makecaption command.
First we define the font and size for the caption-Title (figure or table) and the font for the caption-text. Then \@makecaption is rewritten:

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

\newcommand*{\textCapTitFont}[1]{\textbf{#1}}
\newcommand*{\Captionfont}{\small\sffamily}
\makeatletter
\long\def\@makecaption#1#2{%
\vskip\abovedisplayskip\Captionfont%
\setbox\@tempboxa\hbox{\textCapTitFont{#1}~~#2}%
\ifdim \wd\@tempboxa > \hsize
\textCapTitFont{#1}~~#2\par
\else
\hbox to \hsize{\hfill\box\@tempboxa\hfill}%
\fi
\vskip\belowcaptionskip}
\makeatother

\begin{document}
Some normal text, not beeing in a caption, just to compare
\begin{figure}\centering
\includegraphics[width=0.5\linewidth]{example-image-a}
\caption{This is an explanation \ldots}
\end{figure}
\end{document}


This looks like this:

-
The question is not about changing font size in the caption. –  egreg Jul 24 '12 at 14:19
@egreg It seems I missed something. But the fontsize in caption is changed to \small. The setting of \sffamily can be omitted. –  Peter Breitfeld Jul 24 '12 at 15:31
The question ends with "\captionsetup will only alter the caption itself not the legend text". Thus a "legend text" is not the caption. –  egreg Jul 24 '12 at 15:36
@egreg You can change the font for "Figure 1" and "This is an ..." individually, eg. setting \textCapTitFont to {{footnotesize#1} and \Captionfont to \Large`. Or am I still missing something? –  Peter Breitfeld Jul 24 '12 at 16:02
The OP wanted to change the font used in the body of the figure environment, not in the caption. –  egreg Jul 24 '12 at 16:39