Text Formatting\addcontentsline is not aligned

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
nipj
Posts: 17
Joined: Thu May 10, 2018 6:15 am

\addcontentsline is not aligned

Post by nipj »

Hello!

I added a chapter following this:

Code: Select all

\chapter*{\begin{center}
	     {\begin{spacing}{1.2}
	     {\fontsize{14}{104}\selectfont Chapter 1: bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 		 
             bla bla bla bla bla bla bla bla 
	     }
	     \end{spacing}
	     }
\end{center}} \vskip -0.0cm \vspace*{-1.5cm}
\stepcounter{chapter}
\addcontentsline{toc}{chapter}{Chapter 1: bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla}
\input{chapters/chapter01}

My problem is why the heading "Chapter 1: bla bla ....." is not completely aligned to the left? (see the attached image).
Also, I would like to know how to add consecutive points as in the the sections.
Attachments
sdddd.jpg
sdddd.jpg (23.67 KiB) Viewed 7697 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

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

\addcontentsline is not aligned

Post by Stefan Kottwitz »

Hi!

The appearance of chapter headings depends on the document class. Which one are you using?

All those formatting commands within \chapter*{} are very against LaTeX's philosophy. As argument, there should be just text. The chapter heading formatting should be customized globally, not in each heading itself.

Stefan
LaTeX.org admin
nipj
Posts: 17
Joined: Thu May 10, 2018 6:15 am

\addcontentsline is not aligned

Post by nipj »

Thanks for answering.

Code: Select all

\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}
Oh I see. But, How do I stablish a customized global format for headings? At least where the headings are left-aligned.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

\addcontentsline is not aligned

Post by Stefan Kottwitz »

All with dots, for example:

Code: Select all

\usepackage{tocstyle}
\usetocstyle{allwithdot}
Documentation:

tocstyle
titlesec

The titlesec package is for customizing chapter and section headings. In the appenix of the manual, there are examples how to use it.

Stefan
LaTeX.org admin
nipj
Posts: 17
Joined: Thu May 10, 2018 6:15 am

\addcontentsline is not aligned

Post by nipj »

Thanks. I'll give it a try.
nipj
Posts: 17
Joined: Thu May 10, 2018 6:15 am

\addcontentsline is not aligned

Post by nipj »

In the page 13 of "titlesec.pdf", I think i found what i need, but i cannot make it work.

I also found and tried this code without success:

Code: Select all

\usepackage{titletoc,titlesec}
\titlecontents{section}[1.5em]
   {\addvspace{1em}\bfseries}
   {\contentslabel{2em}}
   {\hspace*{-2.3em}}
   {\hfill\contentspage}
any suggestions?
nipj
Posts: 17
Joined: Thu May 10, 2018 6:15 am

\addcontentsline is not aligned

Post by nipj »

I realized that the problem is not "\chapter".
The problem appears when adding a chapter with "\addcontentsline".

An easy but not sophisticated solution is using "\hspace{Xcm}". Adjusting "X" as you desire.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

\addcontentsline is not aligned

Post by Stefan Kottwitz »

Hi,

that way

\addcontentsline{toc}{chapter}{Chapter 1: ...}

is not so good anyway. For example, in LaTeX one should never need manual numbering. If one has such manual numbers in spots over the document, it's hard to insert another chapter (or other elements), in general.

One could change to:

Code: Select all

\stepcounter{chapter}
\addcontentsline{toc}{subsubsection}{\chaptername\ \thechapter: ...}
But the whole thing is unusual: \chapter is for numbered chapters, \chapter* for unnumbered chapters, \addtocontents is for putting those unnumbered chapters to the table of contents. But it's originally numbered. You make a workaround for another reason. I think you made it because of the formatting commands in the header text. But it's not needed anymore if you do correct global formatting via titlesec. If you like, you can post a new minimal working example with the updated code and we take a look if it can be fixed.

Stefan
LaTeX.org admin
nipj
Posts: 17
Joined: Thu May 10, 2018 6:15 am

\addcontentsline is not aligned

Post by nipj »

I literally just added "\hspace":

Code: Select all

\addcontentsline{toc}{chapter}{1 \hspace{0.00cm} CHAPTER I: bla bla bla bla bla bla bla la bla bla bla bla la bla bla bla bla }
Since I have no idea on how to use "titlesec" or "titletoc" to make a global customized format for headings (chapter headings), it would be awesome to see a working example.
Post Reply