This question may sound similar to what has been asked before, but I tried to do a minimalistic implementation (stealing some code from the verbatim package). Also I don't really know TeX, just basic LaTeX.

Anyway: I have implemented my own variant of subfigures and I use captions on the bottom. That code works well, but if I generate a list of figures, the subfigure captions are emitted before the main caption, like in:

1.2a Blabla
1.2b More blabla
1.2 Another caption

I want to reorder the entries by saving the subfigures' \addcontentsline until the \addcontentsline of the main figure was output. So I made some simplistic code that seems to work within one paragraph (lofLines is the buffer for "list-of-figures lines"):

\newtoks\lofLines% storage
\def\lofLinesEmpty{\lofLines{}}% empty storage
\def\lofLinesAdd#1{\lofLines\expandafter{\the\lofLines#1}}% append to storage
\def\lofLinesOut{\expandafter{\the\lofLines}}% output storage

A short sample document (without the figure stuff) would be:

% ...
\newtoks\lofLines% storage
\def\lofLinesEmpty{\lofLines{}}% empty storage
\def\lofLinesAdd#1{\lofLines\expandafter{\the\lofLines#1}}% append to storage
\def\lofLinesOut{\expandafter{\the\lofLines}}% output storage
\lofLinesEmpty% initialize
Some text...
More text

This document outputs the text as:

Some text... More text aa

So it works as intended (in my simple view of things), but when I want to save and restore actual \addcontentslines within some commands and environments I wrote for managing the figures, they are never written to the .lof file. To me it looks as if the contents got lost between commands, environments and floats, because not even simple plain text did survive the patch from subfigure caption to main text...

An example of such a line looks like this:


Most likely the problem is my limited understanding of TeX internals.

  • As best I can tell with subcaption, all the subcaptions are stored in macros until the next caption, if there is a caption. If not, the subcaptions are sent immediately (before the labels). The big question is, how does it know? Apr 5, 2019 at 3:11

1 Answer 1


Considering all the things one has to do to get subcaptions to work right in the LOF, it is easier to use the subcaption package and set \@captype (if needed).

This is based on another question.



\expandafter\def\csname @captype\endcsname{figure}% fake figure
\caption{subcaption 1}
\caption{subcaption 2}



  • Actually I had this thought (using subfigure, subcaption) when I had another problem with my implementation (which I could solve). But (unless as most, I guess) I don't want just a solution for my problem, I also want to understand and learn, thus I'm interested in an answer to my question (if any).
    – U. Windl
    Apr 5, 2019 at 20:15
  • As I said earlier, it seems that the subcaption \addcontents entries are stored in a macro, \caption@subcontentslines which are later expanded by \flushsubcaptionlistentries after the next caption. Apr 6, 2019 at 16:27

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.