Text FormattingTable of Contents Formatting

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
samness25
Posts: 8
Joined: Sat Apr 03, 2010 10:29 pm

Table of Contents Formatting

Post by samness25 »

Hi,
I've been struggling with this for a couple months now. I'm creating a report and I've inserted

Code: Select all

\titleformat{\section}{\normalfont\Large\bfseries}{\thesection.0}{1em}{}
in order to make my section headers look like 1.0 Mission Definition, but when the toc compiles it comes up as 1 Mission Definition.

Does anyone know how to fix this? It would be greatly appreciated.

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Table of Contents Formatting

Post by gmedina »

Hi,

since you want this new format to affect not only the tiles but also the ToC entries (and the references, I assume) then you have to redefine the \thesection command; of course, this will also imply increasing the spacing between the number of the sections and their titles in the ToC and perhaps a redefinition of the commands corresponding to lower sectional units: \thesubsection, etc. (this last part is not clear from your post (and I didn't include it in my example code), since you didn't give any hint about the meaning of the suffix ".0" added to the counter for sections).

An example on how to proceed using article as the document class:

Code: Select all

\documentclass{article}
\usepackage{titlesec}

\renewcommand\thesection{\arabic{section}.0}

\titleformat{\section}{\normalfont\Large\bfseries}{\thesection}{1em}{}

\makeatletter
\renewcommand*\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{2em}%default: 1.5em
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}
\makeatother

\begin{document}
\tableofcontents
\section{Test section}

\end{document}
Remark: the redefinition of the \l@section command might be useless if your document class is not article. Please do include in your posts information about the document class you are using.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
samness25
Posts: 8
Joined: Sat Apr 03, 2010 10:29 pm

Re: Table of Contents Formatting

Post by samness25 »

I'm sorry, I should have explained everything.

I need the TOC to show

1.0 Mission Definition
1.1 Mission Segmet Summary
1.1.1 Phase I
etc...

The reason for the sections containing the .0 is merely because the english professor grading our technical report wants it that way....
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Table of Contents Formatting

Post by gmedina »

Again, which is the document class used? And, in "1.1.1 Phase I", what do the digits represent? I mean, do the leftmost "1" correspond to a sectional unit defined via \chapter, and do the middle "1" correspond from a \section command, etc?
1,1,2,3,5,8,13,21,34,55,89,144,233,...
samness25
Posts: 8
Joined: Sat Apr 03, 2010 10:29 pm

Re: Table of Contents Formatting

Post by samness25 »

Oh...sorry. I'm using an aritcle. The first 1 is the section number the second 1 is the subsection and the third 1 is the subsubsection.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Table of Contents Formatting

Post by gmedina »

Then simply use the default settings:

Code: Select all

\documentclass{article}

\begin{document}
\tableofcontents

\section{Mission Definition}
\subsection{Mission Segment Summary}
\subsubsection{Phase I}

\end{document}
Adding this line:

Code: Select all

\titleformat{\section}{\normalfont\Large\bfseries}{\thesection}{1em}{}
to your document won't have a visible effect since that line produces the default behaviour for the titles of the section in the article class.

If you are trying to define some special format for the title of sections, please describe it and we will suggest you some options.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
samness25
Posts: 8
Joined: Sat Apr 03, 2010 10:29 pm

Table of Contents Formatting

Post by samness25 »

So the article class would probably not be ideal for this then. All right. I've figured out how to change the section headers throughout the paper. What I can't get to update is the TOC for those section headers.

Code: Select all

\documentclass[11pt]{article}
\usepackage[a4paper]{geometry}
\geometry{top=1.0in, bottom=1.0in, left=1.5in, right=1.0in}

% Load packages for individual typesetting needs (e.g. special fonts)
\usepackage[centertags]{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[mathcal]{euscript}
\usepackage{array}
\usepackage{bm}
\usepackage{enumerate}
\usepackage{graphicx}

\usepackage{textcomp}
\usepackage[pdfborder={0 0 0},colorlinks=true,urlcolor=blue,linkcolor=blue,
            bookmarks=false,bookmarksnumbered=true,pdfstartview=FitH,
            breaklinks=true,pagebackref=true]{hyperref}
\usepackage{fancyhdr}
\usepackage{chngcntr}
\usepackage{setspace}
\usepackage{titlesec}
\usepackage{tocloft}

\pagestyle{fancy}


\pdfpagewidth 8.5in
\pdfpageheight 11in

\chead{\thepage\ of 10}
\cfoot{}
\lfoot{}
\rfoot{}

\titleformat{\section}{\normalfont\Large\bfseries}{\thesection.0}{1em}{}

\renewcommand{\labelitemii}{$\cdot$}
\renewcommand\contentsname{Table of Contents}
\renewcommand\listfigurename{List of Graphics}
\renewcommand\listtablename{List of Tables}
\renewcommand{\cftfigfont}{Figure }
\renewcommand{\cfttabfont}{Table }



\counterwithin{figure}{section}
\counterwithin{table}{section}

% Format page layout
\pdfpagewidth 8.5in
\pdfpageheight 11in

% Begin typesetting ...
\begin{document}
\input{title}

\rhead{Mission Document}
\lhead{Eagle Nest}

\pagebreak
\pagenumbering{roman}
\begin{doublespace}
\addtocontents{toc}{\protect\thispagestyle{fancy}}
\tableofcontents
\end{doublespace}

\pagebreak
\begin{doublespace}
\addtocontents{lot}{\protect\thispagestyle{fancy}}
\listoffigures
\listoftables
\end{doublespace}

\pagebreak
\pagenumbering{arabic}
\setcounter{page}{1}

\pagebreak[4]
\vspace{0.25in}
\section{Mission Definition}
\input{file.tex}

\end{document}
The file.tex is essentially just filled with the \subsection{} and \subsubsection{}. Should I be using a different class for my document or can I somehow force the TOC to match up to what I want the the section, subsection, and subsubsection to do?
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Table of Contents Formatting

Post by gmedina »

I am so sorry. IN my previous reply I forgot about the subsection counter starting in zero; for this, simply set the counter to -1 just before the first subsection of each section:

Code: Select all

\documentclass{article}

\begin{document}
\tableofcontents

\section{Test section}
\setcounter{subsection}{-1}
\subsection{Mission Definition}
\subsection{Mission Segment Summary}
\subsubsection{Phase I}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
samness25
Posts: 8
Joined: Sat Apr 03, 2010 10:29 pm

Re: Table of Contents Formatting

Post by samness25 »

Thank you for your help! :) You are quite amazing! You did in a few hours what I've been trying to do all semester. Thank you times a million.
Post Reply