## LaTeX forum ⇒ Text Formatting ⇒ \addcontentsline is not aligned

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

Hello!

I added a chapter following this:

\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 (23.67 KiB) Viewed 285 times

Stefan Kottwitz
Posts: 8904
Joined: Mon Mar 10, 2008 9:44 pm
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

nipj
Posts: 10
Joined: Thu May 10, 2018 6:15 am

\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.

Stefan Kottwitz
Posts: 8904
Joined: Mon Mar 10, 2008 9:44 pm
All with dots, for example:

\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

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

nipj
Posts: 10
Joined: Thu May 10, 2018 6:15 am
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:

\usepackage{titletoc,titlesec}\titlecontents{section}[1.5em]   {\addvspace{1em}\bfseries}   {\contentslabel{2em}}   {\hspace*{-2.3em}}   {\hfill\contentspage}

any suggestions?

nipj
Posts: 10
Joined: Thu May 10, 2018 6:15 am
I realized that the problem is not "\chapter".

An easy but not sophisticated solution is using "\hspace{Xcm}". Adjusting "X" as you desire.

Stefan Kottwitz
Posts: 8904
Joined: Mon Mar 10, 2008 9:44 pm
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:

\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

nipj
Posts: 10
Joined: Thu May 10, 2018 6:15 am

\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.

### Who is online

Users browsing this forum: No registered users and 2 guests