自定义目录

自定义目录

我认为 Sakurai 的《现代量子力学》目录非常漂亮。我该如何在 中创建它LaTeX

Sakurai 的目录

我尝试过使用etoctocloft但是我对这个东西还不熟悉,所以无法取得任何真正的进展。

答案1

特殊设置需要特殊手段 ;-)

等等spacings可以通过功能来完成tocloft,但是,这会改变\tableofcontents命令太多。

章节标题行中的章节页码需要对\@sect命令进行一些更改。

\documentclass{book}

\makeatletter
\let\latextableofcontents\tableofcontents % Save the original version
\makeatother


\usepackage{amssymb}
\usepackage{tocloft}


\newlength{\commonindentshift}

\setlength{\commonindentshift}{15pt}

\renewcommand{\cftchapaftersnum}{\hfill$\blacksquare$\hfill}
\addtolength{\cftchapnumwidth}{\commonindentshift} % increase the space
\renewcommand{\cftchapdotsep}{\cftnodots}
\renewcommand{\cftsecdotsep}{\cftnodots}
\renewcommand{\cftsubsecdotsep}{\cftnodots}
\renewcommand{\cftsubsubsecdotsep}{\cftnodots}
\renewcommand{\cftchappagefont}{\Large\bfseries}
\addtolength{\cftsecindent}{\commonindentshift}
\addtolength{\cftsubsecindent}{\commonindentshift}
\addtolength{\cftsubsubsecindent}{\commonindentshift}


\renewcommand{\cftchapfont}{\Large\bfseries}

\newcommand{\starredchapter}[1]{%
  \chapter*{#1}%
  \addtocontents{toc}{\protect\contentsline{chapter}{\hskip\cftchapnumwidth #1}{\thepage}}
}  

\usepackage{xpatch}


\makeatletter
\AtBeginDocument{%
\xpatchcmd{\latextableofcontents}{%
  \chapter*{\contentsname
    \@mkboth{%
      \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
}{%
  \chapter*{%
    \centering \contentsname
    \@mkboth{%
      \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
}{\typeout{Patched!!!}}{\typeout{Patch failure}}
\let\tableofcontents\latextableofcontents

}


\def\@sect#1#2#3#4#5#6[#7]#8{%
  \ifnum #2>\c@secnumdepth
    \let\@svsec\@empty
  \else
    \refstepcounter{#1}%
    \protected@edef\@svsec{\@seccntformat{#1}\relax}%
  \fi
  \@tempskipa #5\relax
  \ifdim \@tempskipa>\z@
    \begingroup
      #6{%
        \@hangfrom{\hskip #3\relax\@svsec}%
          \interlinepenalty \@M #8\@@par}%
    \endgroup
    \csname #1mark\endcsname{#7}%
    \addtocontents{toc}{\protect\contentsline{#1}{%
      \ifnum #2>\c@secnumdepth \else
        \protect\numberline{\csname the#1\endcsname}%
      \fi
      #7 \textit{\thepage}}{}}%
  \else
    \def\@svsechd{%
      #6{\hskip #3\relax
      \@svsec #8}%
    \csname #1mark\endcsname{#7}%
    \addtocontents{toc}{\protect\contentsline{#1}{%
        \ifnum #2>\c@secnumdepth \else
        \protect\numberline{\csname the#1\endcsname}%
        \fi
        #7 \textit{\thepage}}{}}}%
    \fi
  \@xsect{#5}
}
\makeatother


\begin{document}

\makeatletter
\makeatother
\tableofcontents


\starredchapter{Preface}
\starredchapter{In memoriam}


\chapter{First}
\section{First of first chapter}
\section{Second of first chapter}
\subsection{First sub section of 2nd section}
\chapter{Second}

\end{document}

在此处输入图片描述

相关内容