在 tocbasic 中创建新的条目样式

在 tocbasic 中创建新的条目样式

我想使用 自定义目录和图表列表tocbasic。我最初使用 进行这些自定义tocloft。我设法完成了几乎所有工作。然而,还有 2 个问题:

  1. 创建独立样式,而不是使用选项tocline
  2. 似乎dynnumwidthnumsep选项没有任何效果

我想为每一章、部分、小节、小小节、图表和表格创建独立样式。我知道有,\CloneTOCEntryStyle{tocline}{chapter}但我认为无法使用选项集克隆它。

下面是完整的 MWE。

\documentclass[fontsize=11pt]{scrreprt}

\usepackage[left=25mm,right=25mm,top=8.4mm,bottom=10.7mm%
    ,includeheadfoot,headsep=15.4mm,marginparwidth=18mm,marginparsep=4mm]%
    {geometry}

\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}

\usepackage{blindtext}

\makeatletter
\newcommand*{\skillmon@chapter@dotfill}{%
    \def\@dotsep{0.072}\TOCLineLeaderFill[\textbf{.}]%
}
\newcommand*{\skillmon@section@dotfill}{%
    \def\@dotsep{0.072}\TOCLineLeaderFill%
}
\DeclareTOCStyleEntry[%
    ,beforeskip=1.15em plus 1pt%
    ,dynnumwidth=true% commenting out this doesn't change anything
    ,numsep=5pt% changing this to e.g. -5pt doesn't change anything
    ,linefill=\skillmon@chapter@dotfill%
    ,entryformat=\textbf%
    ,indent=0pt%
    ,level=0%
    ,pagenumberbox=\relax%
]{tocline}{chapter}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numsep=5pt%
    ,linefill=\skillmon@section@dotfill%
    ,indent=1.3em%
    ,pagenumberbox=\relax%
]{tocline}{section}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numsep=5pt%
    ,linefill=\skillmon@section@dotfill%
    ,indent=3.38em%
    ,pagenumberbox=\relax%
]{tocline}{subsection}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numsep=5pt%
    ,linefill=\skillmon@section@dotfill%
    ,indent=6.38em%
    ,pagenumberbox=\relax%
]{tocline}{subsubsection}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numsep=5pt%
    ,linefill=\skillmon@section@dotfill%
    ,indent=1.5em%
    ,pagenumberbox=\relax%
]{tocline}{table}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numsep=5pt%
    ,linefill=\skillmon@section@dotfill%
    ,indent=1.5em%
    ,pagenumberbox=\relax%
]{tocline}{figure}
\makeatother

