6

Is there a way to completely hide the \part and \chapter headings when they are called (but still show them in the toc)? Maybe using titlesec?

Note:

I'm using something like this to capture the chapter headings and reuse them:

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

% Define \chaphead to be used in section headings
\let\oldchapter\chapter
\newcommand\temphead{}
\newcommand\chaphead{}
\renewcommand\chapter[2][\temphead]{%
    \renewcommand\temphead{#2}%
    \renewcommand\chaphead{#2}%
    \oldchapter[#1]{#2}}

\newcommand*\Hide{%

\titleformat{\chapter}[display]
  {}{}{0pt}{}
%\titleclass{\chapter}{straight}

\titleformat{\section}[display]
  {\large} % format
  {\chaphead, section \thesection} % label
  {10pt} %sep
  {} %before
}

\begin{document}

{
\Hide
\chapter{A first chapter}
\section{A first section}
\lipsum
}

\chapter{A second chapter}
\section{A second section}
\lipsum

\end{document}

When activating \titleclass{\chapter}{straight}, it seems \chaphead is not capture anymore.

  • The headings must not be typeset, but the space they occupied must remain? – Gonzalo Medina Apr 18 '11 at 12:20
  • I mean to hide the chapter name completely, so it doesn't appear in the text. – ℝaphink Apr 18 '11 at 12:49
4

Indeed, you can use the titlesec package; its explicit option allows you to remove the titles:

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

\newcommand*\Hide{%
\titleformat{\chapter}[display]
  {}{}{0pt}{\Huge}
\titleformat{\part}
  {}{}{0pt}{}
}

\begin{document}
\tableofcontents

{
\Hide
\part{A test part}
\chapter{A test chapter}
\section{Test section}
}

\part{A test part}
\chapter{A test chapter}
\section{Test section}

\end{document}
  • Alright, that removes the chapter headings... but it also removes the section headings, and the chapter headings outside of the environment in which I did the call to \titleformat... – ℝaphink Apr 18 '11 at 14:06
  • You can keep the changes local by using the grouping mechanism; I've edited my example to reflect this approach (and defining a command to simplify the work). – Gonzalo Medina Apr 18 '11 at 14:11
  • Hmmm... I'm using an environment already, that should limit the scope, shouldn't it? – ℝaphink Apr 18 '11 at 14:15
  • Without your actual relevant code it's really hard to tell. Why don't you add to your question all the necessary elements (in the sense of a minimal working example) affecting your request? – Gonzalo Medina Apr 18 '11 at 14:22
  • 1
    Again, without knowledge of your actual relevant code, this process of guessing is totally useless and time wasting... as I already suggested, add a minimal working example of your relevant code. – Gonzalo Medina Apr 18 '11 at 14:43
0

I extended and changed the example for class srcartcl to the following solution (You find the one for class srcbook below):

\documentclass{scrartcl}
\usepackage{blindtext}
\usepackage[explicit]{titlesec}

% change part format
\titleformat{\part}[drop]{}{}{0pt}{}
\titlespacing*{\part}{0pt}{0pt}{0pt}

\begin{document}
\tableofcontents

\part{One}
\blindtext
\section{Apple}
\blindtext
\section{Peach}
\blindtext

\part{Two}
\blindtext
\section{Red}
\blindtext
\section{Green}
\blindtext

\end{document}

Btw.: It works nicely together with the counter reset from Adendum 2 in this first answer.

\makeatletter
\@addtoreset{section}{part}
\makeatother

Here the code with scrbook:

\documentclass{scrbook}
\usepackage{blindtext}
\usepackage[explicit]{titlesec}

% change part format
\titleformat{\part}[drop]{}{}{0pt}{}
\titlespacing*{\part}{0pt}{0pt}{0pt}
\titleformat{\chapter}[drop]{}{}{0pt}{}
\titlespacing*{\chapter}{0pt}{0pt}{0pt}

\begin{document}
\tableofcontents

\part{One}
\blindtext
\chapter{Fruits}
\blindtext
\section{Apple}
\blindtext
\section{Peach}
\blindtext

\part{Two}
\blindtext
\chapter{Colours}
\blindtext
\section{Red}
\blindtext
\section{Green}
\blindtext

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.