\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}