39

I want to change the spacing around a section heading so that there is less of a gap between it and the paragraph that follows.

I found the following commands

\usepackage[compact]{titlesec}  
\titlespacing{\section}{0pt}{0pt}{0pt}

But that produces the error Package titlesec Error: Entered in horizontal mode.. Googling has not found any useful answers for that.

Is there another way to change the spacing around headings or is there an easy fix for that error?

Im using fancyhdr and sectsty if that makes a difference.

lockstep
  • 250,273
Adam Pope
  • 1,055
  • 2
    titlesec and sectsty are likely to interfere with each other, as they both change the way headings are handled. That said, I wasn't able to reproduce the error you described, so you should provide a minimal example. – lockstep Nov 06 '10 at 11:26
  • Yeah, \titlespacing{\section}{0pt}{0pt}{0pt} compiles fine for me. Though it is pretty ugly: whitespace is your friend. – Seamus Nov 06 '10 at 11:32
  • I want whitespace - just not as much as default. I was only using 0 until I could see what the results look like to trial+error my way to good spacing. Obviously I need it to compile first :) I'll try commenting out other packages. – Adam Pope Nov 06 '10 at 11:39
  • Yup, it's a conflict with sectsty. I was using that to set the text size and color, can I do that easily with \titleformat in the titlesec package? – Adam Pope Nov 06 '10 at 11:43
  • add \listfiles to your preamble and tell us what versions of titlesec and sectsty you're using. Also tell us what you are using sectsty for... – Seamus Nov 06 '10 at 11:44
  • I've edited my answer. I hope that helps – Seamus Nov 06 '10 at 11:48
  • I'm using titlesec.sty 2007/08/12 v2.8 and sectsty.sty 2002/02/25 v2.0.2. I was using the following with sectsty

    \sectionfont{\fontsizesection\color{grey}\textmd}
    \subsectionfont{\fontsizesubsection\color{stormblue}\textmd}

    where the fontsizes and colors are custom definitions

    – Adam Pope Nov 06 '10 at 11:50
  • 4
    You probably want to use \titlespacing* instead of \titlespacing because "[t]he starrred version kills the indentation of the paragraph following the title" (titlesec manual, p. 9). – lockstep Nov 06 '10 at 12:09

3 Answers3

29

You can use \usepackage[compact]{titlesec} to shrink all the whitespace around section headings.

Whatever sectsty is doing for you, you can probably also do it with titlesec. I expect the problem is due to some clash between them.

Adding to my answer from the comments above: titlesec's \titleformat option can deal with size and colour options. See pp. 3-4 of the titlesec manual.

Seamus
  • 73,242
  • Sorry, I'm already using [compact]. I copied and pasted a version where I was just playing around to get rid of the error message. I still get the Entered in horizontal mode error. – Adam Pope Nov 06 '10 at 11:26
  • The compact option already decreases whitespace. You want to decrease it more? – Seamus Nov 06 '10 at 11:27
  • My document doesn't compile when I include the titlesec package - I don't know what the results look like to judge how much I want to remove. – Adam Pope Nov 06 '10 at 11:38
  • Thanks for your update - it turns out it was me using \textmd in my \sectionfont definition that was breaking it as it also broke in \titleformat until I removed it. – Adam Pope Nov 06 '10 at 11:56
  • Excellent answer. This may be combined with size options, as in \usepackage[small,compact]{titlesec} – PatrickT Oct 05 '23 at 03:21
5
\usepackage[compact]{titlesec}
\titlespacing{\section}{0pt}{*0}{*0}
\titlespacing{\subsection}{0pt}{*0}{*0}
\titlespacing{\subsubsection}{0pt}{*0}{*0}
Johannes_B
  • 24,235
  • 10
  • 93
  • 248
0

I use \vspace{12pt} for spacing. I am not saying it is correct, it just works for me.

John
  • 133