KOMA 腳本 etoc 套件更改 TOC 標題和條目之間的垂直間距

KOMA 腳本 etoc 套件更改 TOC 標題和條目之間的垂直間距

根據問題KOMA 腳本清單和 LOF 標題下方的空間不相等我用目錄擴充了這個例子。我在文件中使用 etoc 包,KOMA 選項parskip=half更改 TOC 章節標題和 TOC 條目之間的垂直間距。 LOF、LOF ... 的間距保持不變。如何避免這種不相容的情況呢?圖片應該能說明問題。預先非常感謝您!

在此輸入影像描述

編輯:我用 xelatex 編譯

微量元素:

\documentclass[
    10pt,
    oneside,
    listof=totoc,
    bibliography=totoc,
]{scrbook}

\usepackage{scrhack}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{etoc}

\onehalfspacing
\KOMAoptions{parskip=half}

\begin{document}
    \tableofcontents
    \listoffigures
    \listoftables
    \lstlistoflistings
    \chapter{A Chapter}
    \begin{figure}
        \centering\includegraphics[width=0.5\linewidth]{example-image}
        \caption{First figure}
    \end{figure}
    \begin{table}
        \caption{First table}
        \centering
        \begin{tabular}[width=0.5\linewidth]{ccc}
            Cell 1 & Cell 2 & Cell 3
        \end{tabular}
    \end{table}
    \begin{lstlisting}[caption={First listing}]
        Some code
    \end{lstlisting}
\end{document}

答案1

tocbasic在(lof, lot, lol)控制的清單中,\parskip在關閉段落間距之前插入一個韻尾。可以透過以下方式停用此插入

\doforeachtocfile{\setuptoc{#1}{noparskipfake}}

但是清單標題和第一個條目之間的垂直空間比普通章節標題和普通文字之間的垂直空間要小。

因此,最好\parskip在段落間距關閉之前將這個結尾添加到受 控制的目錄 (toc) 中etoc。並\etocscrbookstyle沒有\parskip考慮到這一點。但是您可以修補\etocscrbookstyle以添加與此相關的程式碼\parskip(從 複製tocbasic):

\usepackage{xpatch}
\makeatletter
\xpatchcmd{\etocscrbookstyle}
  {\setlength {\parskip }{\z@ }}
  {%
    \etoc@Iftocfeature{\@currext}{noparskipfake}{}{%
      \ifvmode
        \@tempskipa\lastskip
        \vskip-\lastskip
        \addtolength{\@tempskipa}{\parskip}%
        \vskip\@tempskipa
      \fi
    }%
    \setlength {\parskip }{\z@ }%
  }{}{\PatchFailed}
\makeatother

\etocstandarddisplaystyle

例子:

\documentclass[
  10pt,
  oneside,
  listof=totoc,
  bibliography=totoc,
]{scrbook}

\usepackage{scrhack}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{etoc}

\onehalfspacing
\KOMAoptions{parskip=half}

\usepackage{xpatch}
\makeatletter
\xpatchcmd{\etocscrbookstyle}
  {\setlength {\parskip }{\z@ }}
  {%
    \etoc@Iftocfeature{\@currext}{noparskipfake}{}{%
      \ifvmode
        \@tempskipa\lastskip
        \vskip-\lastskip
        \addtolength{\@tempskipa}{\parskip}%
        \vskip\@tempskipa
      \fi
    }%
    \setlength {\parskip }{\z@ }%
  }{}{\PatchFailed}
\makeatother

\etocstandarddisplaystyle

\begin{document}
\tableofcontents
\listoffigures
\listoftables
\lstlistoflistings
\chapter{A Chapter}
Some text
\begin{figure}
  \centering\includegraphics[width=0.5\linewidth]{example-image}
  \caption{First figure}
\end{figure}
\begin{table}
  \caption{First table}
  \centering
  \begin{tabular}[width=0.5\linewidth]{ccc}
    Cell 1 & Cell 2 & Cell 3
  \end{tabular}
\end{table}
\begin{lstlisting}[caption={First listing}]
  Some code
\end{lstlisting}
\end{document}

在此輸入影像描述

相關內容