TransWikia.com

Problem with the table of contents indentation/spacing

TeX - LaTeX Asked on June 26, 2021

I am writing a thesis using my institution’s template. My working code is as follows:

makeatletter
letmy@xfloat@xfloat
makeatother

documentclass[oneside,12pt,a4paper]{book}
%documentclass[12pt,a4paper]{book}
usepackage{UTMThesis, enumerate, amsfonts, longtable, qtree, etoolbox, array, rotating, pgf, tikz, tikz-cd, algorithm, csquotes}

makeatletter
def@xfloat#1[#2]{
    my@xfloat#1[#2]%
    defbaselinestretch{1}%
    @normalsize normalsize
}
makeatother

allowdisplaybreaks
usetikzlibrary{arrows, matrix, positioning, shapes, shapes.geometric, calc, intersections, decorations.pathreplacing}
newcommand{tikznode}[2]{relax
    ifmmode%
    tikz[remember picture,baseline=(#1.base),inner sep=0pt] node (#1) {$#2$};
    else
    tikz[remember picture,baseline=(#1.base),inner sep=0pt] node (#1) {#2};%
    fi}
letopenboxrelax
letiintrelax
letiiintrelax
letiiiintrelax
letidotsintrelax

newcommand*{qed}{hfillensuremath{square}}

%-------------------------------------------------------------
usepackage{cite}                       % change  cite from [1,2,3] to [1-3] etc for number system
makeatletter                           % change from
  renewcommand{@biblabel}[1]{#1.}     % [1] to 1. etc 
makeatother                            % in list of references
%-----------------------------------------------------------
  setlength{voffset}{-2.1cm}
  setlength{hoffset}{-.4cm}  
%--------------------------------------------------------
fontfiverm=cmr5 
%input{Pictex.tex} % using pictex
%---------------------------------------------------------
%pagestyle{plain}
%-------------------------------------------------------
  usepackage{fancyhdr}
  pagestyle{fancy}
  lhead{}
  chead{}
  rhead{}
  lfoot{}  
  cfoot{vspace{-.35cm}thepage}  % 
  rfoot{} 
  renewcommand{headrulewidth}{0pt}
%-------------------------------------------------------
begin{document}
frontmatter

chapter*{TABLE OF CONTENTS}

addcontentsline{toc}{section}{textbf{TABLE OF CONTENTS}}
contentsline{toc}{hspace{-1.3cm}phantom{textbf{CHAPTER}}hfill
    textbf{TITLE}hspace{1.1cm}}hfill {textbf{PAGE,,}}

{setlength{parskip}{.25cm}
    setlength{baselineskip}{.5cm}
    
    contentsline {chapter}{numberline {hspace {-.9cm}CHAPTER 1}hspace{1cm}THIS IS A VERY LONG LONG LONG LONG LONG LONG TITLE}{1}
    contentsline {section}{numberline {hspace {-.175in}1.1hspace {.12in}}Background Problem}{1}

backmatter
end{document}

that produces:

enter image description here

I want it to look like this one:

enter image description here

In other words, the spacing of the very long title has to be fixed. But I don’t know how. Please help.

One Answer

I must admit that I am not fond of your institution's template, whatever that might be. Try the following and see if it produces what you are after.

% thesistocprob.tex  SE 581226

makeatletter
letmy@xfloat@xfloat
makeatother

documentclass[oneside,12pt,a4paper]{book}
%documentclass[12pt,a4paper]{book}

usepackage{comment}

%usepackage{UTMThesis, enumerate, amsfonts, longtable, qtree, etoolbox, array, rotating, pgf, tikz, tikz-cd, algorithm, csquotes}

makeatletter
def@xfloat#1[#2]{
    my@xfloat#1[#2]%
    defbaselinestretch{1}%
    @normalsize normalsize
}
makeatother

begin{comment}
allowdisplaybreaks
usetikzlibrary{arrows, matrix, positioning, shapes, shapes.geometric, calc, intersections, decorations.pathreplacing}
newcommand{tikznode}[2]{relax
    ifmmode%
    tikz[remember picture,baseline=(#1.base),inner sep=0pt] node (#1) {$#2$};
    else
    tikz[remember picture,baseline=(#1.base),inner sep=0pt] node (#1) {#2};%
    fi}
letopenboxrelax
letiintrelax
letiiintrelax
letiiiintrelax
letidotsintrelax
end{comment}

newcommand*{qed}{hfillensuremath{square}}

%-------------------------------------------------------------
usepackage{cite}                       % change  cite from [1,2,3] to [1-3] etc for number system
makeatletter                           % change from
  renewcommand{@biblabel}[1]{#1.}     % [1] to 1. etc 
makeatother                            % in list of references
%-----------------------------------------------------------
  setlength{voffset}{-2.1cm}
  setlength{hoffset}{-.4cm}  
%--------------------------------------------------------
fontfiverm=cmr5 
%input{Pictex.tex} % using pictex
%---------------------------------------------------------
%pagestyle{plain}
%-------------------------------------------------------
  usepackage{fancyhdr}
  pagestyle{fancy}
  lhead{}
  chead{}
  rhead{}
  lfoot{}  
  cfoot{vspace{-.35cm}thepage}  % 
  rfoot{} 
  renewcommand{headrulewidth}{0pt}
%-------------------------------------------------------

usepackage{tocloft}
renewcommand{cftchappresnum}{textbf{CHAPTER }}
setlength{cftchapnumwidth}{3cm}
renewcommand{contentsname}{TABLE OF CONTENTS}

begin{document}
frontmatter

addtocontents{toc}{textbf{CHAPTER} hfill textbf{TITLE} hfill textbf{PAGE} par}
%chapter*{TABLE OF CONTENTS}
addcontentsline{toc}{section}{contentsname}
tableofcontents

begin{comment}
addcontentsline{toc}{section}{textbf{TABLE OF CONTENTS}}
contentsline{toc}{hspace{-1.3cm}phantom{textbf{CHAPTER}}hfill
    textbf{TITLE}hspace{1.1cm}}hfill {textbf{PAGE,,}}
end{comment}

setlength{parskip}{.25cm}
    setlength{baselineskip}{.5cm}
begin{comment}    
%    contentsline {chapter}{numberline {hspace {-.9cm}CHAPTER 1}hspace{1cm}THIS IS A VERY LONG LONG LONG LONG LONG LONG TITLE}{1}
    contentsline {chapter}{numberline {CHAPTER 1}hspace{2.5cm}THIS IS A VERY LONG LONG LONG LONG LONG LONG TITLE}{1}
    contentsline {section}{numberline {hspace {-.175in}1.1hspace {.12in}}Background Problem}{1}
end{comment}
mainmatter

chapter{THIS IS A VERY LONG LONG LONG LONG LONG LONG TITLE}
section{Background Problem}

backmatter
end{document}

It is a heavily revised version of your MWE but generally abides by the usual LaTeX style. It uses the regular LaTeX chapter, unlike your MWE, but uses the tocloft package to get the ToC as I think that your template wants.

Answered by Peter Wilson on June 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP