Home > Tips and tricks [en] > New styles for some tango titles

New styles for some tango titles

An example of possible user intervention on the layout

Tuesday 16 July 2024, by Michel Bovani

All the versions of this article: [English] [français]

When it comes to structuring the documents generated, the tango class is relatively unchanged from standard classes. Tango has a PubliClass option which can take two values: article (default) or book. The principle adopted in tango is that a document designed for the article version can be compiled almost as it is with the PubliClass=book option. This has a very limited influence on sectioning commands.

  • The \part command is disabled when using the PubliClass=article option, but the truth is that very few people use this command in the article class.
  • The \chapter and \chapter* commands don’t exist in the article version, but there are \tgotitle and \tgotitle* commands that allow you to enter top-level titles in the article version.
  • In the book version, these commands also exist, but become aliases for the \chapter and \chapter* commands.

On the other hand, the style of the different title levels proposed by tango differs greatly from that found in standard classes. The aim of this article is to show how tango’s behavior can be modified, not to revert to the standard classes (in which case it would be sufficient not to use tango), but to obtain variants from the behavior predefined by the class.

An example of a specification for redefining certain title levels

We’re going to propose a modification to the style of chapter headings (command \chapter) and first-level paragraphs (command \section). Note that all code on this page can be copied and pasted. So we’re mainly interested in the book version.

Here’s what we want to achieve:

  • With regard to chapter titles, we want them to be composed against the right-hand margin, with the title first and then the chapter number (this is the symmetrical situation of what exists by default). We also want to do away with color: titles and chapter numbers will be composed in black, separated by a colored vertical fillet.
  • For first-level paragraph titles, it’s simpler: we simply want to dispense with capitals; the title will be composed in lower case, albeit in a slightly larger body than at present.

At the end of this article, you’ll find a downloadable example illustrating these specifications (french only).

The existing situation

The tango class uses the titlesec (Javier Bezos) package to define its titles. If you want to understand what follows, it’s essential to read the documentation for this package, or at least what concerns the \titleformat command, which one of the only two titlesec commands used by the casse tango document class. Of course, those in a hurry can skip to the end of the article, where a ready-to-compile example is available.

