9

I want to represent the \part in the TOC as on the figure below:

enter image description here

The problem is the \part could be represented so simple as other headers. As you see in the MWE below, the \part design has been created by same way as \section, but the color box in not displayed in the first case:

enter image description here

\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 Answer 1

16

Unfortunately, citing the titlesec manual

Standard parts write the toc entry number in a non standard way. You may change that with newparttoc so that titletoc or a similar package can manipulate the entry. (That works only if \part has been redefined.)

This means that you have to load the titlesec package with the option newparttoc

\usepackage[newparttoc]{titlesec}

and redefine \part in a way to reproduce the standard article class behavior:

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

After doing that, your tikzpicture magically appears...

enter image description here

MWE:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .