Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The incompatibility of having a float inside the solutions box of the exam class is somewhat well known. Multiple solutions for this exist, almost all of which use some variant of the caption package and the minipage environment.

Why doesn't simply wrapping the figure inside a minipage environment work?

I tried

share|improve this question
Does the exam class define a figure environment which you can redefine? –  Johannes_B Aug 23 at 17:43
No. But graphicx(?) does. –  user2751530 Aug 23 at 18:27
I guess its time for a minimal working example (MWE) –  Johannes_B Aug 23 at 18:36

1 Answer 1

exam is based on article, and thus the figure environment is defined. You can define a new environment using a minipage, but i do not recommend to redefine the original figure-environment. But doing this, the order of the figures (and the captions) can be messed up pretty badly. You need to decide, let them all float, or let none float.

--Edit-- @tohecz made me aware of the solution environment. This is a serious thing. Traditional floats will just be lost. The just defined questionfigure environment works, but there is another thing. There is a switch to print answers, or not. If not, the counter will still be refstepped and can make everything look more than odd if no answers are printed. I would recommend to define separate environments for questions (always printed) and answers/solutions (only printed if toggled). This would take care of the numbering. But then a question arises: Do you need figures that can be referenced if inside a framed (default) environment?

I defined two separate environments and gave them pretty dumb names. Referencing to figures in question will always work, no matter if called from a question or an answer. Referencing from answers to other answers (or rather the pics in them) works as well. Referencing an answerfigure in a question will not work if printanswers is false, but what would be the use-case? »Ha Ha, there will be a real great image in the answer, but can't see it!«

Disclaimer: If you compile the following (and you should) you need to use your imagination. No ducks were harmed while writing this answer.

]{exam}%based on article
listname={List of questionfigures},
listname={List of answerfigures},

%Print the list of afigures only if answers toggled
    \question Name a place where the lights are always on.
        \begin{solution} The light in my fridge is always
            \caption{Almost all refridgerators
                provide the feature of \emph{eternal}
        \question Look at the following picture. What do
        you conclude?
        \caption{An open fridge. What do you conclude?}
        Seeing the footprints in the butter, i can conclude that there must
        have been an elephant in there earlier.
    \question Homer was one of the greatest greek
    philosophers. Sum up his philosophy in as few words as
        Beer, Donuts.
    \question Nucleaar weapons are terrible. Describe and
    explain the physical reactions of an atomic bomb.
        A picture is worth more than a thousand words.
           _.-^^          -~_
        _--                  --_
        <                       >)
        |                        |
        \._                   _./
           ```--. . , ; .--'''
             | |   |
              .-=||  | |=-.
             | ;  :|
    \question When to \emph{Duck and cover}?
    \begin{solution} See \autoref{boom}!
\question{Is it easy to change a refridgerator light bulb?}
\begin{solution} Sure, according to \autoref{fridge} an elephant
    lives in there. Just place the light bulb inside, the
    elephant will do the work.
\question You see a block of iron glowing with an orange color
(see the picture).
What does that tell you about the temperature?
    \caption{A gloowing block of iron}
\begin{solution} Oh, that's hot. Can't touch this!
\question Did you ever use Plan 9 from Bell Labs?
\begin{solution} 42! Glenda is cool. See \autoref{boom}. 
share|improve this answer
Thanks!! I was away from work for a few days. Yes, I do need the ability to refer to these figures. –  user2751530 Sep 1 at 9:46
@user2751530 I'll have a look at it. –  Johannes_B Sep 1 at 9:50
@user2751530 Sorry, your request somehow got lost in my stack. I extended my answer a little bit. –  Johannes_B Sep 20 at 15:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.