LaTeX forum ⇒ Page LayoutCentering section titles in article class Topic is solved

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
User avatar
Cham
Posts: 858
Joined: Sat Apr 02, 2011 4:06 pm

Centering section titles in article class

Postby Cham » Tue Dec 19, 2017 6:51 pm

I'm wondering if it's possible to do the following. Here's a MWE showing a very important paper to be published somewhere (content is highly classified! ;) ). The section titles are horizontally centered with their number. I would like to center the title text itself, while the section number should have an offset to the left, keeping its constant space.
  1. \RequirePackage[l2tabu,orthodox]{nag}
  2. \documentclass[12pt,letterpaper,twoside]{article}
  3. \usepackage{microtype}
  4. \usepackage[total={6.5in,10in},left=1in,top=0.5in,includehead,includefoot]{geometry}
  5. \usepackage{sectsty}
  6. \sectionfont{\centering}
  7. \subsectionfont{\sffamily}
  8. \subsubsectionfont{\sffamily}
  9. \raggedbottom
  10. \usepackage{lipsum}
  11.  
  12. \begin{document}
  13.  
  14. \section{Some not so hilarious introduction}
  15. \lipsum[1-2]
  16.  
  17. \section{Fancy theory of absolutely everything}
  18. \lipsum[5-5]
  19.  
  20. \section{General crap analysis}
  21.  
  22. \subsection{Tables of useless data}
  23. \lipsum[1-2]
  24.  
  25. \subsection{Funky graphics}
  26. \lipsum[3-3]
  27.  
  28. \section{Painfull discussion and killer conclusion}
  29. \lipsum[4-4]
  30.  
  31. \end{document}


Is it possible to center the title text, while keeping the section number (which would be pushed a bit to the left)?

User avatar
Stefan Kottwitz
Site Admin
Posts: 8792
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Tue Dec 19, 2017 6:59 pm

With titlesec instead of sectsty:

  1. \usepackage{titlesec}
  2. \titleformat{\section}
  3. [block]{\normalfont\bfseries\sffamily\Large}{\rlap{\thesection}}{0em}
  4. {\hspace*{.05\textwidth}\begin{minipage}[t]{.9\textwidth}\centering}[\end{minipage}]


This centers the section title in a minipage, and keeps the number left aligned.

Stefan
Site admin

User avatar
Cham
Posts: 858
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Tue Dec 19, 2017 7:03 pm

That's not what I meant. The section number should stay at the same location, relative to its title. I mean same constant space at the left part of the title, not completely flushed to the left side.

Is there a way to do this while keeping the sectsty package?

User avatar
Stefan Kottwitz
Site Admin
Posts: 8792
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Tue Dec 19, 2017 8:58 pm

Well, extremely uncommon... I guess nobody implemented such an asymmetric feature. It's like centering plus shifting. Or centering plus adding the numbers to the left. It's asymmetric, especially when numbers are of different width, such as 1 vs. 8 vs. 10.

I would reconsider doing that or not, before hacking it together. ;)

Stefan
Site admin

User avatar
Cham
Posts: 858
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Tue Dec 19, 2017 9:40 pm

Well, I agree. But when I look globally at the full text, I find it a bit weird that the section titles aren't centered, because of their number (it's a bit aesthetically unpleasing). Maybe that's why the default article class put all the titles flushed to the left instead. Maybe adding a dot after the numbers would fix the aesthetical glitch.

User avatar
Cham
Posts: 858
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Tue Dec 19, 2017 10:27 pm

What do you think of adding a point after the number, using the secdot package in the code above ?
  1. \usepackage{secdot}

It looks good, but I have a doubt.

User avatar
Stefan Kottwitz
Site Admin
Posts: 8792
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Tue Dec 19, 2017 11:40 pm

I like the dot as a separator. "1 Introduction" looks like a bad "One Introduction" to me, while "1. Introduction" is clearly for me "First: Introduction".

I would use sans serif headings though:

\sectionfont{\sffamily\centering}

Serif bold big headings look fat to me, and remind me of stone age LaTeX. Specifically, serif section headings don't fit to sans serif subsection headings.

Also, I would not use left aligned subsection headings following centered section headings. If I would have centered headings, then no headings below them at all. And by the way, in some book styles it's considered to be bad if one heading follows another heading. Some prefer a bit intro text before the next sub heading comes.

Stefan
Site admin

User avatar
Cham
Posts: 858
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Wed Dec 20, 2017 1:12 am

I also feel that the default quad space is too large, between the number and its section/subsection title. These secdot options are working great, but I'm not sure this is good :
  1. \usepackage{secdot}
  2. \sectionpunct{section}{. ~}
  3. \sectionpunct{subsection}{ ~}

What would you use as an elegant space ?

EDIT : \enskip appears to be perfect !
  1. \sectionpunct{section}{.\enskip}
  2. \sectionpunct{subsection}{\enskip}


Return to “Page Layout”

Who is online

Users browsing this forum: No registered users and 4 guests