3

When using titlesec with the option explicit the toc title "Contents" is formatted using settings from the (where the explicit #1 parameter must be used). I think the MWE shows it all.

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8

\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{titletoc}

\titleformat{name=\chapter}
[block] 
{\Large}
{\thechapter}
{10pt}
{some fancy formatting using tikz #1}
[]

\titlecontents{chapter}
[20mm]
{\normalsize}
{\contentslabel{20mm}}
{}
{\titlerule*[1pc]{.}\contentsmargin{7.5mm}\filright \contentspage}
[]

\begin{document}
\tableofcontents
\chapter{chapX}
\chapter{chapY}

\end{document}

How can this be prevented?

Andrew Swann
  • 95,762
  • Yes, of course: \tableofcontents issues \chapter*{\contentsname}. Maybe you want an alternate \titleformat{name=\chapter,numberless}... for unnumbered chapters. I see no messing up, in other words, but only the expected behavior. – egreg Feb 10 '15 at 12:04

1 Answers1

7

This has nothing to do with using the explicit option. You have to add a \titleformat for unnumbered chapters, e.g.

\titleformat{name=\chapter,numberless}[display]
{}
{}
{0pt}
{\normalfont\Huge\bfseries #1}

MWE

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8

\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{titletoc}

\titleformat{name=\chapter}
[block]
{\Large}
{\thechapter}
{10pt}
{some fancy formatting using tikz #1}
[]   

\titleformat{name=\chapter,numberless}[display]
{}
{}
{0pt}
{\normalfont\Huge\bfseries #1}

\titlecontents{chapter}
[20mm]
{\normalsize}
{\contentslabel{20mm}}
{}
{\titlerule*[1pc]{.}\contentsmargin{7.5mm}\filright \contentspage}
[]

\begin{document}
\tableofcontents
\chapter{chapX}
\chapter{chapY}

\end{document} 

Output

enter image description here

karlkoeller
  • 124,410
  • In general, I discourage using the explicit option; it's better to define a one parameter macro, say \fancysettingwithtikz and using it in the last mandatory argument to \titleformat. The argument will automatically be supplied. – egreg Feb 10 '15 at 12:19
  • thanks. Adding this extra piece of code solved the issue. It is my misunderstanding of titlesec functionality. I was under the impression all my chapters/sections have a number, and did not see any relation of the titlesec chapter formatting configurations vs. the actual toc formatting (which you could do with titletoc or leave it up to latex). – user2263306 Feb 10 '15 at 13:12
  • @user2263306 You're welcome. Anyway, try to avoid using the explicit option when no strictly needed, as egreg warns in his comment. :-) – karlkoeller Feb 10 '15 at 13:15