12

I'd like to use titlesec to make some modifications to section and chapter headings, but titleformat redefines the formatting entirely instead of just making modifications (e.g. if I just want to change the colour).

How do I get titlesec to modify instead of entirely redefine? Is this possible?

If not, how do I figure out what is the current formatting of \chapter, \section, etc. so that I can replicate it and make my modifications?


In response the request for a sample document, I guess the most basic is:

\documentclass{article}
\begin{document}
\section{Hello World}
Hello world!
\end{document}

However, I'm interested in a way to find out (e.g. to print out) the current formatting of \section instead of simply "knowing" it for a particular configuration.

3
  • Can you give a short complete document showing your setup (like document class and style files)? What you consider as the default depends on such things.
    – gernot
    Nov 15, 2016 at 15:24
  • You could switch to KOMAscript (in your case \documentclass{scrartcl}) and then use the \addtokomafont{}{} command to change single attributes of the fonts of e.g. headings. Nov 15, 2016 at 15:32
  • Check the documentation of titlesec, section 9.2. Standard Classes. Nov 15, 2016 at 15:33

3 Answers 3

8

For simple modifications such as the title colour, you can use the light version of \titleformat, but have to check in article.cls (or report, or book) what the values of the parameters are (fontsize, weight, shape).

Here is an example:

\documentclass[a4paper]{article}
\usepackage[svgnames]{xcolor}
\usepackage{titlesec}
\titleformat*{\section}{\color{IndianRed}\normalfont\bfseries\Large}

\begin{document}

\section{A short title}
This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph.

\end{document} 

enter image description here

28

The standard classes are defined as follows (copied from titlesec reference, section 8.2)

\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titleformat{\section}
{\normalfont\Large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\large\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}
\titleformat{\paragraph}[runin]
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titleformat{\subparagraph}[runin]
{\normalfont\normalsize\bfseries}{\thesubparagraph}{1em}{}
\titlespacing*{\chapter}     {0pt}{50pt}{40pt}
\titlespacing*{\section}     {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{\subsection}   {0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\paragraph}   {0pt}{3.25ex plus 1ex minus .2ex}{1em}
\titlespacing*{\subparagraph} {\parindent}{3.25ex plus 1ex minus .2ex}{1em}
0

Try that

\documentclass{scrartcl}
\usepackage{xcolor}
\addtokomafont{section}{\color{red}}
\begin{document}
\section{Hello World}
Hello world!
\end{document}

enter image description here

2
  • 2
    scrartcl does not know \chapter. Using the KOMA-Script command \RedeclareSectionCommand it is also possible to modify attributes like beforeskip, afterskip, indent. The default settings for these attributes can be found in the KOMA-Script documentation.
    – esdd
    Nov 15, 2016 at 15:53
  • 1
    Please test your answers before posting.
    – gernot
    Nov 15, 2016 at 16:13

You must log in to answer this question.

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