\clearpage after every subsubsection

1,854

Solution 1

You could include the following instructions in your document's preamble:

\usepackage{titlesec}
\newcommand\sectionbreak{\ifnum\value{section}>1\clearpage\fi}
\newcommand\subsectionbreak{\ifnum\value{subsection}>1\clearpage\fi}
\newcommand\subsubsectionbreak{\ifnum\value{subsubsection}>1\clearpage\fi}

This will insert a page break every time a \section, \subsection, or \subsubsection command is encountered if the corresponding counter is greater than 1. I.e., every \section command after the very first such command will trigger a page break; every \subsection command after the very first such command within a given section will trigger a page break, etc.

This method assumes that your document class uses "plain" counter variables for section, subsection and subsubsection. If that's not the case, please indicate how you've set up those variables.

Solution 2

The following doesn't require titlesec:

\makeatletter
\newif\if@subsubsectionused \@subsubsectionusedfalse
\let\oldsection\section
\let\oldsubsection\subsection
\let\oldsubsubsection\subsubsection
\renewcommand{\section}{\if@subsubsectionused\clearpage\@subsubsectionusedfalse\fi\oldsection}
\renewcommand{\subsection}{\if@subsubsectionused\clearpage\@subsubsectionusedfalse\fi\oldsubsection}
\renewcommand{\subsubsection}{\if@subsubsectionused\clearpage\fi\@subsubsectionusedtrue\oldsubsubsection}
\makeatother

It inserts a \clearpage before calling the traditional sectioning command based on a condition \if@subsubsectionused. This condition is set to true whenever a \subsubsection is used, and to false otherwise.

An example of code like

\section{A section}
\subsection{A subsection}
\subsubsection{A subsubsection}
\subsubsection{A subsubsection}
\subsection{A subsection}
\subsubsection{A subsubsection}
\subsubsection{A subsubsection}
\section{A section}
\subsection{A subsection}
\subsubsection{A subsubsection}
\subsubsection{A subsubsection}
\subsection{A subsection}
\subsection{A subsection}
\subsubsection{A subsubsection}
\subsubsection{A subsubsection}

would yield a layout of

1 A section
1.1 A subsection
1.1.1 A subsubsection
-----------< page break >--------------------
1.1.2 A subsubsection
-----------< page break >--------------------
1.2 A subsection
1.2.1 A subsubsection
-----------< page break >--------------------
1.2.2 A subsubsection
-----------< page break >--------------------
2 A section
2.1 A subsection
2.1.1 A subsubsection
-----------< page break >--------------------
2.1.2 A subsubsection
-----------< page break >--------------------
2.2 A subsection
2.3 A subsection
2.3.1 A subsubsection
-----------< page break >--------------------
2.3.2 A subsubsection
Share:
1,854

Related videos on Youtube

user28291
Author by

user28291

Updated on April 13, 2020

Comments

  • user28291
    user28291 over 3 years

    I'd like to clear the page at the end of every \subsubsection. I tried

    \usepackage{titlesec}
    \newcommand{\subsubsectionbreak}{\clearpage}
    

    But this appears to force a \clearpage at the start of every \subsubsection. Is it possible to force a \clearpage at the end?

    • Mico
      Mico over 10 years
      Just to clarify: Do you also want page breaks between subsections that do not include subsubsections, and between sections that do not include subsections? Please advise.
    • user28291
      user28291 over 10 years
      @Mico Yes I also want page breaks between subsections and sections (even if they don't include subsub or subsections).
    • Werner
      Werner over 10 years
      What do your current definitions of the sectional units \section, \subsection and \subsubsection using titlesec look like?
    • Werner
      Werner over 10 years
      According to @Mico's comment and your response, it seems like you just want a \clearpage at every sectional level (\section, \subsection and \subsubsection). Correct?
    • user28291
      user28291 over 10 years
      @Werner Sorry for the confusion. I don't just want page breaks everywhere. That could be accomplished by adding \clearpage for every *sectionbreak command. When I do that I have way to many almost blank pages. I really just want to force a clearpage at the end of every subsubsection.
  • user28291
    user28291 over 10 years
    It works if I add a \fi at the end of the macro definition, otherwise I get a bunch of warnings
  • Mico
    Mico over 10 years
    @user28291 - Thanks for pointing out this omission - I've added the \fi instructions.