在 KOMA-script scrbook 类的目录中添加日期列

在 KOMA-script scrbook 类的目录中添加日期列

自接受以来Jasper Habicht 的工作答案我之前的问题,我已从标准book类切换到 KOMA 脚本scrbook。我仍然需要向我的 ToC 添加一个特定的列,以下 MWE 是一个book类解决方案,不幸的是,它在 KOMA 脚本环境中不再适用于我:

\documentclass{book}
\usepackage[utf8]{inputenc}

\newcommand{\toclineinsert}[3][25mm]{%
    \dotfill\ #2\makebox[#1][l]{#3\dotfill}%
}

\title{test}
\author{name}
\date{now}

\begin{document}

\tableofcontents

\addcontentsline{toc}{chapter}{first lecture title \toclineinsert{4 }{January}}

\addcontentsline{toc}{chapter}{second lecture title \toclineinsert{2nd half }{January}}

\addcontentsline{toc}{chapter}{third lecture title \toclineinsert{February/}{March}}

\addcontentsline{toc}{chapter}{a pretty long fourth lecture title \newline that goes over two lines \toclineinsert{29 or 30 }{March}}

\end{document}

目录

如何在scrbook课堂上实现相同(或类似)的效果?

答案1

添加

\DeclareTOCStyleEntry[
  linefill={},% default for chapter is linefill=\hfill
]{tocline}{chapter}

回到序言。

例子:

\documentclass{scrbook}

\DeclareTOCStyleEntry[
  linefill={},
]{tocline}{chapter}

\newcommand{\toclineinsert}[3][25mm]{%
    \dotfill
    \ #2\makebox[#1][l]{#3\dotfill}%
}

\begin{document}
\tableofcontents

\addxcontentsline{toc}{chapter}{first lecture title \toclineinsert{4 }{January}}
\addxcontentsline{toc}{chapter}{second lecture title \toclineinsert{2nd half }{January}}
\addxcontentsline{toc}{chapter}{third lecture title \toclineinsert{February/}{March}}
\addxcontentsline{toc}{chapter}{a pretty long fourth lecture title \newline that goes over two lines \toclineinsert{29 or 30 }{March}}
\end{document}

在此处输入图片描述


也许您想使用\addchap其可选参数。那么您可以设置类选项headings=optiontotocandhead来激活分段命令的可选参数的高级功能。

\documentclass[headings=optiontotocandhead]{scrbook}
\usepackage{lipsum}% only for dummy text

\DeclareTOCStyleEntry[
  linefill={},
]{tocline}{chapter}

\newcommand{\toclineinsert}[3][25mm]{%
    \dotfill
    \ #2\makebox[#1][l]{#3\dotfill}%
}

\begin{document}
\tableofcontents

\addchap
  [tocentry={first lecture title \toclineinsert{4 }{January}}]
  {first lecture title}
\lipsum[1-20]

\addchap
  [tocentry={second lecture title \toclineinsert{2nd half }{January}},head={different entry in page header}]
  {second lecture title}
\lipsum[1-20]

\addchap
  [tocentry={third lecture title \toclineinsert{February/}{March}}]
  {third lecture title}
\addchap
  [tocentry={a pretty long fourth lecture title \newline that goes over two lines \toclineinsert{29 or 30 }{March}}]
  {a pretty long fourth lecture title that goes over two lines}
\end{document}

相关内容