# How can I align the multiple line of chapter title with titletoc package?

I am currently doing my thesis. I use titletoc package to manage my TOC. I have a problem with the very long chapter title. I would like to have a new line that is aligned at the same as the first line of the chapter title.

This is my sample code.

\documentclass[fontsize=16pt,a4paper,oneside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

% Layout packages
\usepackage[top=25mm, bottom=20mm, left=25mm, right=20mm]{geometry}

%%% toc packages
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{lineno}
\def\firstindentlength{1cm}
\setcounter{tocdepth}{1}
\makeatletter
\renewcommand\tableofcontents{%
\chapter*{Contents}%
\begin{flushright}
\textbf{page}
\end{flushright}
% Hold current page value
\newcounter{tocitem}
\setcounter{tocitem}{0}
\modulolinenumbers[50]
\linenumbers[1]
\@starttoc{toc}%
\setcounter{tocitem}{0}
\clearpage
\cleardoublepage
}
\makeatother

\titlecontents{chapter}
[0mm]
{\stepcounter{tocitem}}
{\MakeUppercase\chaptername\hspace{1ex}\thecontentslabel\enspace}
{}
{\titlerule*[0.6pc]{.}\contentspage}

\titlecontents{section}
[0mm]
{\stepcounter{tocitem}}
{\hspace{\firstindentlength}\thecontentslabel.\hspace{2mm}}
{\hspace{\firstindentlength}\thecontentslabel\hspace{2mm}}
{\titlerule*[0.6pc]{.}\contentspage}

\begin{document}

\thispagestyle{empty}

\tableofcontents
\newpage

\chapter{new chapter1}
\newpage
\chapter{This is a handbook about TeX, a new typesetting system intended for the creation of beautiful books and especially for books that contain a lot of mathematics.}
\newpage

\end{document}


This is my result.

The new line of the chapter title should be aligned at the same as the first title line. The new TOC should be like this.

Use the \contentslabel command, which has a mandatory argument – the width used by the label, and an optional argument for the label formatting, and change accordingly the left margin for chapter in toc (1st optional argument of \titlecontents). I also added some vertical padding between chapters in the toc with the last optional argument of \titlecontents:

\documentclass[fontsize=16pt,a4paper,oneside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

% Layout packages
\usepackage[top=25mm, bottom=20mm, left=25mm, right=20mm]{geometry}

%%% toc packages
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{lineno}

\setcounter{tocdepth}{1}
\makeatletter
\renewcommand\tableofcontents{%
\chapter*{Contents}%
\begin{flushright}
\textbf{page}
\end{flushright}
% Hold current page value
\newcounter{tocitem}
\setcounter{tocitem}{0}
\modulolinenumbers[50]
\linenumbers[1]
\@starttoc{toc}%
\setcounter{tocitem}{0}
\clearpage
\cleardoublepage
}
\makeatother
\titlecontents{chapter}
[0cm]
{\stepcounter{tocitem}}
{\contentspush{CHAP}TER\hspace{1ex}\thecontentslabel\enspace}
{}
{\titlerule*[0.6pc]{.}\contentspage}[\medskip]

\titlecontents{section}
[2.88em]
{\stepcounter{tocitem}}
{\thecontentslabel.\hspace{2mm}}
{\thecontentslabel\hspace{2mm}}
{\titlerule*[0.6pc]{.}\contentspage}

\begin{document}

\thispagestyle{empty}

\tableofcontents
\newpage

\chapter{New chapter1}
\newpage
\chapter{This is a handbook about TeX, a new typesetting system intended for the creation of beautiful books and especially for books that contain a lot of mathematics.}

\section{Hello! This is a section}
\newpage

\end{document}


• Thank you, @Bernard for your answer. I misunderstanding about my thesis format. It's my bad. I am so sorry. I have edited my sample code. Dec 23 '20 at 17:14
• @PisitNakjai: You don't have to use \firstindentlength inside \titlecontents{section}{.... Use the first optional argument to set the margin w.r.t. the tex margin to the same value as for chapters. Please se if my updated answer is what you want. Dec 23 '20 at 17:46
• The command "\def\firstindentlength{1cm}" has added in my code. Dec 23 '20 at 18:09
• It seems I misunderstood what you want. I'll update my answer in a moment. Dec 23 '20 at 18:27
• Please see if it OK now. B.t.w., if your latex version is comparatively recent, you don't have to load inputenc`: utf8 has been the default for more than two years. Dec 23 '20 at 18:40

This is the format that I want. The sample code has been edited.