37

I want to place a long bold \hrule-type line under the \section to make it more distinctive. How can I do that?

lhhNJU
  • 545

1 Answers1

40

You can use the titlesec package; the optional argument for \titlerule allows you to control the rule "thickness":

\documentclass{article}
\usepackage{titlesec}

\titleformat{\section}
  {\normalfont\Large\bfseries}{\thesection}{1em}{}[{\titlerule[0.8pt]}]

\begin{document}

\section{Test Section}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • And for the width? Because default is \textwidth... – Aurelius May 03 '13 at 20:13
  • @FormlessCloud can you please expand your question a little? I don't understand what you mean. Do you want the line only to cover the title and not the whole text width? – Gonzalo Medina May 03 '13 at 20:23
  • Sure, for example, if I would a \titlerule that have the width of for example .5\textwidth how can I do this? Because if I type only \titlerule that command give me automatically a rule that fit the entire width of my page. In sinthesys I would to adjust the length (or I can call it width, how you prefer) of my line. – Aurelius May 03 '13 at 20:46
  • 1
    @FormlessCloud Ah, I see. In that case, instead of [{\titlerule[0.8pt]}] you can use something like [\vskip-10pt{\makebox[\linewidth][l]{\rule{0.5\textwidth}{0.8pt}}}] (adjusting the vertical skip, if necessary). Changing the settings for the \makebox you can also obtain lines wider than the \textwidth. – Gonzalo Medina May 03 '13 at 20:56
  • 1
    This does not work if one uses \usepackage{sectsty}. I use this package for setting the color of the section. Alternatively, just set \color{red} within the \titleformat command. – Martin Thoma Sep 11 '17 at 09:43
  • @GonzaloMedina How do I remove numbers in section? – Death Metal Jan 18 '24 at 16:03