2

Taking THIS question one step further, and given the dialogue with Christian Hupfer following THIS question, the following code is a minimum example of what I have done so far in oder to condense many adjacent similar plots into a single line in the list of figures.

In the below, what was originally 12 lines, is now reduced to 1 line, with the figure number replaced by a range of numbers, and similarly for the page numbers. The hyperlink points to the first image in the series.

Things to bear in mind, are the increased width required in the numberline, and also, the additional right margin required to accommodate a range of page numbers (bit over twice the width ordinarily required).

I would like to know if there is a better way to do this, in order to replace the use of the addtocontents macro used inside the custom addfigurerange macro used below.

Additional functionality which would be awesome, would be to append to the line item a count of the number of images in the range like for example, the below entry could become: Plots at temperatures of 1400 -- 300K (12x Figures). This is of course trivial to do manually, but it would be great if the count could be automated as part of the macro.

\documentclass{memoir}
\usepackage{hyperref}
\usepackage{pgffor}
\usepackage{caption}
\usepackage[demo]{graphicx}

\setpnumwidth{10mm}
\setrmarg{12mm}
\makeatletter
     \renewcommand*\l@figure{\@dottedtocline{1}{1em}{6em}}
\makeatother


%% First argument is the line to add to the LOF, 
%% 2nd and 3rd arguments are the start and finish labels in the range
\newcommand\addfigurerange[3]{%
    \addtocontents{lof}{
        \protect\contentsline
        {figure}
        {\numberline{\getrefnumber{#2} -- \getrefnumber{#3}}{\ignorespaces #1}}
        {\getpagerefnumber{#2} -- \getpagerefnumber{#3}}
        {\getrefbykeydefault{#2}{anchor}{}}%
    }%
}

\begin{document}

    \listoffigures
    \clearpage

    \chapter{First Chapter}

    \foreach \x in {1400, 1300, 1200, 1100, 1000, 900, 800, 700, 600, 500, 400, 300}{
            \begin{figure}[p]
            \captionsetup{list=no}%
            \includegraphics[width=\linewidth,height=10cm]{dummy}
            \caption{Some Plot at a Temperature of \x{}K}\label{fig:\x}
            \end{figure}
    }
    \addfigurerange{Plots at temperatures of 1400 -- 300K}{fig:1400}{fig:300}

\end{document}

This produces the following result.

Result

3
  • Your MWE is not complete...no \documentclass and also \setpnumwidth undefined. Aug 9, 2017 at 12:28
  • 1
    oops sorry... missed the first line Aug 9, 2017 at 12:30
  • You don't have to use \contentsline or \numberline. You can just format it yourself with \makebox and \hfill. Okay, adding dots (leaders) can be tricky. Aug 9, 2017 at 13:00

1 Answer 1

3

This approach uses the listofitems package to achieve a simple invocation syntax of

\multifig{1400, 1300, 1200, 1100, 1000, 900, 800, 700, 600, 500, 400, 300}
  {Some Plot at a Temperature of ***K}
  {Plots at temperatures of ***K}
  {<filename-root>}

Where the enumerated figure list is given as #1, the stencil for the figure caption is given as #2, the stencil for the group caption is given as #3, and the filename root for the images is given as #4. The use in the stencils of *** is literal, not figurative. The macro will parse the stencils and substitute, for ***, the appropriate argument or argument range. A limitation is that the *** must only appear once in both the figure as well as the group caption stencil. Furthermore, it cannot appear inside a group, so that \texttt{***} must instead be presented as \ttfamily ***\rmfamily.

The MWE, EDITED to use actual images, rather than demo mode, that is,

\multifig{A, B, C}
{The \protect\LaTeX{} example image \ttfamily example-image-***\rmfamily}
{Example Figures ***}
{example-image-}

The MWE:

\documentclass{memoir}
\usepackage{hyperref}
\usepackage{pgffor}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{listofitems}
\setpnumwidth{10mm}
\setrmarg{12mm}

\makeatletter
     \renewcommand*\l@figure{\@dottedtocline{1}{1em}{6em}}
\makeatother


%% First argument is the line to add to the LOF, 
%% 2nd and 3rd arguments are the start and finish labels in the range
\newcommand\addfigurerange[3]{%
    \addtocontents{lof}{%
        \protect\contentsline%
        {figure}%
        {\numberline{\getrefnumber{#2} -- \getrefnumber{#3}}{\ignorespaces #1}}%
        {\getpagerefnumber{#2} -- \getpagerefnumber{#3}}%
        {\getrefbykeydefault{#2}{anchor}{}}%
    }%
}

\newcommand\multifig[4]{%
    \setsepchar{***}%
    \readlist\figurecaption{#2}%
    \readlist\groupcaption{#3}%
    \setsepchar{,}%
    \readlist*\myfiglist{#1}%
    \def\labelprefix{fig:}%
    \foreachitem \x \in \myfiglist{%
            \begin{figure}[p]%
            \captionsetup{list=no}%
            \includegraphics[width=\linewidth,height=10cm]{#4\x}%
            \xdef\tmp{\labelprefix\x}%
            \caption{\figurecaption[1]\x\figurecaption[2]}%
              \expandafter\label\expandafter{\tmp}%
            \end{figure}%
    }%
    \xdef\tmpfirst{\myfiglist[1]}%
    \xdef\tmplast{\myfiglist[-1]}%
    \xdef\mycap{\groupcaption[1]\tmpfirst{} -- \tmplast\groupcaption[2]}%
    \xdef\labelfirst{\labelprefix\tmpfirst}%
    \xdef\labellast{\labelprefix\tmplast}%
    \def\tmpA{\expandafter\addfigurerange\expandafter{%
      \expandafter\mycap\expandafter}\expandafter{\labelfirst}}%
    \expandafter\tmpA\expandafter{\labellast}%
}

\begin{document}
    \listoffigures
    \clearpage

    \chapter{First Chapter}

      In Figure~\ref{fig:B}

    \multifig{A, B, C}
    {The \protect\LaTeX{} example image \ttfamily example-image-***\rmfamily}
    {Example Figures ***}
    {example-image-}
\end{document}

enter image description here

enter image description here

enter image description here

You must log in to answer this question.

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