49

I'm using LaTeX using the article type 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?

4
  • Please add a minimal example that illustrates your problem. Commented Nov 3, 2010 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
    Commented Nov 3, 2010 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. Commented Nov 3, 2010 at 23:26
  • 4
    No question is too basic for this site, as long as it's ask clearly.
    – mpg
    Commented Nov 3, 2010 at 23:49

4 Answers 4

43

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.

7
  • 1
    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
    Commented Nov 3, 2010 at 23:57
  • 13
    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
    Commented Nov 4, 2010 at 0:03
  • 1
    @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. Commented Nov 4, 2010 at 0:12
  • 3
    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
    Commented Jan 30, 2011 at 16:08
  • 2
    @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
    Commented Jan 14, 2014 at 13:34
40

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.

3
  • 2
    @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. Commented Nov 4, 2010 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
    Commented Nov 4, 2010 at 14:45
  • 4
    +1 for encouraging use of a distributed package to change the formatting instead of an idiosyncratic patch.
    – Aaron
    Commented Mar 27, 2011 at 17:04
2

The titlesec package allows changing the section margins:

\usepackage{titlesec}
\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{1em}
  • The above are the default values, that you can modify as needed.

  • I recommend using plus and minus for spacing to adapt to how much space is left on the page.

0

If you are using a KOMA-Script template such as scartcl:

You can modify section spacing by using \DeclareSectionCommand, e.g. the default definition for \paragraph is:

\DeclareSectionCommand[%
level=4,
indent=0pt,
beforeskip=3.25ex plus 1ex minus .2ex,
afterskip=-1em,
font={},
tocindent=7em,
tocnumwidth=4.1em,
counterwithin=subsubsection
]{paragraph}

By reducing beforeskip, you can change this spacing to your liking.

You must log in to answer this question.

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