1

I am using titlesec to define the format of my chapter titles, for instance:

\titleformat{\chapter}[hang]{\Large\bfseries}{}{0em}{\LARGE\bfseries}

I would like to be able to specify the same format (i.e., extract the \LARGE\bfseries bit) for a portion of normal text.

Motivation: I am typesetting an anthology where one of the authors occasionally starts a new chapter alongside a figure, in a table, inbetween paragraphs, and so on. So while most of my chapters start on a new page and I don't want to change the default, I need to "fake" a new chapter in several places. My idea is to set it with font defined by \titleformat, increment counters if necessary (the book does not have numbered chapters so probably not) and add to contents with \addcontentsline.

1
  • So what you want is a nobreak chapter and a regular chapter, but the nobreak chapter is otherwise identical to a regular chapter?
    – Alan Munn
    Commented Oct 20, 2017 at 15:22

1 Answer 1

2

Here's a simple solution. It defines a \nobreakchapter command that behaves just like \chapter but suppresses the pagebreak. To do this I've created a boolean \ifnbchap which gets set to true by the \nobreakchapter. Then this boolean is used inside a patched \chapter command to skip the pagebreak code. Since your question is quite sketchy on more details I haven't done anything else to format this type of chapter. I reset the \nbchap conditional to false using the titlesec end code, so that you can use that conditional to also affect any formatting requirements (e.g. vertical spacing) you might need for the \nobreakchapter command.

In response to the comment, I've also eliminated the \thispagestyle{plain} command from the \nobreakchapter chapters.

\documentclass{book}
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\Large\bfseries}{}{0em}{\LARGE\bfseries}[\global\nbchapfalse]
\usepackage{xpatch}
\usepackage{kantlipsum} % for dummy text
\newif\ifnbchap
\xpretocmd{\chapter}{\ifnbchap\else}{}{}
\xpatchcmd{\chapter}{\clearpage\fi}{\clearpage\fi\fi}{}{}
\xpatchcmd{\chapter}{\thispagestyle{plain}}{\ifnbchap\else\thispagestyle{plain}\fi}{}{}
\newcommand{\nobreakchapter}{\nbchaptrue\chapter}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{This is a regular chapter}
\kant
\chapter{This is another regular chapter}
\kant[1]
\nobreakchapter{This is a no break chapter}
\kant[2]
\nobreakchapter{This is another no break chapter}
\kant
\chapter{Another regular chapter}
\kant
\nobreakchapter{A nobreak chapter} 
\kant[1]
\chapter{Another regular chapter}
\kant
\end{document}

partial output of code

4
  • Not sure if I did something wrong but using \nobreakchapter suppresses all explicit \clearpage commands I have in my code.
    – Frigo
    Commented Oct 20, 2017 at 19:36
  • @Frigo You're absolutely right. Sorry about that. I've revised the code using a conditional which you can then also use within your titlesec commands to adjust spacing if needed. This should now work as you expect.
    – Alan Munn
    Commented Oct 20, 2017 at 21:29
  • This works for me now but opens up a new can of trouble so I won't be using it in my specific case. For instance, since the chapters now start mid-page, I don't want to use the plain page style for them. Also \nobreakchapter does not stack with \lettrine, which I find I need to use in one place. I think I really need to use just plain text, formatted in the same way as chapter titles.
    – Frigo
    Commented Oct 22, 2017 at 12:38
  • @Frigo You gave so little information in your question, this is the result. I've added code to change fix the pagestyle problem. If you want to solve the lettrine problem, ask a new question with a minimal working document using my code and linking to this question which clearly shows the lettrine problem.
    – Alan Munn
    Commented Oct 22, 2017 at 13:03

You must log in to answer this question.

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