TransWikia.com

How to change style of section titles

TeX - LaTeX Asked by Forklift17 on August 19, 2021

As a follow-up question to this question, how can I get "Subsection title" below into italics and not bold? I do not want to change "Subsection title" in the table of contents, nor do I want to change the font of "Subsection text."

documentclass{article}
usepackage{tocloft}
usepackage{titlesec}

begin{document}
tableofcontents

section{Section title}
Section text

subsection{Subsection title}
Subsection text

end{document}

I have read through the titlesec documentation, but I am struggling to decipher it.

One Answer

I suggest you run either

usepackage{sectsty}
subsectionfont{mdseriesitshape}

or (as already suggested by @Bernard)

usepackage{titlesec}
titleformat*{subsection}{largeitshapemdseries

in the preamble. Note: load either titleformat or secsty, but not both.

Both methods shown above will render the subsection header text and the associated subsection number in italics. If you want the subsection number to be rendered in an upright font shape, I suggest you also include the following code in the preamble:

makeatletter % See pp. 26f. of 'The LaTeX Companion,' 2nd ed.
def@seccntformat#1{@ifundefined{#1@cntformat}%
   {csname the#1endcsnamequad}%    default appearance
   {csname #1@cntformatendcsname}}% enable individual control
newcommandsubsection@cntformat{upshapethesubsectionquad} % subsection level 
makeatother

A full MWE and its output:

enter image description here

documentclass{article}
usepackage{tocloft}

usepackage{sectsty}
subsectionfont{mdseriesitshape}

% See pp. 26f. of 'The LaTeX Companion,' 2nd ed. 
makeatletter
def@seccntformat#1{@ifundefined{#1@cntformat}%
   {csname the#1endcsnamequad}%    default appearance
   {csname #1@cntformatendcsname}}% enable individual control
newcommandsubsection@cntformat{upshapethesubsectionquad} % subsection level 
makeatother

begin{document}
tableofcontents

section{Section title}
Section text

subsection{Subsection title}
Subsection text
end{document}

Answered by Mico on August 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP