# Change whitespace above and below a section heading

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.

-
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 6 '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 6 '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 6 '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 6 '10 at 11:43
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 6 '10 at 12:09

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.

-
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 6 '10 at 11:26
The compact option already decreases whitespace. You want to decrease it more? –  Seamus Nov 6 '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 6 '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 6 '10 at 11:56

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

-