通过 titletoc 自定义目录中的部分内容

通过 titletoc 自定义目录中的部分内容

\part我想要在目录中表示如下图所示:

在此处输入图片描述

问题是\part不能像其他标题一样简单地表示。正如您在下面的 MWE 中看到的,设计\part是通过与 相同的方式创建的\section,但在第一种情况下没有显示颜色框:

在此处输入图片描述

\documentclass[a4paper,twoside]{article}

\usepackage{color}
\usepackage[svgnames,x11names,table]{xcolor}

\usepackage{tikz}
\usepackage{titletoc}

\setcounter{tocdepth}{3}
\contentsmargin{2.55em}

\titlecontents{part}[0pc]
{}
{\begin{tikzpicture}[baseline={([yshift=-.8ex]current bounding box.center)},]
\node [thick, draw=LavenderBlush4, fill=LavenderBlush1, rectangle, rounded corners] {\thecontentslabel};\end{tikzpicture}\quad}
{}
{}

\titlecontents{section}[0pc]
{}
{\begin{tikzpicture}[baseline={([yshift=-.8ex]current bounding box.center)},]
\node [thick, draw=LavenderBlush4, fill=LavenderBlush1, rectangle, rounded corners] {\thecontentslabel};\end{tikzpicture}\quad}
{}
{$\:$\titlerule[0.5pt]$\:$\small\thecontentspage}

\dottedcontents{subsection}[3.6em]{}{2.5em}{1pc}

\titlecontents*{subsubsection}[1.8pc]
{\small}{\thecontentslabel}
{}{\,---\,\thecontentspage}[\quad][]

\begin{document}

\tableofcontents

\part{A}
\section{AA}
\subsection{AAA}
\subsubsection{AAAA}
\subsubsection{AAAB}
\subsection{AAB}
\subsection{AAC}
\subsection{AAD}
\subsubsection{AADA}
\subsubsection{AADB}
\subsubsection{AADC}
\subsubsection{AADD}

\end{document} 

答案1

不幸的是,引用titlesec手册

标准部分以非标准方式写入目录条目编号。您可以使用以便更改它,newparttoc或者titletoc类似的包可以操纵条目。(这仅在\part已重新定义时才有效。)

这意味着你必须titlesec使用选项加载包newparttoc

\usepackage[newparttoc]{titlesec}

\part以重现标准类行为的方式重新定义article

\titleformat{\part}[display]
{\Large\bfseries}
{\partname\nobreakspace\thepart}
{0mm}
{\huge\bfseries}

这样做之后,你的tikzpicture魔法就会出现......

在此处输入图片描述

梅威瑟:

\documentclass[a4paper,twoside]{article}

\usepackage{color}
\usepackage[svgnames,x11names,table]{xcolor}

\usepackage{tikz}

\usepackage[newparttoc]{titlesec}

\titleformat{\part}[display]
{\Large\bfseries}
{\partname\nobreakspace\thepart}
{0mm}
{\huge\bfseries}

\usepackage{titletoc}

\setcounter{tocdepth}{3}
\contentsmargin{2.55em}

\titlecontents{part}[0pc]
{}
{\begin{tikzpicture}[baseline={([yshift=-.8ex]current bounding box.center)},]
\node [thick, draw=LavenderBlush4, fill=LavenderBlush1, rectangle, rounded corners] {\thecontentslabel};\end{tikzpicture}\quad}
{}
{}

\titlecontents{section}[0pc]
{}
{\begin{tikzpicture}[baseline={([yshift=-.8ex]current bounding box.center)},]
\node [thick, draw=LavenderBlush4, fill=LavenderBlush1, rectangle, rounded corners] {\thecontentslabel};\end{tikzpicture}\quad}
{}
{$\:$\titlerule[0.5pt]$\:$\small\thecontentspage}

\dottedcontents{subsection}[3.6em]{}{2.5em}{1pc}

\titlecontents*{subsubsection}[1.8pc]
{\small}{\thecontentslabel}
{}{\,---\,\thecontentspage}[\quad][]

\begin{document}

\tableofcontents

\part{A}
\section{AA}
\subsection{AAA}
\subsubsection{AAAA}
\subsubsection{AAAB}
\subsection{AAB}
\subsection{AAC}
\subsection{AAD}
\subsubsection{AADA}
\subsubsection{AADB}
\subsubsection{AADC}
\subsubsection{AADD}

\end{document} 

相关内容