完全自定义目录编号

完全自定义目录编号

我必须构建一个具有不同节级(以及目录)的文档结构,该结构具有特定的自定义“编号”,而不是默认的数学编号。例如,在列表环境中,节的开头应始终像罗马数字一样(使用“\Alph*.”执行的操作),子节的开头始终为“(\arabic*)”,段落的开头为“\alph*\alph*)”,等等。

我已经为此搜索了很多次,但要么在我之前没人需要这个,要么我错过了要搜索的正确标签。

有什么方法可以做到吗?

目录看起来应该是这样的:

A. Section
 I. Subsection
 II. Subsection
  1) Subsubsection
   a) Paragraph
  2) Subsubsection
   a) Paragraph
    aa) Subparagraph
B. Section
 I. Subsection
  1) Subsubsection

答案1

为了在整个文档中获得这种行为,我们使用以下titlesec包:

\usepackage{titlesec}

\renewcommand{\thesection}{\Alph{section}}
\titleformat{\section}{\normalfont\Large\bfseries}{\thesection.}{1em}{}
\renewcommand{\thesubsection}{\Roman{subsection}}
\titleformat{\subsection}{\normalfont\large\bfseries}{\thesubsection.}{1em}{}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}
\titleformat{\subsubsection}{\normalfont\normalsize\bfseries}{\thesubsubsection)}{1em}{}
\renewcommand{\theparagraph}{\alph{paragraph}}
\titleformat{\paragraph}[runin]{\normalfont\normalsize\bfseries}{\theparagraph)}{1em}{}
\renewcommand{\thesubparagraph}{\alph{subparagraph}\alph{subparagraph}}
\titleformat{\subparagraph}[runin]{\normalfont\normalsize\bfseries}{\thesubparagraph)}{1em}{}

对于目录,我们使用tocloft包进行定制:

\usepackage{tocloft}

\renewcommand{\cftsecaftersnum}{.}
\renewcommand{\cftsubsecaftersnum}{.}
\renewcommand{\cftsubsubsecaftersnum}{)}
\renewcommand{\cftparaaftersnum}{)}
\renewcommand{\cftsubparaaftersnum}{)}

\setlength{\cftsecnumwidth}{1.8em}
\setlength{\cftsubsecnumwidth}{2.3em}
\setlength{\cftsubsubsecnumwidth}{1.8em}
\setlength{\cftparanumwidth}{1.8em}
\setlength{\cftsubparanumwidth}{2.2em}

\setlength{\cftsecindent}{0em}
\setlength{\cftsubsecindent}{1.8em}
\setlength{\cftsubsubsecindent}{4.1em}
\setlength{\cftparaindent}{5.9em}
\setlength{\cftsubparaindent}{7.7em}

因此,这个 MWE

\documentclass{article}

\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}

\usepackage{titlesec}

\renewcommand{\thesection}{\Alph{section}}
\titleformat{\section}{\normalfont\Large\bfseries}{\thesection.}{1em}{}
\renewcommand{\thesubsection}{\Roman{subsection}}
\titleformat{\subsection}{\normalfont\large\bfseries}{\thesubsection.}{1em}{}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}
\titleformat{\subsubsection}{\normalfont\normalsize\bfseries}{\thesubsubsection)}{1em}{}
\renewcommand{\theparagraph}{\alph{paragraph}}
\titleformat{\paragraph}[runin]{\normalfont\normalsize\bfseries}{\theparagraph)}{1em}{}
\renewcommand{\thesubparagraph}{\alph{subparagraph}\alph{subparagraph}}
\titleformat{\subparagraph}[runin]{\normalfont\normalsize\bfseries}{\thesubparagraph)}{1em}{}

\usepackage{tocloft}

\renewcommand{\cftsecaftersnum}{.}
\renewcommand{\cftsubsecaftersnum}{.}
\renewcommand{\cftsubsubsecaftersnum}{)}
\renewcommand{\cftparaaftersnum}{)}
\renewcommand{\cftsubparaaftersnum}{)}

\setlength{\cftsecnumwidth}{1.8em}
\setlength{\cftsubsecnumwidth}{2.3em}
\setlength{\cftsubsubsecnumwidth}{1.8em}
\setlength{\cftparanumwidth}{1.8em}
\setlength{\cftsubparanumwidth}{2.2em}

\setlength{\cftsecindent}{0em}
\setlength{\cftsubsecindent}{1.8em}
\setlength{\cftsubsubsecindent}{4.1em}
\setlength{\cftparaindent}{5.9em}
\setlength{\cftsubparaindent}{7.7em}

\begin{document}

\tableofcontents

\bigskip\bigskip

\section{A section}

\subsection{A subsection}

\subsection{A subsection}

\subsubsection{A subsubsection}

\paragraph{A paragraph}

\subsubsection{A subsubsection}

\paragraph{A paragraph}

\subparagraph{A subparagraph}

\section{A section}

\subsection{A subsection}

\subsubsection{A subsubsection}

\end{document} 

得出这个结果

在此处输入图片描述

相关内容