Text FormattingSpaces above and below headings

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
nipj
Posts: 17
Joined: Thu May 10, 2018 6:15 am

Spaces above and below headings

Post by nipj »

Hello!

I found in this forum the following code to remove spaces before "\chapter":

Code: Select all

\usepackage{etoolbox}
\makeatletter % 
\patchcmd{\@makechapterhead}{\vspace*{50\p@}}{}{}{}% Removes space above \chapter head
\patchcmd{\@makeschapterhead}{\vspace*{50\p@}}{}{}{}% Removes space above \chapter* head
\makeatother
Is there a way to do remove spaces after "\chapter" using similar commands?

Thanks & Regards.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Spaces above and below headings

Post by Johannes_B »

Welcome to the forum,

sure there is a way. The standard classes are very old, one could argue that they are full of spaghetti code.
While the space above chapters is done using vspace, for the space below, the class uses \vskip for spacing. A package like titlesec can cahnge the appearance of chapters, sections etc using commands, though i personally don't think the package is intuitive.

Code: Select all

\documentclass{report}
\usepackage{blindtext}
\usepackage{etoolbox}
\makeatletter %
\patchcmd{\@makechapterhead}{\vskip 40\p@}{\bigbreak}{}{}% Removes space below \chapter head
\patchcmd{\@makeschapterhead}{\vskip 40\p@}{\bigbreak}{}{}% Removes space below \chapter* head
\patchcmd{\@makechapterhead}{\vspace*{50\p@}}{}{}{}% Removes space above \chapter head
\patchcmd{\@makeschapterhead}{\vspace*{50\p@}}{}{}{}% Removes space above \chapter* head
\makeatother
\begin{document}
\chapter{Wallaby}
\blindtext
\chapter*{Alpaca}
\blindtext
\end{document}
In the example above, i did not completely remove the space below the chapter title, because it looks just awful.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
nipj
Posts: 17
Joined: Thu May 10, 2018 6:15 am

Spaces above and below headings

Post by nipj »

Your code works!

And I agree with you, "titlesec" package is not that easy to work with, at least for beginners like me.

Thanks for your time and help!
nipj
Posts: 17
Joined: Thu May 10, 2018 6:15 am

Spaces above and below headings

Post by nipj »

How would the code look if someone needs to completely remove the space below the chapter title.

I tried myself by deleting the increasing, decreasing and deleting the number "40", without success. I also removed "\bigbreak", but I'm not sure if the space below is deleted 100%

Regards.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Spaces above and below headings

Post by Johannes_B »

Removing \bigbreak is the way to go.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
nipj
Posts: 17
Joined: Thu May 10, 2018 6:15 am

Spaces above and below headings

Post by nipj »

Thank you.
Post Reply