3

Is there a way to display part names, but not numbers in ToC with titletoc?

simply removing \thecontentslabel seems easy enough for chapter, section etc, but not part.

Background: I used the starred variant (\part*{foo}) but as I also would like some parts to have a line break in the document and be on the same line in ToC and page header, I would need the optional argument, which doesn't work with the starred variant (see this question for the reasons).

\documentclass[12pt,a4paper,oneside]{scrbook}

\usepackage{titlesec}
\titleformat{\part}[display]{}{}{1em}{\sffamily\huge}

\usepackage{titletoc}
\titlecontents{part}[0em]
    {\vspace{2em}\large\bfseries\sffamily}
    {}{}{}

\begin{document}

\tableofcontents

\part{Introduction}
    Bla

\part[Example 1: Foo]{Example 1:\\Foo}
    Bla

\part[Example 2: Bar]{Example 2:\\Bar}
    Bla

\part{Appendix}
    Bla

\end{document}
10
  • 1
    Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Nov 7, 2014 at 17:10
  • in creating the example I realised the problem arises only if I use both titlesec and titletoc, when I remove titlesec, there are no leading numbers for part in the toc.
    – jshlke
    Nov 7, 2014 at 17:22
  • Seul: KOMA script (scrbook) and titlesec do not really match together! You should drop one of them
    – user31729
    Nov 7, 2014 at 17:24
  • oops. would you have a suggestions which one best to drop? and replace with what? I am in the final stages of my PhD, so I am a bit reluctant to change major variables here...
    – jshlke
    Nov 7, 2014 at 17:27
  • another question: KOMA and titletoc are fine?
    – jshlke
    Nov 7, 2014 at 17:30

2 Answers 2

2

You don't have to use the starred version if you want no part label to appear in the toc. With the newlinetospace option, it is needless to use the optional argument to remove a line break in titles: it is automatically converted to a horizontal space in table of contents and headers.

\documentclass[12pt,a4paper,oneside]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\usepackage[newlinetospace, newparttoc]{titlesec}

\titleformat{\part}[display]{}{}{1em}{\sffamily\huge}

\usepackage{titletoc}
\titlecontents{part}[0em]
    {\vspace{2em}\large\bfseries\sffamily\relax}
    {\contentslabel[\relax]{0em}}{}{\hfill\contentspage}

\begin{document}

\tableofcontents

\part{Introduction}
    Bla

\part{Example 1:\\Foo}%
    Bla

\part{Example 2:\\Bar}%[
    Bla

\part{Appendix}
    Bla

\end{document} 

enter image description here

9
  • Thanks, that works really well and feels less of a hack. Do I understand correctly that newparttoc-option is responsible for removing the part-number in the ToC? In the titlesec-documentation it says the options is changing its use from a »non standard way« and I do not quite get what that means (p8).
    – jshlke
    Nov 8, 2014 at 11:16
  • I don't really understand either. I think (not sure) some changes made to part formatting are unefficient without this option. I know I should experiment to understand what's behind all this, but never had time to do it…
    – Bernard
    Nov 8, 2014 at 11:20
  • but it is the option responsible for suppressing the leading numbers, right?
    – jshlke
    Nov 8, 2014 at 11:21
  • also, I feel that your answer would add valuable information to the first question I asked regarding this problem: tex.stackexchange.com/questions/210976/… not sure how the proper way would be: should I ask you to paste it there again? should I do it? should I comment there with a link to this answer here?
    – jshlke
    Nov 8, 2014 at 11:24
  • @Seul: The pure KOMA solution is no hack ;-)
    – user31729
    Nov 8, 2014 at 11:38
2
\documentclass[12pt,a4paper,oneside]{scrbook}

%\usepackage{titlesec}
%\titleformat{\part}[display]{}{}{1em}{\sffamily\huge}

%\usepackage{titletoc}
%\titlecontents{part}[0em]
%    {\vspace{2em}\large\bfseries\sffamily}
%    {}{}{}

\begin{document}

\tableofcontents

\part{Introduction}
    Bla

\addpart[Example 1: Foo]{Example 1:\\Foo}
    Bla

\addpart[Example 2: Bar]{Example 2:\\Bar}
    Bla

\part{Appendix}
    Bla

\end{document}

enter image description here

You must log in to answer this question.

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