While trying to typeset examination papers in LaTeX, I've become the victim of shifting figure numbering standards laid down by my institution.

The old way required figures to be numbered like this:


which is to say Figure Q1, Figure Q1/B, Figure Q1/C, etc. (the A omitted on the first figure). Now we have to put the '/A' on the first figure, but if there's only one figure per question, leave the '/A' out all together. Questions are in an enumerated list at the top level; hence the \theenumi above.

So now, if Q2 had one figure, it would be Figure Q2. If it were followed by Q3 with two figures, they would be Figure Q3/A and Figure Q3/B.

  • 1
    Welcome to TeX.SX! The problem seems clear, but it's hard to understand where Q1 comes from. Can you present a minimal example in the “old style”?
    – egreg
    Nov 12, 2013 at 15:26
  • The simplest way would be \newif\ifsolefigure\renewcommand{\thefigure}{\theenumi\ifsolefigure\else/\Alph{figure}\fi\global\solefigurefalse} and manually insert \solefiguretrue in each item with only one figure. But this requires manual mark-up with this \solefiguretrue. (I anticipate though some problems if your figures are really in floats, but I personally would not use floats in such circumstances, and I would manually caption the figures).
    – user4686
    Nov 12, 2013 at 15:35
  • Sure! The real problem is most of my EE faculty use WYSIWYG products, and type figure numbers in by hand. I won't do this because (a) my students work really hard, so the least I can do is give them nice exam papers, and (b) for this course I need music (lilypondbook), electronic circuits (circuitikz) and code (lgrind)... unset rantmode... here's the example you requested (in ASCII): Nov 13, 2013 at 10:21
  • Q1. Look at Figure Q1. What is the letter?[br]A[br]Figure Q1. A Letter.[br]...figure 2/A...[br]Q2. (a) What is the digit in Figure Q2/A?[br]...figure 2/B...[br](b) Another digit is appended in Figure Q2/B. What's the number now?[br]I'm afraid they are floats. This was helping me a lot when there was a page of, say, orchestral score. But this could be lived without I suppose :( (Sorry, I don't know how to put line breaks in a comment... not doing too well, am I? :) ) Nov 13, 2013 at 10:28
  • @jfbu - thanks for the headsup on using the \newif. My plan was to detect that Figure Qx/B was ever captioned, the write something to the aux file. So if \thefigure was called to create the string Q2/B, it might write the \newifsolefigQ2true in the aux file. Then \thefigure would know to return Q2/A instead of Q2 along the lines you show. On a second pass, the figure strings would magically change. At the moment though, even my redef of figure messes up so that the positional argument doesn't get read (the auxfile says \newlabel{tbp}{{Q1}{2}}), so I'm not in a position to test that idea. :( Nov 13, 2013 at 10:41

1 Answer 1


Here's one possible way to achieve this:


It works by subverting the figure environment. When a second figure is supplied for a given question (the figure counter is used per question in this context, so I'm testing for its value being 2), a control sequence gets written in the aux file of the form

\gdef @MultiFigI {multifig}

where the trailing I corresponds to the question number in roman numeral form. Arabic numerals make it harder because they aren't normally allowed in control sequences, and there would no doubt be a load of \csnames all over the place if I went that way. {multifig} is a placeholder. Its value is never used, but it might come in handy one day.

\thefigure is overridden to test whether the current question is in fact a multi-figure one, and if it is, supplies the trailing \A, \B etc for all of the figures in the question.

My biggest hang-up was getting \@multiq right. Without the \expandafter\noexpand, the file would read first but on the second pass, you'd get items in the aux file like

\gdef multifig {multifig}

because the \@MultiFig would get expanded as it was written.

This solution has the following issues:

  • It adds etoolbox as a required package
  • It means you need three passes of the latex file to get the references right (but the tool I use to build the document, Kile, sorts this out automatically)

You must log in to answer this question.

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