6

I'm trying to use \AtBeginEnvironment{figure} to customize the font family and font size used in figures. However, it doesn't seem to have any effect. Here is a minimal example:

\documentclass{memoir}
\usepackage{etoolbox}

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

\begin{document}

\begin{figure}
  % \tiny % this works
  test
\end{figure}

\end{document}

Any ideas on what's happening here?

EDIT: Forgot to mention that I'm using memoir. The solution found in another question works for setting the font family, but not the size.

  • There's a very similar question here: tex.stackexchange.com/questions/64514/… In that question \small is the command to add, but the solution should be the same. If this helps you, please let us know so that we can close this question as duplicate; otherwise, please tell why the solution doesn't apply to your case. – egreg Apr 2 '13 at 15:42
  • @egreg: Ah, knew there would be someone who had had this problem before... Just couldn't find it. =) Well, it now sets the font family, but the size is not affected. Apparently memoir is doing something here... – gablin Apr 2 '13 at 16:18
  • 1
    @gablin No idea what the underlying problem is, but memoir provides its own hooks for floats: \setfloatadjustment{figure}{\sffamily\tiny}. There is also \setfloatadjustment{table}{<code>}. – Audrey Apr 2 '13 at 16:24
  • @Audrey: That did it! Can you please write it as an answer so I can accept it? – gablin Apr 2 '13 at 16:25
  • @Audrey That's exactly what I found. Please, add an answer. – egreg Apr 2 '13 at 16:25
5

The memoir class provides its own hooks for floats:

\setfloatadjustment{figure}{\sffamily\tiny}

In general to invoke <code> at the beginning of every <floatname>, add the following to your preamble:

\setfloatadjustment{<floatname>}{<code>}
| improve this answer | |
0

If you’re not using the memoir class, the following should work:

% Redefine figure environment so that all figures are centered and use tiny sans-serif font
\makeatletter
\let\figureorig\figure
\def\figure@i[#1]{\figureorig[#1]\centering\sffamily\tiny}  % with optional argument
\def\figure@ii{\figureorig\centering\sffamily\tiny}  % without optional argument
\def\figure{\@ifnextchar[\figure@i \figure@ii}  % Redefine depending on presence of [
\makeatother

% Redefine table environment so that all tables are set in tiny sans-serif font
\makeatletter
\let\tableorig\table
\def\table@i[#1]{\tableorig[#1]\sffamily\tiny}  % with optional argument
\def\table@ii{\tableorig\sffamily\tiny}  % without optional argument
\def\table{\@ifnextchar[\table@i \table@ii}  % Redefine depending on presence of [
\makeatother

The relatively complicated redefinition results from the fact that the figure and table environments can carry optional arguments. Thus, the redefinition looks for an opening square bracket “[” in order to determine whether an optional argument is provided or not.

| improve this answer | |

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.