Text FormattingTroubles with subsubsection styling

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Troubles with subsubsection styling

Post by Cham »

I'm having a few problems with this MWE code. I would like to customize the subsubsection styling only, so I used the titlesec and tocloft packages. Maybe there's a better and simpler way to customize the subsubsection in both the main text and in the ToC ? I want it to be displayed in bold sans-serif font.

The problem is that by adding the titlesec and tocloft commands, the first intro text has a garbled title, and the ToC is put on the same page, while it should stay on the next page.

The code below (with titlesec and tocloft turned OFF) gives a perfect display. Turning ON the commands gives the issues. How to fix these ?

Code: Select all

\documentclass[11pt,twoside]{book}
\usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
%\usepackage[pagestyles,medium]{titlesec}
%\titleformat*{\subsubsection}{\bfseries\sffamily}
%\usepackage{tocloft}
%\renewcommand{\cftsubsubsecfont}{\normalfont\sffamily\footnotesize}
\usepackage{hyperref}

\begin{document}

\frontmatter

\begin{titlepage}
	\centering
	\vfill {\Huge Some big title !} \vfill
	\vfill Version 1.0
\end{titlepage}

\thispagestyle{empty}
{\centering\subsubsection*{Title of this small part}}

\noindent
Some simple text about the title page.

\pagestyle{plain}
\setcounter{tocdepth}{3}
\tableofcontents
\mainmatter

\chapter{Chapter title}
\section{Section title}
\subsection{Notion de variable}
Blabla
\subsection{Subsection title}
Blablabla
\subsubsection{Subsubsection title}
Blablabla
\subsection{Subsection title}
Blablabla
\subsubsection{Subsubsection title}
Blablabla
\subsubsection{Subsubsection title}
Blablabla
\subsection{Subsection Title}
Blablabla
\subsubsection{Subsubsection title}
Blablabla
\subsubsection{Subsubsection title}
Blablabla
\subsubsection{Subsubsection title}
Blablabla
\subsection{Subsection Title}
Blablabla
\subsection{Subsection Title}
Blablabla

\end{document}
Here's a preview of both issues :
wrong.jpg
wrong.jpg (46.69 KiB) Viewed 6513 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Troubles with subsubsection styling

Post by Johannes_B »

If you really just want to change the appearance to be sans serif and centered, i would use patching.

Code: Select all

\documentclass[11pt,twoside]{book}
    \usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
    \usepackage{etoolbox}
    \patchcmd{\subsubsection}{\bfseries}{\centering\bfseries\sffamily}{}{}
    \usepackage[titles]{tocloft}
    \renewcommand{\cftsubsubsecfont}{\normalfont\sffamily\footnotesize}
    \usepackage{hyperref}
     
    \begin{document}
     
    \frontmatter
     
    \begin{titlepage}
    	\centering
    	\vfill {\Huge Some big title !} \vfill
    	\vfill Version 1.0
    \end{titlepage}
     
    \thispagestyle{empty}
    \subsubsection*{Title of this small part}
     
    \noindent
    Some simple text about the title page.
     
    \pagestyle{plain}
    \setcounter{tocdepth}{3}
    \tableofcontents
    \mainmatter
     
    \chapter{Chapter title}
    \section{Section title}
    \subsection{Notion de variable}
    Blabla
    \subsection{Subsection title}
    Blablabla
    \subsubsection{Subsubsection title}
    Blablabla
    \subsection{Subsection title}
    Blablabla
    \subsubsection{Subsubsection title}
    Blablabla
    \subsubsection{Subsubsection title}
    Blablabla
    \subsection{Subsection Title}
    Blablabla
    \subsubsection{Subsubsection title}
    Blablabla
    \subsubsection{Subsubsection title}
    Blablabla
    \subsubsection{Subsubsection title}
    Blablabla
    \subsection{Subsection Title}
    Blablabla
    \subsection{Subsection Title}
    Blablabla
     
    \end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Troubles with subsubsection styling

Post by Cham »

It's working nicely ! But I don't want the subsubsection titles to be centered, except the first introduction one (which isn't really a "subsubsection").

What would be the best way of defining a small introduction title (to describe a picture on the title page) ?

I'm also getting an error message in my full document :
LaTeX Error: Command \c@lofdepth already defined.
Or name \end... illegal, see p.192 of the manual.

See the LaTeX manual or LaTeX Companion for explanation.
...
l.607 \newcounter{lofdepth}
\setcounter{lofdepth}{1}
The tocloft package is triggering this.

What is happening here?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Troubles with subsubsection styling

Post by Johannes_B »

You might have a package like subfig loaded. Or subcaption.

Concerning the not really a subsection heading: Do it manually. If you know what and why, you do not need semantic markup. Especially if you are misusing it.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Troubles with subsubsection styling

Post by Cham »

Yes, I do have subfig loaded. How to fix this ToC depth problem ?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Troubles with subsubsection styling

Post by Johannes_B »

Option subfigure
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Troubles with subsubsection styling

Post by Cham »

Johannes_B wrote:Option subfigure
What do you mean? Please, could you be more specific?
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Troubles with subsubsection styling

Post by Cham »

Ah! Ok, this appears to fix the issue :

Code: Select all

\usepackage[titles,subfigure]{tocloft}
Post Reply