
He leído sobre esto: Bonita tabla de contenidos
¿Alguien puede decirme cómo hacer ese círculo para mi \part? Intenté copiar algo de código pero obviamente no funcionó.
\documentclass[twoside]{book}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{geometry}
\usepackage{fancyhdr,calc,blindtext}
\usepackage{xwatermark,wallpaper,grffile}
\usepackage{bm,graphicx,empheq,etoolbox}
\usepackage{units,cancel,mathtools,lipsum,lmodern}
\usepackage{varwidth,verbatim,setspace,lmodern}
\usepackage{anyfontsize,rotating,framed,titletoc}
\usepackage{amsmath,tocloft, amssymb,fancyhdr,color,contour}
\usepackage{booktabs,caption,multirow,marginnote}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage[listings]{tcolorbox}
\tcbuselibrary{listings,theorems,skins,breakable
,theorems,many,raster}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=black, anchorcolor=black, citecolor=black, urlcolor=black,pdfstartpage=5}
\usepackage{listings, float, wasysym}
\floatstyle{boxed}
\setlength\parindent{0pt}
\DeclareMathAlphabet{\mathpzc}{OT1}{pzc}{m}{it}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{fadings,decorations.text}
\setcounter{tocdepth}{3}
\addtocontents{toc}{\cftpagenumbersoff{chapter}}
\setlength{\cftsubsecindent}{\cftsecnumwidth}
\patchcmd{\tableofcontents}{\contentsname}{\sffamily\contentsname}{}{}
\setlength{\cftbeforechapskip}{6ex}
\setlength{\cftbeforesecskip}{0ex}
%---this doesn't work!--------------
\newcommand\mycircle[1]{
\begin{tikzpicture}%
\node[draw=yellow,circle, text width=18pt,line width=1pt,align=center] {#1};
\end{tikzpicture}}
\makeatletter
\patchcmd{\@part}
{\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}}
{\addtocontents{toc}{\protect\addvspace{20pt}}
\addcontentsline{toc}{part}{\huge{\protect\color{yellow}%
\setlength\fboxrule{2pt}\protect\mycircle{%
\hfil\thepart\hfil%
}%
}\\[2ex]\color{red}\sffamily#1}}{}{}
%----------------------------
\begin{document}
\tableofcontents
\part{First Part}
\chapter{My first}
\section{section 1}
\subsection{stuff1}
\subsubsection{substuff1}
\subsection{stuff2}
\subsection{stuff3}
\chapter{My second}
\section{section 2}
-----------
\part{Second Part}
\chapter{My third}
\section{section 3}
\end{document}
Respuesta1
hyperref
redefine \@part
, etc. considerablemente, por lo que \patchcmd{...}
después de su uso hyperref
es demasiado tarde. Los parches deben realizarse antes de hyperref
cargarlos.
Escribir algo frágil como tikzpicture
un comando en el archivo .aux
and .toc
es difícil, ¡entonces es mejor fortalecer el \mycircle
comando!
\documentclass[twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{calc}
\usepackage{blindtext}
\usepackage{xwatermark}
\usepackage{wallpaper}
\usepackage{grffile}
\usepackage[explicit]{titlesec}
\usepackage{bm,graphicx,empheq}
\usepackage{units,cancel,mathtools,lipsum,lmodern}
\usepackage{varwidth,verbatim,setspace,lmodern}
\usepackage{anyfontsize,rotating,framed,titletoc}
\usepackage{amsmath,amssymb,contour}
\usepackage{booktabs,caption,multirow,marginnote}
\usepackage{tocloft}
\usepackage{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{etoolbox}
\usepackage{xpatch}
\usepackage{listings}
\usepackage{wasysym}
\usepackage{float}
\makeatletter
\newcommand\mycircle[1]{%
\begin{tikzpicture}%
\node[draw=blue,circle, text width=18pt,line width=1pt,align=center] {#1};
\end{tikzpicture}
}
\robustify{\mycircle}
\xpatchcmd{\@part}{%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
}{%
\addcontentsline{toc}{part}{\huge\texorpdfstring{\hfil\protect\color{blue}%
\mycircle{%
\thepart}\hfil%%
\\[2ex]\color{red}\sffamily#1}{#1}}%
}{\typeout{Success}}{\typeout{Failed}}
%----------------------------
\makeatother
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=black, anchorcolor=black, citecolor=black, urlcolor=black,pdfstartpage=5}
%\floatstyle{boxed}
\setlength\parindent{0em}
%\DeclareMathAlphabet{\mathpzc}{OT1}{pzc}{m}{it}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{fadings,decorations.text}
\setcounter{tocdepth}{3}
\addtocontents{toc}{\cftpagenumbersoff{chapter}}
\setlength{\cftsubsecindent}{\cftsecnumwidth}
\patchcmd{\tableofcontents}{\contentsname}{\sffamily\contentsname}{}{}
\setlength{\cftbeforechapskip}{6ex}
\setlength{\cftbeforesecskip}{0ex}
%---this doesn't work!--------------
\begin{document}
\tableofcontents
\part{First Part}
\chapter{My first}
\section{section 1}
\subsection{stuff1}
\subsubsection{substuff1}
\subsection{stuff2}
\subsection{stuff3}
\chapter{My second}
\section{section 2}
-----------
\part{Second Part}
\chapter{My third}
\section{section 3}
\end{document}