在 LOF 中将数字压缩为单行

在 LOF 中将数字压缩为单行

服用这个问题进一步发展,并考虑到与 Christian Hupfer 的对话问题,下面的代码是我迄今为止所做的最小示例,目的是将许多相邻的类似图表压缩为图表列表中的一行。

在下面,原本是 12 行,现在减少到 1 行,图号被一系列数字取代,页码也是如此。超链接指向该系列中的第一张图片。

需要记住的是,数字线需要增加宽度,而且需要额外的右边距来容纳一系列页码(比通常所需宽度多一倍多一点)。

我想知道是否有更好的方法来做到这一点,以便取代下面addtocontents使用的自定义宏里面使用的宏。addfigurerange

非常棒的附加功能是将范围内的图像数量计数附加到行项目中,例如,以下条目可以变成:1400 -- 300K 温度下的绘图(12 张图)。这当然手动完成很简单,但如果计数可以作为宏的一部分自动完成,那就太好了。

\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}

这会产生以下结果。

结果

答案1

此方法使用listofitems包来实现简单的调用语法

\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>}

其中,枚举图形列表为#1,图形标题的模板为#2,组标题的模板为#3,图像的文件名根为#4。模板中的 的使用***是文字性的,而不是比喻性的。宏将解析模板并用适当的参数或参数范围替换***。限制是*** 必须仅出现一次在图形和组标题模板中均如此。此外,它不能出现在组内,因此\texttt{***}必须将其显示为\ttfamily ***\rmfamily

MWE 经过编辑,使用实际图像,而不是演示模式,即

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

妇女权利委员会:

\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}

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

相关内容