2

I am trying to have some environments in my LaTeX document where the font in general is smaller than in the main text. This means that whenever I include a figure, the caption from the \begin{figure}... should have the same (smaller) font size. I found answers where the change is globally by providing the font size parameter to the caption package. Yet I was wondering if I could do this locally for some figures. Actually, I would like to know if this is possible in the definition of the exercise environment I have:

\usepackage[lastexercise]{exercise} % for exercise environment

% set font for exercise environment
\newcommand\ExerciseFont{\footnotesize}
\renewcommand\AtBeginAnswer{\ExerciseFont}
\renewcommand\AtBeginExercise{\ExerciseFont}

% change format of exercise environment
\renewcommand{\ExerciseHeader}{\ExerciseFont\textsc{
                \ExerciseName\ \ExerciseHeaderNB. \ExerciseHeaderTitle
                \ExerciseHeaderOrigin}}

% change font for answers header
\renewcommand{\AnswerHeader}{\ExerciseFont\textit{
                Solution:\ }}

Can I somehow change the font size for the figures in such environment?

1 Answer 1

3

You can define an \ExerciseCaption to use within the exercise. By using \captionsetup in caption.sty the caption can be changed locally.

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\newcommand\ExerciseCaption[1]{%
  \captionsetup{font=footnotesize}%
  \caption{#1}}
\begin{document}

\begin{figure}
  \centering
  \includegraphics[scale=0.3]{example-image-a}
  \caption{Test 1}
  \label{TA}
\end{figure}

\begin{figure}
  \centering
  \includegraphics[scale=0.3]{example-image-b}
  \ExerciseCaption{Test 2}
  \label{TB}
\end{figure}

Figure \ref{TA} and Figure \ref{TB}
\end{document}

enter image description here

8
  • Thanks for replying. I'm getting a Missing \endcsname inserted. error. Do you know why?
    – aaragon
    Jul 14, 2016 at 12:45
  • I cannot get the same error here. I have tried to include also the exercisepackage together with your settings, and a figure within an exercise. But it compiles as expected. Maybe you have some other included packages?
    – StefanH
    Jul 14, 2016 at 13:20
  • I have a lot of included packages. I'm using the subcaption package actually. Any ideas on how I can determine the source of the conflict?
    – aaragon
    Jul 14, 2016 at 13:21
  • I think subcaptionis part of caption so that should work. I would start with your original (compilable) document and just add \usepackage{caption}. If that works add \captionsetup{font=footnotesize} just before a caption. If that works it is only the command left.
    – StefanH
    Jul 14, 2016 at 13:31
  • 1
    The footnotesizeis an input parameter to caption, telling it to use \footnotesize. How that is internally handled is something else, and you can only give the per-specified inputs.
    – StefanH
    Jul 14, 2016 at 13:58

You must log in to answer this question.

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