LOF 中的圖表按章節分組(包含章節號,但不包含頁碼)

LOF 中的圖表按章節分組(包含章節號,但不包含頁碼)

我有一個似乎無法解決的問題:

我的圖表清單按章節分組,每章的圖表之間有一個空格。我想要的不僅是空間,還有一個章節標題,說明章節的編號和標題,但是不是章節的頁碼。

有什麼辦法可以做到這一點嗎?最好沒有這個tocloft包,由於某種原因,它在 TOC 和 LOF 的頂部添加了巨大的空間,我似乎無法擺脫它。此外,當我包含它時,LOF 不會顯示在目錄中。

有任何想法嗎?

編輯:我不知道這是否符合最小範例的要求,但這將是我展示問題的範例。

\documentclass[12pt,headsepline,toc=bibliography,toc=listof]{scrreprt}

\begin{document}
\chapter{Chapter 1}
\begin{figure}
\caption{Figure 1}
\end{figure}
\begin{figure}
\caption{Figure 2}
\end{figure}

\chapter{Chapter 2}
\begin{figure}
\caption{Figure 3}
\end{figure}

\listoffigures

\end{document}

這會產生以下結果。 在此輸入影像描述 您可以看到這些圖表按章節分組列出,各章之間有一個空格。我希望它在每個組上方顯示“(章節編號)(空格)(章節標題)”,但旁邊沒有頁碼(不過,數字旁邊的頁碼應該仍然可見)。我所說的(空間)是指足夠的空間,以便章節標題的第一個字母的起始位置與所列出的數字的數字完全相同。

答案1

有一個 KOMA 選項可以在所有清單中插入所有章節:( chapteratlists=entrychapteratlistslistof=chapterentry

如果章節頁碼不應顯示在圖片清單 (lof) 中,您可以使用\AfterTOCHead[lof]{\addtokomafont{chapterentrypagenumber}{\nullfont}}

在此輸入影像描述

代碼:

\documentclass[12pt,headsepline,toc=bibliography,toc=listof,chapteratlists=entry]{scrreprt}

\AfterTOCHead[lof]{\addtokomafont{chapterentrypagenumber}{\nullfont}}

\begin{document}
\chapter{Chapter 1}
\begin{figure}
\caption{Figure 1}
\end{figure}
\begin{figure}
\caption{Figure 2}
\end{figure}

\chapter{Chapter 2}
\begin{figure}
\caption{Figure 3}
\end{figure}

\listoffigures
\tableofcontents

\end{document}

更新

我找到了一個馬庫斯·科姆的建議如果本章中至少有一個圖(表,...),則僅在圖(表,...)清單中插入該章。

\documentclass[12pt,headsepline,toc=bibliography,toc=listof,chapteratlists=entry]{scrreprt}

\AfterTOCHead[lof]{\addtokomafont{chapterentrypagenumber}{\nullfont}}
\AfterTOCHead[lot]{\addtokomafont{chapterentrypagenumber}{\nullfont}}

%%%%% from http://www.komascript.de/comment/5070#comment-5070 (Markus Kohm)
\makeatletter
\let\chapterhas@original@addcontentsline\addcontentsline
\renewcommand*{\addcontentsline}[1]{%
  \immediate\write\@auxout{\string\chapterhas{\thechapter}{#1}}%
  \chapterhas@original@addcontentsline{#1}%
}
\newcommand*{\chapterhas}[2]{%
  \global\@namedef{chapterhas@#1@#2}{true}%
}
\renewcommand*{\addchaptertocentry}[2]{%
  \addtocentrydefault{chapter}{#1}{#2}%
  \if@chaptertolists
    \doforeachtocfile{%
      \iftocfeature{\@currext}{chapteratlist}{%
        \ifundefinedorrelax{chapterhas@\thechapter @\@currext}{%
        }{%
          \addxcontentsline{\@currext}{chapteratlist}[{#1}]{#2}%
        }%
      }{}%
    }%
    \@ifundefined{float@addtolists}{}{\scr@float@addtolists@warning}%
  \fi
}
\makeatother
%%%%

\begin{document}
\chapter{Chapter 1}
\begin{figure}
\caption{Figure 1}
\end{figure}
\begin{figure}
\caption{Figure 2}
\end{figure}

\chapter{Chapter 2}

\chapter{Chapter 3}
\begin{figure}
\caption{Figure 3}
\end{figure}
\begin{table}
\caption{Table 1}
\end{table}

\listoffigures
\listoftables
\tableofcontents

\end{document}

運行三次即可得到

在此輸入影像描述

相關內容