8

a question about formatting section titles. In the article class, I want to format my section titles as follows:

  • Hide the section number in the title.
  • Use upper case.
  • Add a dashed title rule below the title (I have custom dashed lines defined elsewhere).

I have tried out a lot with the titlesec package already, but I don't get even near a solution.

\titleformat{\section}{\centering\large\titlerule}{\thesection}{0.5em}{}

This produces a titlerule above my title, but not below. I have tried various places for \titlerule, but I cannot find the correct one^^. Also, \MakeUppercase does not work on the titlename. The section numbers are visible. Can anyone help?

Best, a

1
  • hello, could you give us a MWE ?
    – flav
    Feb 11, 2016 at 9:58

2 Answers 2

16

Like so?

\documentclass{article}
\usepackage{titlesec}
\titleformat{\section}{\centering\large}{}{0em}{\MakeUppercase}[\titlerule]
\begin{document}
\section{This}
\end{document}

(Some hints were found in inline uppercase chapter title)


The general syntax of \titleformat is

\titleformat{<command>}[<shape>]{<format>}{<label>}{<sep>}{<before-code>}[<after-code>]
  • <command> is the sectioning command you want to modify, here \section.
  • <shape> determines the general placement of the heading, see page 3 in the manual for a list of options. This is an optional argument.
  • <format> holds general format switches for the text of the heading, here \centering\large.
  • <label>: This is where you place code that prints the number of the section (\thesection), and other related things, e.g. the word Chapter for chapters.
  • <sep> is the distance from the number to the title (I just changed this to 0em)
  • <before-code> is just that, code placed before the text of the title. \MakeUppercase takes an argument (i.e. \MakeUppercase{text}), but as I understand it titlesec is constructed so that the last macro used in <before-code> can take an argument, and you can use it as I have.

  • <after-code> as expected is placed after the title text. You wanted the rule after, so I added it here. This is also an optional argument, brackets ([]) typically denote optional arguments in LaTeX, while braces ({}) denote mandatory arguments. For that reason you cannot leave out the empty pair of braces.

4
  • Thank you, that worked so far, but could you help me a little further by explaining the logic behind placing those {} [], some of which are empty? I did read the titlesec documentation, but, well, I don't understand. Cheers, a
    – anne
    Feb 11, 2016 at 10:22
  • @anne I'll try adding some, though I'm hardly an expert on titlesec. Will update in a few minutes. Feb 11, 2016 at 10:23
  • @anne You know that there is a manual to the package, right? The syntax of the command is described in detail in the manual.
    – yo'
    Feb 11, 2016 at 10:43
  • @TorbjørnT. Thank you very much, very useful, I just needed a little more explanation than the manual offered. Got it!
    – anne
    Feb 11, 2016 at 10:48
0

thanks for your help. Just to sum up the lesson learned, I want to add an example of how I formatted the subsection headings with lines etc. The code is:

\titleformat{\section}{\centering\large}{}{0em}{\MakeUppercase}[\titlerule]
\titleformat{\subsection}[block]{\upperdots\\\large}{\thesubsection}{1.5em}{\MakeUppercase}[\basedots]

Note that (upper|base)dots are custom lines defined using the dashrule package. The result may not be perfect, but it looks ok for now: 1

1
  • 1
    Where is that \upperdots command comes from?
    – Qaher
    Oct 18, 2020 at 3:53

You must log in to answer this question.

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