3

Given the package sectsty and the following code:

\documentclass[english]{article}
\usepackage{lipsum}

\usepackage{sectsty}
\sectionfont{\sectionrule{0ex}{0pt}{-1ex}{0.2pt}}

\begin{document}
\section*{Life}
\lipsum[1]
\end{document}

enter image description here

Is there a way to adjust the vertical distance between the horizonatal line (underneath the word "Life") and the lipsum text, just by acting on the command \sectionfont{\sectionrule{0ex}{0pt}{-1ex}{0.2pt}}?

2
  • 1
    What do you mean with “adjust“? Increase or decrease?
    – cabohah
    Commented Mar 7 at 11:05
  • I mean both of them... :-)
    – Ommo
    Commented Mar 7 at 11:06

2 Answers 2

5

No, but you can define another command, that uses \sectionrule, for example:

\documentclass[english]{article}
\usepackage{lipsum}

\newcommand{\adaptedsectionrule}[6]{%
  \sectionrule{#1}{#2}{#3}{#4}{#6\rule[-#5]{0pt}{#5}}% invisible rule used to increase the distance below

\usepackage{sectsty}
\sectionfont{\adaptedsectionrule{0ex}{0pt}{-1ex}{0.2pt}{1em}}

\begin{document}
\section*{Life}
\lipsum[1]
\end{document}

But IMHO a better solution would be to change the distance after \section:

\documentclass[english]{article}
\usepackage{lipsum}
\usepackage{sectsty}

\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
      {-3.5ex \@plus -1ex \@minus -.2ex}%
      {4.5ex \@plus.2ex}% original 2.3ex \@plus .2ex
      {\normalfont\Large\bfseries\SS@sectfont}}
\makeatother

\sectionfont{\sectionrule{0ex}{0pt}{-1ex}{0.2pt}}

\begin{document}
\section*{Life}
\lipsum[1]
\end{document}

BTW: Current version of sectsty is not fully compatible with current LaTeX, because the definition of \underbar has changed. LaTeX defines it protected now, but the redefinition of sectsty is still not robust.

4
  • Thanks a lot for your answer! If sectsty is not robust, what would you suggest as an alternative package/tool? P.S.; Your first solution (i.e. before "But IMHO a better solution...") works, but I do not see any difference between your second solution (i.e. after "But IMHO a better solution...") and \usepackage{sectsty} \sectionfont{\sectionrule{0ex}{0pt}{-1ex}{0.2pt}}.....
    – Ommo
    Commented Mar 7 at 11:07
  • 1
    The first solution is only a hack with an invisible line of large depth. It cannot be used to decrease the distance.
    – cabohah
    Commented Mar 7 at 11:14
  • 1
    If you don't have a problem with the incompatibility (or the warning message) of sectsty, use it. You just should know, that sometimes you may need to use \protect\underbar instead of \underbar (e.g. inside the argument of \section or \caption). But if you think, this is a problem: There are a lot of alternatives. For example classes scrartcl or memoir or package titlesec provide features to change the formatting of sectioning commands.
    – cabohah
    Commented Mar 7 at 11:18
  • Great, thanks a lot !! :-)
    – Ommo
    Commented Mar 7 at 11:19
1

Use titlesec instead of sectsty.

\documentclass{article}
\usepackage{titlesec}

\usepackage{lipsum}

\titleformat{\section}
  {\normalfont\Large\bfseries}
  {\thesection}
  {1em}
  {}
  [{\titlerule[0.2pt]}]
\titlespacing*{\section}
  {0pt}
  {3.5ex plus 1ex minus 0.2ex}
  {4ex plus 0.2ex}% <-- standard is 2.3ex plus 0.2ex

\begin{document}

\section*{Life}

\lipsum[1]

\end{document}

I marked the argument where the spacing after the section title is defined. Look in the documentation of titlesec for the standard values (section 8.2).

enter image description here

1
  • Thanks a lot @egreg! I switched from sectsty to titlesec since, the latter looks easier to use to me.... :-) Should I then change the accepted answer? Btw, I upvoted your answer..
    – Ommo
    Commented Mar 8 at 9:35

You must log in to answer this question.

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