1

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:

\documentclass[a4paper,twoside]{report}
\usepackage{german}
\usepackage[latin1]{inputenc}
\usepackage{a4}
% ...
\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
\begin{document}
\lofLinesEmpty%
\lofLinesAdd{aa\\bb}
Some text...
\lofLinesAdd{ccc}
More text
\lofLinesOut
\end{document}

This document outputs the text as:

Some text... More text aa
bbccc

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:

\lofLinesAdd{\addcontentsline{lof}{figure}{\protect%
\numberline{\thesubfigureX}{\ignorespaces{}#1}}}%

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

1
  • 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

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.

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage[list=true]{subcaption}


\begin{document}
\listoffigures

\vspace{\intextsep}%
\begin{minipage}{\textwidth}
\expandafter\def\csname @captype\endcsname{figure}% fake figure
\centering
\begin{subfigure}[t]{.5\textwidth}
\centering
\includegraphics[width=0.9\textwidth]{example-image-a}
\caption{subcaption 1}
\label{fig:sub1}
\end{subfigure}%
\begin{subfigure}[t]{.5\textwidth}
\centering
\includegraphics[width=0.3\textwidth]{example-image-b}
\caption{subcaption 2}
\label{fig:sub2}
\end{subfigure}
\caption{Caption}
\label{fig:fig} 
\end{minipage}

\end{document}

demo

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.