2

with the following code

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{titletoc}

\titlecontents{chapter}
[0em]
{\vspace*{\baselineskip}}
{\mdseries \contentslabel[\thecontentspage] {0mm}  \hspace*{1.4em}  \chaptername 
\,\,\thecontentslabel \\
\hspace*{2em} \itshape    \vspace*{0.3\baselineskip}}
{\mdseries   \thecontentspage \hspace*{1.2em}   \itshape}
{}
[]

\titlecontents*{section}
[0em]
{}
{\footnotesize \thecontentslabel~}
{}
{\footnotesize,~\thecontentspage}
[~--\ ]
[]

\begin{document}

\tableofcontents

\chapter{Events and Probability}
\section{Composite Events}
\section{Composite Events}
\section{An Application of Composite Events}
\section{Probability}
\section{The Probability of an Unknown Constant}
\section{A Confirmation}

\setcounter{page}{277}

\chapter*{Conclusion}
\addcontentsline{toc}{chapter}{Conclusion}

\end{document}

how can I align the left left margin of sections titles with the chapter title? I'm able to line up with an eye, but obviously it's a very bad idea... thanx

PS

Now I realize another problem. The starred chapter is not aligned with the other titles. why? enter image description here

PS2

i add an image of that I'd like to obtain

enter image description here

PS 3 With this complete code

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{newpxtext,newpxmath}
\useosf
\usepackage{microtype}
\usepackage{titletoc}

\usepackage[margin=3cm,heightrounded]{geometry}
\usepackage{showframe}

% book -- titletoc patch: https://tex.stackexchange.com/a/454553/134574
\usepackage{etoolbox}
\makeatletter
\patchcmd\@part
  {\thepart}
  {\protect\numberline{\thepart}}
  {}{\FAIL}
\makeatother

\makeatletter

\titlecontents{part}
  [0em]
  {\addvspace{1.5pc}\filcenter}
  {\large\partname~\thecontentslabel\endgraf\bfseries}
  {\large}
  {} % without page number
  [\addvspace{.5pc}]

\titlecontents{chapter}
  [0em]
  {\vspace*{\baselineskip}}
  {\mdseries
   \llap{\hb@xt@\@pnumwidth{\hfil\thecontentspage}\quad}\chaptername~\thecontentslabel\\
   \vspace*{0.3\baselineskip}%
   \itshape
  }
  {\mdseries
   \llap{\hb@xt@\@pnumwidth{\hfil\thecontentspage}\quad}%
   \itshape
  }
  {}
  []

\titlecontents*{section}
  [0em]
  {}
  {\footnotesize \thecontentslabel~}
  {}
  {\footnotesize,~\thecontentspage}
  [~--~]
  []

\begin{document}


\renewcommand*\contentsname{\hfill\mdseries\huge Indice}
\tableofcontents

\part{Setting up of a Business}

\chapter{Events and Probability}
\section{Composite Events}
\section{Composite Events}
\section{An Application of Composite Events}
\section{Probability}
\section{The Probability of an Unknown Constant}
\section{A Confirmation}

\chapter*{Conclusion}
\addcontentsline{toc}{chapter}{Conclusion}

\clearpage

\chapter{Events and Probability}
\section{Composite Events}
\section{Composite Events}
\section{An Application of Composite Events}
\section{Probability}
\section{The Probability of an Unknown Constant}
\section{A Confirmation}

\setcounter{page}{277}

\chapter*{Conclusion}
\addcontentsline{toc}{chapter}{Conclusion}

\end{document}

the page margins and the index margins are different. Why? Index is narrower as page.... You can see it in the picture under enter image description here

user41063
  • 1,967
  • If I add a starred chapter to the ToC with \addcontentsline{toc}{chapter}{Conclusion} they look aligned... Can you please expand your MWE so that it shows the misalignment? – Phelype Oleinik Oct 16 '18 at 13:07
  • I updated code, recompiled. same problem, as in the figure above – user41063 Oct 16 '18 at 13:20

1 Answers1

2

You had some spurious spaces in your \titlecontents definition, for example:

\hspace*{1.4em} \chaptername

produces a larger space than

\hspace*{1.4em}\chaptername

You also was using \contentslabel incorrectly. This macro reserves some space to the left of the margin for the label. But form your picture I assumed you didn't want it, so I removed and used a plain \hbox with \llap. I also added the \part formatting from your other question:

enter image description here

Updated code:

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{titletoc}

% book -- titletoc patch: https://tex.stackexchange.com/a/454553/134574
\usepackage{etoolbox}
\makeatletter
\patchcmd\@part
  {\thepart}
  {\protect\numberline{\thepart}}
  {}{\FAIL}
\makeatother

\usepackage{tikz}

\makeatletter

\contentsmargin[-1.55em]{1.55em}

\titlecontents{part}
  [0em]
  {\addvspace{1.5pc}\filcenter}
  {\large\partname~\thecontentslabel\endgraf\bfseries}
  {\large}
  {} % without page number
  [\addvspace{.5pc}]

\titlecontents{chapter}
  [0em]
  {\vspace*{\baselineskip}}
  {\mdseries
   \llap{\hb@xt@\@pnumwidth{\hfil\thecontentspage}\quad}\chaptername~\thecontentslabel\\
   \vspace*{0.3\baselineskip}%
   \itshape
  }
  {\mdseries
   \llap{\hb@xt@\@pnumwidth{\hfil\thecontentspage}\quad}%
   \itshape
  }
  {}
  []

\titlecontents*{section}
  [0em]
  {}
  {\footnotesize \thecontentslabel~}
  {}
  {\footnotesize,~\thecontentspage}
  [~--~]
  []

\begin{document}

\tableofcontents

\part{Setting up of a Business}

\addcontentsline{toc}{chapter}{\protect\tikz[remember picture, overlay]\protect\draw[red,ultra thick] (0,0) -- (0,-7);}

\chapter{Events and Probability}
\section{Composite Events}
\section{Composite Events}
\section{An Application of Composite Events}
\section{Probability}
\section{The Probability of an Unknown Constant}
\section{A Confirmation}

\chapter*{Conclusion}
\addcontentsline{toc}{chapter}{Conclusion}

\clearpage

\chapter{Events and Probability}
\section{Composite Events}
\section{Composite Events}
\section{An Application of Composite Events}
\section{Probability}
\section{The Probability of an Unknown Constant}
\section{A Confirmation}

\setcounter{page}{277}

\chapter*{Conclusion}
\addcontentsline{toc}{chapter}{Conclusion}

\end{document}