Page LayoutUnderlining Section Titles

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
onidavin
Posts: 9
Joined: Thu Apr 29, 2010 11:12 pm

Underlining Section Titles

Post by onidavin »

Hello,

I'm trying to put an underline on a section title. The university's template uses the following section of code to change the headers, but also requires them to be underlined:

Code: Select all

\def\section{\@startsection {section}{1}{\z@}{-7ex }
    { 3.5ex }{\centering\large\bfseries\TitleHyphenation}}
Unfortunately, I don't have the know-how to turn that into a minimum working example (attempts to use it outside of its clo make it yell about spacefactor.

When I try to use underline, ul, or ulem, it shouts about being in horizontal mode. Attempts to use secsty and titlesec have been fruitless. Is there a simple way to accomplish underlining the section title?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Underlining Section Titles

Post by josephwright »

You would need to use \makeatletter to access the internal function here. However, you would be much better not hacking it yourself. Take a look at the sectsty and titlesec packages.
Joseph Wright
onidavin
Posts: 9
Joined: Thu Apr 29, 2010 11:12 pm

Re: Underlining Section Titles

Post by onidavin »

I've tried using titlesec, but it fusses about horizontal mode whenever a \section is called. Been trying to find out what that means. I'll see if I can work up a working example.
onidavin
Posts: 9
Joined: Thu Apr 29, 2010 11:12 pm

Underlining Section Titles

Post by onidavin »

Figured out a solution for it using titlesec -- had to make sure the titleformat was set to block.

Code: Select all

\titleformat{\section}[block]{\centering\large\bfseries}{\thetitle}{.5em}{}[\vspace{-2em}\rule{\titlewidth}{1pt}]
To make \titlewidth work, don't be like me -- remember to load the package with calcwidth!

Code: Select all

\usepackage[calcwidth]{titlesec}
Post Reply