3

Is there a way to influence typesetting of \part{} within the document, but without at the same time affecting it in ToC and the page headings? I have several different parts – in my minimal example "Introduction", "Appendix" – and several related ones – in my minimal example "Example 1, 2". Since I want the prefix "Example n" in some but not all part headings simply redefining part is not an option.

In the related parts I want a line break after the bit that stays the same (Example n) only in the heading, in ToC and head I want it on the same line:

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

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

\usepackage{fancyhdr}
    \pagestyle{fancy}
    \fancyhead[L]{\textit{\textrm{\footnotesize{\rightmark}}}}    

\renewcommand{\partmark}[1]{\markboth{#1}{}}

\begin{document}

\tableofcontents

\part{Introduction}
    Bla \newpage Bla Bla 

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

\part{Example 2:\\Bar}
    Bla \newpage Bla Bla 

\part{Appendix}
    Bla \newpage Bla Bla 

\end{document}

E D I T (after @RicoRally's very good answer came in): Another option for solving this problem is using titlesec with two options, one solving the newline-issue, the other the numbering: \usepackage[newlinetospace, newparttoc]{titlesec}. This solution was provided by @Bernard at this follow up question: https://tex.stackexchange.com/questions/211026#answer-211046

1 Answer 1

3

You can force parts not to be displayed in the table of contents. This can be done suppressing the command \l@part.

You could add this in your preamble:

\makeatletter
\renewcommand*\l@part[2]{}
\makeatother

This is quite a rough way to deal with LaTeX, but it works. Your document could be:

\documentclass{scrbook}

\makeatletter
\renewcommand*\l@part[2]{}
\makeatother

\begin{document}

\tableofcontents

\part{Introduction}
    \chapter{Bla} \newpage Bla Bla 

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

\part{Example 2:\\Bar}
    \chapter{Bla} \newpage Bla Bla 

\part{Appendix}
    Bla \newpage Bla Bla 

\end{document}

In this way only other objects are displayed in the contents.

EDIT

Thanks to Seul I finally understood the question properly.

For that it's enough to use the optional argument of \part. It's used when we want to specify a different title in the head and in the table of contents (they will be the same).

In your case my previous code will become:

\documentclass{scrbook}

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

\usepackage{fancyhdr}
    \pagestyle{fancy}
    \fancyhead[L]{\textit{\textrm{\footnotesize{\rightmark}}}}    

\renewcommand{\partmark}[1]{\markboth{#1}{}}

\begin{document}

\tableofcontents

\part{Introduction}
    Bla \newpage Bla Bla 

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

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

\part{Appendix}
    Bla \newpage Bla Bla 

\end{document}
5
  • With hyperref this might not work, but it's not difficult to find a similar workaround in that case.
    – egreg
    Nov 7, 2014 at 13:01
  • Thanks RicoRally for taking the time to answer. However, I'm not sure whether it gets clear enough from my question what I want to do: 1) have \part as a heading including optional line break 2) keep part in ToC on a single line 3) keep \part in document head on a single line.
    – jshlke
    Nov 7, 2014 at 13:36
  • @Seul thank you for being clear, I edited the answer already.
    – RicoRally
    Nov 7, 2014 at 14:13
  • 1
    Thanks a lot for coming back and solving it! The solution works perfectly on the example I posted, however... there's something I didn't tell you: in my real document I use the starred variant of part because I want to avoid the leading number in ToC ("Example 1: Foo" rather than "2 Example 1: Foo"), and for the life of me I could not get titletoc to drop that number for part. But that is a different question altogether. Thanks again!
    – jshlke
    Nov 7, 2014 at 16:52
  • Asked the new question here: tex.stackexchange.com/questions/211026/…
    – jshlke
    Nov 7, 2014 at 17:05

You must log in to answer this question.

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