\begin{document}
\tableofcontents
\listoftables
\listoffigures
\blinddocument
\addxcontentsline{lot}{table}[1.1]{example of table}
\addxcontentsline{lot}{table}[1.2]{example of table}
\addxcontentsline{lof}{figure}[1.1]{example of figure}
\addxcontentsline{lof}{figure}[1.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[2.1]{example of table}
\addxcontentsline{lot}{table}[2.2]{example of table}
\addxcontentsline{lof}{figure}[2.1]{example of figure}
\addxcontentsline{lof}{figure}[2.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[3.1]{example of table}
\addxcontentsline{lot}{table}[3.2]{example of table}
\addxcontentsline{lof}{figure}[3.1]{example of figure}
\addxcontentsline{lof}{figure}[3.2]{example of figure}
\end{document}

答案1

dynnumwidth=true的值numwidth不会被完全忽略(与文档不同)。相反,它作为包括在内的条目数字的最小宽度。numsep这意味着条目数字使用的宽度至少为numwidth,但如果有数字需要比更宽的空间,它将被调整。因此,只有当所需空间比更宽时,和/或的变化的numwidth效果才可见。我认为必须更改的文档(或者这是的 bug )。dynumwidth=truenumsepnumwidthtocdynnumwidthtocbasic

如果为每个 TOC 样式条目添加numwidth=0pt设置,那么即使只有短条目编号dynnumwidth也会产生效果。numsep

\documentclass[fontsize=11pt]{scrreprt}
%\documentclass[11pt]{report}
%\usepackage{tocbasic}% with a KOMA-Script class do not load explicitly

\usepackage[left=25mm,right=25mm,top=8.4mm,bottom=10.7mm%
    ,includeheadfoot,headsep=15.4mm,marginparwidth=18mm,marginparsep=4mm]%
    {geometry}
\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}
\usepackage{blindtext}

\makeatletter
\def\@dotsep{0.072}
\newcommand*{\skillmon@chapter@dotfill}{%
    \TOCLineLeaderFill[\textbf{.}]%
}
\newcommand*{\skillmon@section@dotfill}{%
    \TOCLineLeaderFill%
}
\newcommand*\skillmon@pagenumberbox[1]{\makebox{#1}}
\newcommand*\skillmon@numsep{0pt}% <- adjust this to set the minimum space between the numbers and the titles

\DeclareTOCStyleEntry[%
    ,beforeskip=1.15em plus 1pt%
    ,dynnumwidth=true%
    ,numwidth=0pt,% <- added
    ,numsep=\skillmon@numsep%
    ,linefill=\skillmon@chapter@dotfill%
    ,entryformat=\textbf%
    ,indent=0pt%
    ,level=0%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{chapter}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numwidth=0pt,% <- added
    ,numsep=\skillmon@numsep%
    ,linefill=\skillmon@section@dotfill%
    ,indent=1.3em%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{section}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numwidth=0pt,% <- added
    ,numsep=\skillmon@numsep%
    ,linefill=\skillmon@section@dotfill%
    ,indent=3.38em%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{subsection}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numwidth=0pt,% <- added
    ,numsep=\skillmon@numsep%
    ,linefill=\skillmon@section@dotfill%
    ,indent=6.38em%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{subsubsection}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numwidth=0pt,% <- added
    ,numsep=\skillmon@numsep%
    ,linefill=\skillmon@section@dotfill%
    ,indent=1.5em%
    ,pagenumberbox=\relax%
]{tocline}{table}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numwidth=0pt,% <- added
    ,numsep=\skillmon@numsep%
    ,linefill=\skillmon@section@dotfill%
    ,indent=1.5em%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{figure}
\makeatother

\begin{document}
\tableofcontents
\listoftables
\listoffigures
\blinddocument
\addxcontentsline{lot}{table}[1.1]{example of table}
\addxcontentsline{lot}{table}[1.2]{example of table}
\addxcontentsline{lof}{figure}[1.1]{example of figure}
\addxcontentsline{lof}{figure}[1.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[2.1]{example of table}
\addxcontentsline{lot}{table}[2.2]{example of table}
\addxcontentsline{lof}{figure}[2.1]{example of figure}
\addxcontentsline{lof}{figure}[2.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[3.1]{example of table}
\addxcontentsline{lot}{table}[3.2]{example of table}
\addxcontentsline{lof}{figure}[3.1]{example of figure}
\addxcontentsline{lof}{figure}[3.2]{example of figure}
\end{document}

现在, 的值\skillmon@numsep设置了 ToC 中数字和标题之间的最小间距。在示例中,它设置为0pt

运行三次即可获得

在此处输入图片描述

scrreprt请注意,如果您用标准类替换,此示例也将起作用report。但您必须scrtocbasic明确加载包。


您正在使用 KOMA-Script 类scrreprt。因此,也可以在可选参数等中设置目录条目的选项\RedeclareSectionCommand。但请注意,您必须为每个选项\RedeclareSectionCommands添加前缀。toc

例子:

\documentclass[fontsize=11pt,
%listof=nochaptergap% remove the chapter gap in lists like LOT or LOF
]{scrreprt}[2017/01/03]

\usepackage[left=25mm,right=25mm,top=8.4mm,bottom=10.7mm%
    ,includeheadfoot,headsep=15.4mm,marginparwidth=18mm,marginparsep=4mm]%
    {geometry}

\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}

\usepackage{blindtext}

\makeatletter
\def\@dotsep{0.072}
\newcommand*\skillmon@pagenumberbox[1]{\makebox{#1}}
\newcommand*\skillmon@numsep{0pt}

\RedeclareSectionCommands[%
    ,tocnumwidth=0pt%
    ,tocdynnumwidth=true%
    ,tocnumsep=\skillmon@numsep%
    ,tocpagenumberbox=\skillmon@pagenumberbox%
]{chapter,section,subsection,subsubsection}

\RedeclareSectionCommand[%
    ,beforeskip=1.15em plus 1pt%
    ,tocentryformat=\textbf%
    ,toclinefill={\TOCLineLeaderFill[\textbf{.}]}%
]{chapter}
\RedeclareSectionCommand[%
  ,tocindent=3.38em%
]{subsection}
\RedeclareSectionCommand[%
  ,tocindent=6.38em%
]{subsubsection}


\DeclareTOCStyleEntry[%
    ,dynnumwidth=true%
    ,numwidth=0pt%
    ,numsep=\skillmon@numsep%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{table}
\DeclareTOCStyleEntry[%
    ,dynnumwidth=true%
    ,numwidth=0pt%
    ,numsep=\skillmon@numsep%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{figure}
\makeatother

\begin{document}
\tableofcontents
\listoftables
\listoffigures
\blinddocument
\addxcontentsline{lot}{table}[1.1]{example of table}
\addxcontentsline{lot}{table}[1.2]{example of table}
\addxcontentsline{lof}{figure}[1.1]{example of figure}
\addxcontentsline{lof}{figure}[1.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[2.1]{example of table}
\addxcontentsline{lot}{table}[2.2]{example of table}
\addxcontentsline{lof}{figure}[2.1]{example of figure}
\addxcontentsline{lof}{figure}[2.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[3.1]{example of table}
\addxcontentsline{lot}{table}[3.2]{example of table}
\addxcontentsline{lof}{figure}[3.1]{example of figure}
\addxcontentsline{lof}{figure}[3.2]{example of figure}
\end{document}

我删除了值为默认值的选项。运行三次,得到与上述相同的结果。


因为\CloneTOCEntryStyle问题中提到:

scrreprt使用\CloneTOCEntryStyle克隆tocline到样式chaptersection\TOCEntryStyleStartInitCode声明新样式的一些选项的初始设置。然后section将 style 克隆到 style default

因此,你也可以做类似的事情(警告:下面的例子使用未记录的内部命令,所以它可能会在未来发生故障)

\documentclass[fontsize=11pt,
%listof=nochaptergap% remove the chapter gap in lists like LOT or LOF
]{scrreprt}[2017/01/03]

\usepackage[left=25mm,right=25mm,top=8.4mm,bottom=10.7mm%
    ,includeheadfoot,headsep=15.4mm,marginparwidth=18mm,marginparsep=4mm]%
    {geometry}

\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}

\usepackage{blindtext}

\makeatletter
\def\@dotsep{0.072}

\TOCEntryStyleInitCode{default}{%
    \expandafter\renewcommand%
        \csname scr@tso@#1@numwidth\endcsname{0pt}%
    \expandafter\renewcommand%
        \csname scr@tso@#1@numsep\endcsname{0pt}%
  \expandafter\renewcommand%
      \csname scr@tso@#1@pagenumberbox\endcsname[1]{\makebox{##1}}%
}
\makeatother

\RedeclareSectionCommands[tocstyle=default,tocdynnumwidth=true]{chapter,section,subsection,subsubsection}
\DeclareTOCStyleEntry[dynnumwidth=true]{default}{table}
\DeclareTOCStyleEntry[dynnumwidth=true]{default}{figure}

\RedeclareSectionCommand[%
    ,beforeskip=1.15em plus 1pt%
    ,tocentryformat=\textbf%
    ,toclinefill={\TOCLineLeaderFill[\textbf{.}]}%
]{chapter}
\RedeclareSectionCommand[%
  ,tocindent=6.38em%
]{subsection}

\begin{document}
\tableofcontents
\listoftables
\listoffigures
\blinddocument
\addxcontentsline{lot}{table}[1.1]{example of table}
\addxcontentsline{lot}{table}[1.2]{example of table}
\addxcontentsline{lof}{figure}[1.1]{example of figure}
\addxcontentsline{lof}{figure}[1.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[2.1]{example of table}
\addxcontentsline{lot}{table}[2.2]{example of table}
\addxcontentsline{lof}{figure}[2.1]{example of figure}
\addxcontentsline{lof}{figure}[2.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[3.1]{example of table}
\addxcontentsline{lot}{table}[3.2]{example of table}
\addxcontentsline{lof}{figure}[3.1]{example of figure}
\addxcontentsline{lof}{figure}[3.2]{example of figure}
\end{document}

相关内容