To see how these commands are used by the tango class, open the tango.cls class file and search for these commands. This file can be retrieved from [tango CTAN page>https://ctan.org/pkg/tango] or directly from your installation’s texmf (on texlive, see texmf-dist/tex/lualatex/tango).

Changing the command defining top-level paragraph titles

This is what we found in the tango.cls file

\titleformat{\section}{\color{ColorOne}\sffamily%
\addfontfeature{RawFeature=-onum}%
\fontseries{b}\selectfont}{\large}{\thesection}{1em}
{\uppercase}%

We don’t want capital letters, so we’ll leave the last argument blank. We want a larger body: we therefore replace \large with \Large. The \addfontfeature{RawFeature=-onum} command allows us to force the lining digits (see the fontspec package documentation) even if the user has requested lower-case digits: this makes sense with a capitalized title, but is no longer necessary if the title changes back to lower-case. Finally, the larger body already provides us with a good contrast in semi-bold, bold is exaggerated: we therefore replace \fontseries{b} by \fontseries{sb}. The rest remains unchanged, giving us:

\titleformat{\section}{\color{ColorOne}\sffamily%
\fontseries{sb}\selectfont\Large}{\thesection}{1em}{}%

Chapter title style modification

Chapter titles are essentially defined by :

\titleformat{name=\chapter}[block]
{\filright\color{ColorOne}%
\fontspec{\TgoChapterTitleFont}%
\addfontfeature{RawFeature=-onum}\huge}
{}{0em}{\TgoChapterBox}
%%%
\titleformat{name=\chapter,numberless}[block]%
{\filright\color{ColorOne}
\fontspec{\TgoChapterTitleFont}%
\addfontfeature{RawFeature=-onum}\huge}
{}{0em}{}

There are two calls to \titleformat as it’s necessary here to distinguish between the case of \chapter and \chapter* (for a block-type format, this is quite common). We can also see that two tango-defined commands are used:

  1. \TgoChapterTitleFont: this is the command used to define the font used for titles. The definition can be found at the very beginning of the class:
    newcommand\TgoChapterTitleFont{RobotoCondensedBold}
    Since we’re switching from color to black, we’ll limit the increase in contrast here too by dispensing with bold:
    \renewcommand\TgoChapterTitleFont{RobotoCondensed}
    But since this command is internal to tango, I think it’s good policy to define a new command and use it rather than redefine \TgoChapterTitleFont. Note that, traditionally, the survival of internal commands (with capital letters in their names) is not guaranteed over successive versions:
    \newcommand\mychapterfont{RobotoCondensed}
  2. \TgoChapterBox Here we use the last argument of \titleformat to improve the definition of the box containing the title — this is actually a (welcome) suggestion from the LaTeX Companion, Third Edition. This command is only used for the non-starred version of \chapter.

In practice, as our new version of the chapter heading style is a little more complicated than the old one, we’ll be using two commands such as \TgoChapterBox :

  • \mychapterbox associated with \chapter and
  • \mychapterboxstarred associated with \chapter*.

We’ll then have

\titleformat{name=\chapter}[block]
{\filleft\addfontfeature{RawFeature=-onum}\huge}
{}{0em}{\mychapterbox}
\titleformat{name=\chapter,numberless}[block]{\filleft%
\addfontfeature{RawFeature=-onum}\huge}%
{}{0em}{\mychapterboxstarred}

Here we see that the call to the title font has disappeared: it was necessary to relegate it to the \mychapterbox and \mychapterboxstarred commands (for reasons I still can’t explain).

Finally, here are the definitions of the last two commands:

\newcommand\mychapterboxstarred[1]{%
\sffamily\parbox{0.85\textwidth}
{\fontspec{\mychapterfont}\filleft#1}%
}%
\newcommand\mychapterbox[1]{%
\sffamily\parbox{0.65\textwidth}
{\fontspec{\mychapterfont}\filleft#1}%
\addfontfeature{RawFeature=-onum}
\fontseries{b}\selectfont\HUGE\hspace{15pt}%
{\color{ColorOne}\rule[-29pt]{3pt}{72pt}}\hspace{14pt}%
\raisebox{-11.5pt}{\thechapter}%
}%

This gives us the following complete example:

% !TEX TS-program = LuaLaTeX
\documentclass[english,ColorTheme=Red,PubliClass=book,
FontSize=11pt]{tango}
%
\titleformat{\section}{\color{ColorOne}\sffamily
\fontseries{sb}\selectfont\Large}{\thesection}{1em}{}%
%
\newcommand\mychapterfont{RobotoCondensed}

\newcommand\mychapterboxstarred[1]{%
\sffamily\parbox{0.85\textwidth}
{\fontspec{\mychapterfont}\filleft#1}%
}%
\newcommand\mychapterbox[1]{%
\sffamily\parbox{0.65\textwidth}
{\fontspec{\mychapterfont}\filleft#1}%
\addfontfeature{RawFeature=-onum}
\fontseries{b}\selectfont\HUGE\hspace{15pt}%
{\color{ColorOne}\rule[-29pt]{3pt}{72pt}}\hspace{14pt}%
\raisebox{-11.5pt}{\thechapter}%
}%
%
\titleformat{name=\chapter}[block]
{\filleft\addfontfeature{RawFeature=-onum}\huge}
{}{0em}{\mychapterbox}
\titleformat{name=\chapter,numberless}[block]{\filleft%
\addfontfeature{RawFeature=-onum}\huge}%
{}{0em}{\mychapterboxstarred}
%%%%
\begin{document}
\chapter{Chapter chapter chapter 
chapter chapter chapter}
\section{Section section section}
\subsection{Subsection subsection subsection}
\end{document}%