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

\addcontentsline is not aligned

Postby nipj » Tue May 15, 2018 3:55 am

Hello!

I added a chapter following this:

  1. \chapter*{\begin{center}
  2. {\begin{spacing}{1.2}
  3. {\fontsize{14}{104}\selectfont Chapter 1: bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
  4. bla bla bla bla bla bla bla bla
  5. }
  6. \end{spacing}
  7. }
  8. \end{center}} \vskip -0.0cm \vspace*{-1.5cm}
  9. \stepcounter{chapter}
  10. \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}
  11. \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 285 times

User avatar
Stefan Kottwitz
Site Admin
Posts: 8904
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Tue May 15, 2018 9:39 am

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
Site admin

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

Postby nipj » Wed May 16, 2018 2:01 am

Thanks for answering.

  1. \documentclass[12pt]{report}
  2. \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: 8904
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Wed May 16, 2018 7:32 am

All with dots, for example:

  1. \usepackage{tocstyle}
  2. \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
Site admin

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

Postby nipj » Thu May 17, 2018 3:33 am

Thanks. I'll give it a try.

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

Postby nipj » Thu May 17, 2018 5:08 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:

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


any suggestions?

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

Postby nipj » Thu May 17, 2018 6:49 am

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

Postby Stefan Kottwitz » Thu May 17, 2018 11:08 am

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:

  1. \stepcounter{chapter}
  2. \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
Site admin

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

Postby nipj » Fri May 18, 2018 4:55 am

I literally just added "\hspace":

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


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 2 guests