如何使用 KOMA 获得多个图形列表(LoF)?

如何使用 KOMA 获得多个图形列表(LoF)?

这个问题有一个很好的答案和解决方案克里斯蒂安·胡普弗它不工作,KOMA-Script很遗憾。

问题是如何listof在一个文档中获取多个?

\documentclass{scrbook}

\usepackage{xparse}
\usepackage{xpatch}
\usepackage{caption}
\usepackage{blindtext}


% Do not a driver counter, i.e. a resetting counter for those two counter fellows here:
\newcounter{lofcntr}
\newcounter{lotcntr}


\NewDocumentCommand{\clearcontents}{}{%
  \stepcounter{lofcntr}% We don't need labels here, I suppose?
  \stepcounter{lotcntr}%
  \setcounter{figure}{0}
  \setcounter{table}{0}
}

\AtBeginDocument{%
  \stepcounter{lofcntr}% 
  \stepcounter{lotcntr}%
}


\makeatletter
% Store the definition of \ext@figure etc. first
\let\latex@ext@figure\ext@figure
\let\latex@ext@table\ext@table

\AtBeginDocument{%
\xpretocmd{\caption}{%
  % Prepend the extension with the number of the current list of ...
  \def\ext@figure{\number\value{lofcntr}\latex@ext@figure}
  \def\ext@table{\number\value{lotcntr}\latex@ext@table}
}{\typeout{Worked!}}{\typeout{Failed miserably!}}
}


\xpatchcmd{\listoffigures}{%
  \@starttoc{lof}%
}{%
  \@starttoc{\number\value{lofcntr}lof}%
}{\typeout{Patch success}}{\typeout{Patch failure}}

\xpatchcmd{\listoftables}{%
  \@starttoc{lot}%
}{%
  \@starttoc{\number\value{lotcntr}lot}%
}{\typeout{Patch success}}{\typeout{Patch failure}}

\makeatother



\begin{document}
\tableofcontents
\listoffigures
\listoftables


\captionof{figure}{Some figure caption for 1st lof}
\captionof{figure}{Some figure caption for 1st lof}
\captionof{figure}{Some figure caption for 1st lof}
\captionof{figure}{Some figure caption for 1st lof}

\captionof{table}{Some table caption for 1st lot}
\captionof{table}{Some table caption for 1st lot}
\captionof{table}{Some table caption for 1st lot}
\captionof{table}{Some table caption for 1st lot}

\clearcontents
\listoffigures
\listoftables


\captionof{figure}{Some figure caption for 2nd lof}
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{figure}{Some figure caption for 2nd lof}


\captionof{table}{Some table caption for 2nd lot}
\captionof{table}{Some table caption for 2nd lot}
\captionof{table}{Some table caption for 2nd lot}
\captionof{table}{Some table caption for 2nd lot}
\end{document}

问题是列表的名称没有正确显示并设置为新页面(常见行为?!): 在此处输入图片描述

在此处输入图片描述

是否有可能完全删除标题并且使其不会在新页面上开始?


编辑:我也很乐意使用不同的代码。至少它可以工作,KOMA并且与上面的代码一样容易采用。

答案1

以下是使用链接的建议Christian 的回答网站上KOMA-Script关于额外 LoF 的建议。如果 LoF 不应开始新页面,则它不应是章节。因此您必须使用选项listof=leveldown

\documentclass[%
  listof=totoc,% ToC entry for all LoFs and similar lists
  listof=leveldown]% LoF and similar lists as section instead chapter
{scrbook}
\usepackage{xparse}
\usepackage{blindtext}% only for dummy text

\newcounter{lofcntr}

\makeatletter
\NewDocumentCommand{\clearlof}{}{%
  \stepcounter{lofcntr}%
  \setcounter{figure}{0}%
  \DeclareNewTOC
    [listname=\protect\listfigurename]
    {\number\value{lofcntr}lof}%
  \renewcommand*{\ext@figure}{\number\value{lofcntr}lof}%
}
\makeatother

\AtBeginDocument{\clearlof}

\begin{document}
\tableofcontents
\chapter{First Chapter}
\listoffigures
\captionof{figure}{Some figure caption for 1st lof}
\captionof{figure}{Some figure caption for 1st lof}

\chapter{Secound Chapter}
\clearlof
\listoffigures
\captionof{figure}{Some figure caption for 2nd lof}
\captionof{figure}{Some figure caption for 2nd lof}

\chapter{Third Chapter}
\clearlof
\listoffigures
\captionof{figure}{Some figure caption for 3nd lof}
\captionof{figure}{Some figure caption for 3nd lof}
\end{document}

在此处输入图片描述

在此处输入图片描述

但如果您需要超过 12 个额外的 LoF,您将获得

没有空间容纳新的\write

错误。请注意,即使使用标准类,您的 MWE 也具有相同的限制。

如果您需要更多 LoF,您可以加载KOMA-Scriptscrwfile(alpha-status)。

\documentclass[
  listof=totoc,% ToC entry for all LoFs and similar lists
  listof=leveldown% LoF and similar lists as section instead chapter
]{scrbook}
\usepackage{xparse}
\usepackage{scrwfile}% if there are more than 12 additional aux files needed
\usepackage{blindtext}% only for dummy text

\newcounter{lofcntr}

\makeatletter
\NewDocumentCommand{\clearlof}{}{%
  \stepcounter{lofcntr}%
  \setcounter{figure}{0}%
  \DeclareNewTOC
    [listname=\protect\listfigurename]
    {\number\value{lofcntr}lof}%
  \renewcommand*{\ext@figure}{\number\value{lofcntr}lof}%
}
\makeatother

\AtBeginDocument{\clearlof}% then the default lof is not used

\ExplSyntaxOn
\NewDocumentCommand\examplelofs{m}% only for dummy LoFs
  {
    \int_do_until:nNnn
      {\value{lofcntr}} = {#1}
      {
        \chapter{A~chapter}
        \clearlof
        \listoffigures
        \captionof{figure}{Some~figure~caption~for~\number\value{lofcntr}nd~lof}
        \captionof{figure}{Some~figure~caption~for~\number\value{lofcntr}nd~lof}
      }
  }
\ExplSyntaxOff

\begin{document}
\tableofcontents
\chapter{First chapter}
\listoffigures
\captionof{figure}{Some figure caption for 1st lof}
\captionof{figure}{Some figure caption for 1st lof}

\examplelofs{20}
\end{document}

相关内容