2

I'm writing a paper with some specifications in the section titles. I know that titlesec package is an excellent alternatve, but becuse some compatibility problems I have to use sectsty. I don't know how to specify the space before and after the section and subsection titles with this package. I saw the package documentation and some answers here, but I didn't find anything.

Some hints?

  • As Werner points out in his answer, what you want to do is not possible with sectsty. The package is meant for changing the font only. It is a bit like asking how to get a nail into the wall with toilet paper. It just doesn't work. – Johannes_B Jul 23 '17 at 7:20
1

Redefine the entire \section (and other commands) to suit your needs. Here are the defaults from sectsty:

\renewcommand\section{\@startsection {section}{1}{\z@}%
      {-3.5ex \@plus -1ex \@minus -.2ex}%
      {2.3ex \@plus.2ex}%
      {\normalfont\Large\bfseries\SS@sectfont}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
      {-3.25ex\@plus -1ex \@minus -.2ex}%
      {1.5ex \@plus .2ex}%
      {\normalfont\large\bfseries\SS@subsectfont}}

Since sectsty only changes the font, the only difference between the above and the default definition from the base document class is the addition of \SS@<sec>font to each sectional unit.

Referring to Where can I find help files or documentation for commands like \@startsection for LaTeX?, you should change arguments #4 (<beforeskip>) and #5 (<afterskip>). Here is one option you can add to your preamble that increases the <beforeskip> and <afterskip> slightly:

\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
      {-5ex \@plus -1ex \@minus -.2ex}% <beforeskip>
      {3ex \@plus.2ex}% <afterskip>
      {\normalfont\Large\bfseries\SS@sectfont}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
      {-4ex\@plus -1ex \@minus -.2ex}% <beforeskip>
      {2ex \@plus .2ex}% <afterskip>
      {\normalfont\large\bfseries\SS@subsectfont}}
\makeatother

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.