# How do I control the spacing above a new \paragraph?

I'm sorry if this question has been answered earlier or is too basic for this site, but I couldn't find a reference.

I'm using LaTeX using the article documentclass. I haven't customized any of the LaTeX variables that determine lengths, such as \parindent, \topskip etc. I want to control the amount of vertical spacing that appears right above a new \paragraph. In particular, I want to squeeze it. Any hints?

-
Please add a minimal example that illustrates your problem. – Matthew Leingang Nov 3 '10 at 23:05
Thanks! I'm new to this site. I just mean the most obvious thing, without any customizations. Whenever I start a new "\paragraph", there's some vertical spacing between the newly created paragraph and the text above it. How do it control the amount of spacing? – arnab Nov 3 '10 at 23:12
Welcome. Help us help you. :-) Edit your question to describe what you want to do, what you tried, and what it did instead of what you wanted. Actual code helps. What format (plain TeX, LaTeX, ConTeXt, etc) you're using might also be relevant. – Matthew Leingang Nov 3 '10 at 23:26
No question is too basic for this site, as long as it's ask clearly. – mpg Nov 3 '10 at 23:49

Now that your document class is known, the rest isn't too hard. The definition of \paragraph needs to be changed. The following code snippet (to be added to your preamble) would reproduce the original definition of \paragraph in the article class:

\makeatletter
\renewcommand{\paragraph}{%
\@startsection{paragraph}{4}%
{\z@}{3.25ex \@plus 1ex \@minus .2ex}{-1em}%
{\normalfont\normalsize\bfseries}%
}
\makeatother


Change 3.25ex to a smaller value, and the vertical spacing before a paragraph section will be reduced. (The values after \@plus and \@minus are parameters for stretching and shrinking the standard space - you may change those also, but don't need to.) The -1em in the following argument controls the spacing after the paragraph section -- the negative sign effects that horizontal space is added, i.e., \paragraph will produce an inline heading.

-
This helps a lot. Thanks! Btw, for future reference, where do you get the default definition of \paragraph from? Again, apologies for what must be really basic questions. – arnab Nov 3 '10 at 23:57
If you add \show\paragraph to your LaTeX file, the definition of \paragraph is shown in your output messages (which are saved in a logfile). (For some internal macros, you will have to look up the definition in the documentation of the source code.) – lockstep Nov 4 '10 at 0:03
@arnab: glad you found your answer. \paragraph is defined in article.cls, but only in terms of a more primitive macro \@startsection which is found in latex.ltx. It takes a while before it all makes sense. – Matthew Leingang Nov 4 '10 at 0:12
I'd add that the {-1em} parameter in the above example controls spacing after the section. Not that it's relevant to the question, but this is the only place that covers @startsection in this level of detail! – Marcin Jan 30 '11 at 16:08
@Roly (1) means that you're not using the default settings of the article class. Replacing \bfseries with \itshape in my code snippet would produce an italic paragraph heading. Regarding (2), I tried to improve my answer by incorporating Marcin's comment. – lockstep Jan 14 '14 at 13:34

Package titlesec provides many tools for customizing chapter/section/paragraph/etc headings. Here is an example (which also serves as an example of minimal working example ;-) ):

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{lmodern}

\usepackage{titlesec}
\usepackage{lipsum}% provides filler text

\titlespacing{\paragraph}{%
0pt}{%              left margin
0.5\baselineskip}{% space before (vertical)
1em}%               space after (horizontal)

\begin{document}

\lipsum[1]

\paragraph{Lipsum 2} \lipsum[2]

\end{document}


Unfortunately, there is no easy way (that I know) to change only the vertical spacing before, you need to specify the other parameters too, namely 0pt for left margin and 1em for the spacing after (got that one from guessing and checking). I made the vertical spacing 0.5\baselineskip which mean half the height of a normal line, and looks smaller that the default spacing. Obviously, you can use 0pt to squeeze this space completely.

-
Thanks! For the answer, and for the example :) – arnab Nov 4 '10 at 0:03
@arnab, @mpg: It's even better if instead of 0.5\baselineskip you use something with stretch and shrink, as lockstep mentioned. You can, e.g., use 0.5\baselineskip plus 0.2\baselineskip minus 0.1\baselineskip. This is important when you have a twosided document (option twoside in article), where TeX wants to achieve a constant text height. – Hendrik Vogt Nov 4 '10 at 9:43
@Hendrik: you're right. I tried to simplify the example, but simplifying on this point probably wasn't a good idea. – mpg Nov 4 '10 at 14:45
+1 for encouraging use of a distributed package to change the formatting instead of an idiosyncratic patch. – Aaron Mar 27 '11 at 17:04