16

I have tried to look through, but I couldn't find a clear solution on this.

I have a document that uses report with multiple \chapters in multiple \parts as:

\part{foo}
\chapter{uno}
\chapter{dos}
\part{bar}...

This results in an entire page that is "Part I Uno". I would like to remove the page break, and have both part foo, and chapter uno on the same page as:

Part I foo
Chapter 1 Uno

How do I do that?

lockstep
  • 250,273
Elmasto
  • 161
  • 1
    chapter produces also a page break. However you can use a package like titlesec. – Marco Daniel Jan 27 '12 at 19:56
  • titlesec package is what you search for, as Marco suggests. The page break can be manually removed by some "low-level" tweak (you can locally redefine the command that makes the page break), but it is really not a nice solution to this. – yo' Jan 27 '12 at 19:58

2 Answers2

23

With the titlesec package, you could define a "title class" without pagebreak:

\titleclass{\part}{top}
\titleclass{\chapter}{straight}

Title classes are:

  • page: a single page like a book part page
  • top: starts a page and places the heading at the top
  • straight: titles in the text, such as by \section

A full example:

\documentclass{book}
\usepackage{titlesec}
\titleclass{\part}{top}
\titleformat{\part}[display]
  {\normalfont\huge\bfseries}{\centering\partname\ \thepart}{20pt}{\Huge\centering}
\titlespacing*{\part}{0pt}{50pt}{40pt}
\titleclass{\chapter}{straight}
\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter} {0pt}{50pt}{40pt}
\begin{document}
\part{foo}
\chapter{uno}
\end{document}

part and chapter heading

Stefan Kottwitz
  • 231,401
  • I was hesitating to go the titlesec route, but this works well, and I am enjoying the flexibility of the package. A follow up question...this removes the page break at the end of the chapter. So a new part/chapter starts on the same page of the text as the previous chapter. I could use something like /eject and start a new page, but is there a nicer way to keep the page-break at the end of the chapter? – Elmasto Jan 27 '12 at 20:32
  • @Elmasto: use the top class for parts starting on new pages. I updated my answer. – Stefan Kottwitz Jan 27 '12 at 20:50
  • this does not work work with komascript(scrbook) – user8868 May 06 '12 at 07:56
13

To achieve your objective without loading a package such as titlesec, one must (i) modify the command \@endpart and (ii) change the \chapter command because it, too, inserts a page break by default. Although you didn't specify this explicitly, I further assume that you (iii) want to have the "Part xx" material placed at the top of the page rather than in the middle. By the way, I assume that your document is set in "onecolumn" rather than in "twocolumn" mode. Taking care of the twocolumn case isn't all that more difficult, but it does add some overhead which I gather isn't required here.

The following code shows how to do this for the case of the report document class. Note that I've created a command called \nonewpagechapter and have left the standard \chapter command untouched. That way, you can still use the \chapter command for all those occasions when you do want the chapter to start on a new page. Of course, if \nonewpagechapter is too wordy for your taste, you can give it a more succinct name, such as \nchapter...

\documentclass{report}   
\usepackage{etoolbox}

\makeatletter
% First, modify the \@endpart macro.
\def\@endpart{} 

% Next, copy the \chapter macro to \nonewpagechapter, and ...
% ... suppress page-breaking instructions in the modified macro
\let\nonewpagechapter\chapter 
\patchcmd\nonewpagechapter{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}

% Third, suppress vertical whitespace before "Part xx" material
\patchcmd{\part}{\null\vfil}{}{}{}

\makeatother

\begin{document}
\part{foo}
\nonewpagechapter{Uno} % starts on same page as "Part I ... foo" header
\chapter{Dos}          % starts on a new page
\part{bar}             % starts on a new page
\nonewpagechapter{Tres}% starts on same page as "Part II ... bar" header
\end{document}

Addendum If someone were using the scrbook (Koma-Script book) document class instead of the report document class, he/she would have to replace the command

\patchcmd{\part}{\null\vfil}{}{}{}

with

\patchcmd{\part}{\partheadstartvskip}{}{}{}

in order to suppress the insertion of extra whitespace above the "Part xx" line. The other patch commands could be used without modification.

Mico
  • 506,678
  • +1 for adding \nonewpagechapter. – lockstep Jan 27 '12 at 20:15
  • I liked the idea of modifying the existing commands, but I am having a hard time compiling this (pdflatex). It says 'use of @ doesn't match definition'. – Elmasto Jan 27 '12 at 20:36
  • I added a blank line before \makeatletter. The MWE should compile now. – Mico Jan 27 '12 at 20:43
  • I have tried your answer with koma script (a example is here: http://pastebin.com/JCKXvzhu), and the problem I have is that the part starts very low on the page. (In the example at about have the page, but in longer documents, it might even start lower). Do you know a fix for that? – user8868 May 06 '12 at 13:38
  • @user8868: Do note that my answer was geared to the report document class, as that's what the OP specified. Which one of the koma-script classes are you using? Any adaptation of the code I've provided will depend on the document class in use. – Mico May 06 '12 at 14:11
  • I use scrbook, more or less like in the code example on pastebin. – user8868 May 06 '12 at 15:06
  • 1
    @user8868 -- to get the code working with the scrbook document class, all you need to do is to change the instruction \patchcmd{\part}{\null\vfil}{}{}{} to \patchcmd{\part}{\partheadstartvskip}{}{}{}. This is the case because the \part command is implemented quite differently in the scrbook and report document classes. Interestingly, the other patching commands needn't be modified. Do note, by the way, that more commands would have to be modified if the twocolumn option were in force. (However, judging from your notes, this does not seem to be the case for your document.) – Mico May 06 '12 at 17:04