1

I am seeking to add chapter headings to my list of figures, tables etc. I could not find a solution in the memoir manual, although the solution is probably contained within it I do not know what I am looking for exactly so my apologies.

I have modified RicoRally's EDIT solution here to apply to chapters but memoir is not detecting the titles or they are called something else which I do not know. The code with \documentclass{memoir} produces this lof:

List of figures memoir class

Whereas the code with \documentclass{report} produces this lof:

List of figures Report class

The code that I am using is:

\documentclass[oneside]{memoir}

\usepackage{lipsum} \usepackage{etoolbox}

\makeatletter \def\thischaptertitle{}\def\thischapternumber{} \newtoggle{noFigs}

\apptocmd{@chapter}% {\gdef\thischaptertitle{#1}\gdef\thischapternumber{\thechapter}% \global\toggletrue{noFigs}}{}{}

\AtBeginDocument{% \AtBeginEnvironment{figure}{% \iftoggle{noFigs}{ \addtocontents{lof}{\protect\contentsline {chapter}% {\protect\numberline {\thischapternumber.} {\thischaptertitle}}{}{} } \global\togglefalse{noFigs} }{} }% }

\long\def@caption#1[#2]#3{% \par \gdef\my@caption{#2} \begingroup @parboxrestore \if@minipage @setminipage \fi \normalsize @makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par \endgroup}

\renewenvironment{figure}% {@float{figure}}% {\end@float \addcontentsline{lof}{figure}% {\protect\numberline{\thefigure}{\my@caption}}% }% \renewenvironment{figure*}% {@dblfloat{figure}}% {\end@dblfloat \addcontentsline{lof}{figure}% {\protect\numberline{\thefigure}{\my@caption}}% }% \makeatother

%\usepackage{hyperref}

\begin{document} \listoffigures \chapter{Testing} \lipsum \section{Hallo} \begin{figure}[t] \caption{First figure} Test \end{figure} \begin{figure}[b] \caption{Second figure} Test \end{figure} \chapter{Hallo} \lipsum \section{Hallo} \begin{figure}[t] \caption{First figure} Test \end{figure} \begin{figure}[b] \caption{Second figure} Test \end{figure} \end{document}

I sort of get the gist of the code between \makeatletter and \makeatother although I do not understand what the \long\def section is doing. If anyone could help me add chapter headings to the memoir lof I would appreciate it.

Neither the memoir or report code works with hyperref either, it gives this error message:

Package hyperref Warning: old lof file detected, not used; run LaTeX again.

[1{c:/texlive/2021/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] [2] ! Undefined control sequence. <argument> ...umberline {\thefigure }{\my@caption }}{\thepage }{@currentHre... l.60 \end{figure}

If someone could help me with that in the same breath I would sincerely appreciate it although I could ask it as a separate question if needed.

  • 1
    Thank you for your fieedback!! – Simon Dispa Jul 03 '21 at 21:19
  • 1
    Memoir doesn't use \@chapter. It does however use \@m@mchapter where #1 contains the (short) title. – John Kormylo Jul 04 '21 at 17:00
  • @JohnKormylo By changing \gdef\thischaptertitle{#1}\gdef from #1 to #2 the code worked perfectly as is, in case anyone in the future runs into this issue. Thank you for that, nice one! –  Jul 04 '21 at 23:06

2 Answers2

2

Use in chapters containing figures:

\addcontentsline{lof}{chapter}{\thechapter.\;~Testing}

after \chapter{Testing} and so on.

UPDATED

Use \chapterlof after any \chapter{..} with figures.

d

A simple memoir MWE with hyperref

\documentclass[oneside]{memoir}

\usepackage{lipsum} \usepackage{hyperref}

%**************************** added \makeatletter \def\printchaptertitle#1{\chaptitlefont #1 \gdef\thischaptertitle{#1}}% \makeatother

\cftsetindents{figure}{1.5em}{2.3em} %indent

\newcommand{\chapterlof}{\addcontentsline{lof}{chapter}{\thechapter.;~\thischaptertitle}}% add chapter to lof %*****************************************

\begin{document}

\listoffigures

\chapter{Testing}
\chapterlof % add chapter to lof \lipsum \section{Hallo} \begin{figure}[t] \caption{First figure} Test \end{figure} \begin{figure}[b] \caption{Second figure} Test \end{figure} \chapter{Hallo} \chapterlof \lipsum \section{Hallo} \begin{figure}[t] \caption{First figure} Test \end{figure} \begin{figure}[b] \caption{Second figure} Test \end{figure} \chapter{Bye} \end{document}

Simon Dispa
  • 39,141
  • Thank you for your reply, I was hoping for something more automatic as it is for my thesis which will have lof, lot, list of equations and list of chemical schemes (the beauty of doing chemistry/enzymes) but as that does indeed do what I need I will +1 and hold it in reserve whilst I try harder to work it out. Thank you! –  Jul 03 '21 at 21:15
  • Thank you so much for that edit, that is exactly what I needed! –  Jul 03 '21 at 21:19
  • 1
    @LaccaseTVersicolor I updated the answer. – Simon Dispa Jul 03 '21 at 21:19
2

I thank Simon Dispa for his answer and I note your comment about "something more automatic". The following is a version of Simon's answer that automatically adds chapters to the LoF

% chapinlofprob.tex  603616 (A modified version of Simon Dispa's answer)

\documentclass[oneside]{memoir}

\usepackage{lipsum} \usepackage{hyperref}

%**************************** added \newcommand{\chapterlof}{\addcontentsline{lof}{chapter}{\thechapter.;~\thischaptertitle}}% add chapter to lof

%%%% PW deleted %\makeatletter %\def\printchaptertitle#1{\chaptitlefont #1 \gdef\thischaptertitle{#1}}% %\makeatother

\cftsetindents{figure}{1.5em}{2.3em} %indent

%*****************************************

\begin{document}

\tableofcontents \listoffigures

%%%% PW added here \makeatletter \def\printchaptertitle#1{\chaptitlefont #1 \gdef\thischaptertitle{#1}\chapterlof}% \makeatother

\chapter{Testing}
%\chapterlof % add chapter to lof PW deleted \lipsum \section{Hallo} \begin{figure}[t] \caption{First figure} Test \end{figure} \begin{figure}[b] \caption{Second figure} Test \end{figure} \chapter{Hallo} %\chapterlof % PW deleted \lipsum \section{Hallo} \begin{figure}[t] \caption{First figure} Test \end{figure} \begin{figure}[b] \caption{Second figure} Test \end{figure} \chapter{Bye} \end{document}

enter image description here

Note that if the definition of \printchaptertitle comes before the \listoffigures then various unnumbered chapter-like titles can be added to the LoF; that is why I put it just before the first numbered chapter.

Peter Wilson
  • 28,066