Page LayoutCan I have my chapter titles centered, with numbering only, and no new pages before or after ?

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
dbourrion
Posts: 4
Joined: Sat Apr 13, 2024 8:33 am

Can I have my chapter titles centered, with numbering only, and no new pages before or after ?

Post by dbourrion »

Hi there.

Well, it seems everything is almost in the subject :)

Let's explain more.

In a book, I'm trying to have the number (juste the number) of each chapter in the center of the page, and newpage when a new chapter begins

The result should look like :

1 (centered)

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam gravida sem metus, ac maximus elit aliquam sed. Interdum et malesuada fames ac ante ipsum primis in faucibus. Morbi placerat magna nec scelerisque varius. Quisque est velit, ullamcorper et eros non, venenatis commodo mi. Nulla rutrum velit a nisl tristique sollicitudin.

2 (centered)

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam gravida sem metus, ac maximus elit aliquam sed. Interdum et malesuada fames ac ante ipsum primis in faucibus. Morbi placerat magna nec scelerisque varius. Quisque est velit, ullamcorper et eros non, venenatis commodo mi. Nulla rutrum velit a nisl tristique sollicitudin.

etc

Help welcome. Many thanks.
D.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
dbourrion
Posts: 4
Joined: Sat Apr 13, 2024 8:33 am

Can I have my chapter titles centered, with numbering only, and no new pages before or after ?

Post by dbourrion »

Well, this is working.
I'm happy.

Code: Select all

\documentclass[a4paper,14pt,oneside]{extbook}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{microtype}
\usepackage{setspace}
\usepackage{xpatch}

\makeatletter

\xpatchcmd{\@makeschapterhead}{%
	\Huge \bfseries  #1\par\nobreak%
}{%
	\Huge \bfseries\centering #1\par\nobreak%
}{\typeout{Patched makeschapterhead}}{\typeout{patching of @makeschapterhead failed}}


\xpatchcmd{\@makechapterhead}{%
	\huge\bfseries \@chapapp\space \thechapter
}{%
	\huge\bfseries\centering \@chapapp\space \thechapter
}{\typeout{Patched @makechapterhead}}{\typeout{Patching of @makechapterhead failed}}

\makeatother

\renewcommand{\chaptername}{} %% remove the word \chapter
\renewcommand{\cleardoublepage}{}
\renewcommand{\clearpage}{}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Can I have my chapter titles centered, with numbering only, and no new pages before or after ?

Post by Stefan Kottwitz »

That's great to hear! I'm glad that you could solve it. Also, I drafted a solution, but the concept was confusing me. I would not use chapter functions if it's not like a LaTeX chapter (no title, no header entries, no table of contents item, font and spacing, etc.). I think I would have used a counter and a self-made heading command.

Thank you for letting us know how you work on it!

Stefan
LaTeX.org admin
dbourrion
Posts: 4
Joined: Sat Apr 13, 2024 8:33 am

Can I have my chapter titles centered, with numbering only, and no new pages before or after ?

Post by dbourrion »

Hi Stephan

About "I think I would have used a counter and a self-made heading command." : i'm a Latex newbie, I think I'm enable to do that :D

For "my" solution, I've just glue together two solutions I've found on the Internet. It's not very sexy, or accurate, but it works enough for me.

Best regards
Post Reply