How to Remove Extra Space After a LaTeX Section Title
At a glance
- 1. Find the source
Check the custom command and the lines immediately after the section command for added vertical spacing or paragraph breaks.
- 2. Remove duplicate spacing
Delete unnecessary vspace, line breaks, or blank paragraphs; the document class already sets section spacing.
- 3. Set spacing deliberately
If you want different heading spacing throughout, use a heading-formatting package or a class-level setting.
Extra space after a \section heading is usually not caused by the newline in your .tex file. The document class already adds vertical space around section headings; a custom command can add a second, unintended amount.
The usual fix is to remove the extra spacing instruction from the custom command or from the text immediately after the heading. If you mean extra horizontal space at the end of the heading rather than a vertical gap below it, see the distinction below.
What controls the space after a heading?
Commands such as \section use spacing rules set by the document class. Those rules determine the gap before the heading and the gap between the heading and the following text. A command that runs immediately after \section can add more space on top of the class’s default.
Look in your custom command and nearby source for:
\vspace{...}or\vspace*{...};\\or\newline, which force a line break;- paragraph-spacing settings, such as a nonzero
\parskip; - environments, such as lists, that introduce their own vertical spacing.
A blank line in the source is treated as a paragraph break. After an ordinary displayed section heading, that break does not, by itself, normally add a fixed extra gap. But if the command also changes paragraph spacing, or starts an environment, the result can look like unwanted heading space.
Remove the extra space from the command
For example, this custom command explicitly inserts additional vertical space after every section:
\newcommand{\mysection}[1]{%
\section{#1}%
\vspace{1em}%
}
If you do not want that extra gap, remove the \vspace:
\newcommand{\mysection}[1]{%
\section{#1}%
}
Here is a complete minimal document that uses the corrected version:
\documentclass{article}
\newcommand{\mysection}[1]{%
\section{#1}%
}
\begin{document}
\mysection{First section}
This paragraph begins with the spacing chosen by the article class.
\end{document}
The % characters at the ends of lines prevent ordinary source whitespace from being included in the command’s definition. They do not remove vertical space; the important change is that the custom command no longer adds \vspace.
If your command does not contain explicit spacing, temporarily replace it with a plain \section{...}. If that removes the gap, add parts of the command back one at a time until you find the instruction responsible.
Change heading spacing consistently
If you want to change section spacing throughout the document, configure the heading style rather than adding a spacing command after each heading. For example, the titlesec package lets you set the space before and after section headings:
\documentclass{article}
\usepackage{titlesec}
\titlespacing*{\section}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\begin{document}
\section{First section}
This paragraph follows the section heading.
\end{document}
In this command, the first length is the left indent, the second is the space before the heading, and the third is the space after it. The values above are an example; adjust them to suit your layout. Check compatibility if your document class already has its own heading-formatting rules.
If the problem is horizontal space
A visible gap at the end of the heading text is a different issue from a vertical gap below the heading. It can occur if the command used inside the title expands to text followed by an explicit space, such as \ or \space. Remove that trailing space from the command if it is not needed. Do not remove spaces that are necessary between words in the title.
Ordinary spaces after a control word in the source—for example, after \textbf—are generally consumed by TeX when it reads the command name. They are not a reliable way to add spacing in the output.
Common mistakes
- Adding negative
\vspaceimmediately after\section. This may appear to work on one page but can behave poorly near page breaks and with other heading styles. - Using
\\to adjust the gap below a heading. It makes a line break, not a general heading-spacing setting, and can produce inconsistent results. - Changing the class’s spacing without checking the custom command. If the command itself adds space, changing the class may hide rather than fix the cause.
- Assuming every gap is an error. Some vertical space after a heading is intentional and is set by the document class.
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.