0

I'm trying to write a report in LaTeX. First, I tried to align the table of contents to the left. Then I changed my mind but I couldn't restore. I would like to make some distance between the Sections and Subsections such as 4cm (not aling to left). I would like to change table of contents as below figure.

enter image description here

Could you please help me?

\documentclass[12pt]{report}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=25mm,bmargin=25mm,lmargin=30mm,rmargin=25mm}
\pagestyle{plain}
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}
\usepackage[active]{srcltx}
\usepackage{xcolor}
\usepackage{tocbibind}

\usepackage{lipsum}
\usepackage{float}
\usepackage{siunitx}
\usepackage{fixltx2e}
\usepackage{mathdots}
\usepackage{stmaryrd}
\usepackage{stackrel}
\usepackage{setspace}
\PassOptionsToPackage{version=3}{mhchem}
\usepackage{caption}
\usepackage{times}
\usepackage[titletoc]{appendix}
\usepackage[square, numbers, comma, sort&compress]{natbib}

\usepackage[round]{natbib}
\usepackage[unicode=true,pdfusetitle, bookmarks=t`enter code here`rue,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=1, breaklinks=false,pdfborder={0 0 0},backref=false,colorlinks=false] {hyperref}


\makeatletter
\renewcommand{\baselinestretch}{1.5}
\renewcommand{\cfttoctitlefont}{\hfill\Huge\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill}
\renewcommand{\cftloftitlefont}{\hfill\Huge\bfseries}
\renewcommand{\cftafterloftitle}{\hfill}
\renewcommand{\cftlottitlefont}{\hfill\Huge\bfseries}
\renewcommand{\cftafterlottitle}{\hfill}

\renewcommand\cftchapdotsep{\cftdotsep}


\renewcommand\thechapter{\arabic{chapter}}
\renewcommand\thesection{\arabic{chapter}.\arabic{section}}
\providecolor{lyxadded}{rgb}{0,0,1}
\providecolor{lyxdeleted}{rgb}{1,0,0}
\DeclareRobustCommand{\lyxadded}[3]{{\texorpdfstring{\color{lyxadded}{}}{}#3}}
\DeclareRobustCommand{\lyxdeleted}[3]{{\texorpdfstring{\color{lyxdeleted}\sout{#3}}{}}}
\usepackage{tocloft}

\usepackage{minitoc}
\usepackage[tocfullflat]{tocstyle}

\usepackage[labelfont=bf]{caption} 
\renewcommand{\@pnumwidth}{0.9em}
\usepackage{feyn}

 \usepackage[center]{titlesec}
 \titleformat{\chapter}[block]
   {\normalfont\fontsize{14pt}{12pt}\selectfont\bfseries
\centering} {\MakeUppercase \thechapter.}{1pt}{\MakeUppercase}
 \titleformat{\section}
   {\normalfont\fontsize{12pt}{14pt}\selectfont\bfseries}{\thesection .}{1pt}{}
 \titleformat{\subsection}
   {\normalfont\fontsize{12pt}{14pt}\selectfont\bfseries}{\thesubsection .}{1pt}{}
     \titleformat{\subsubsection}
   {\normalfont\fontsize{12pt}{14pt}\selectfont\bfseries}{\thesubsubsection .}{1pt}{}
 \titlespacing*{\chapter} {0pt}{12pt}{0.3ex plus .2ex}
 \titlespacing*{\section} {0pt}{12pt}{0.3ex plus .2ex}
 \titlespacing*{\subsection}{0pt}{12pt}{0.3ex plus .2ex}
\titlespacing*{\subsubsection}{0pt}{12pt}{0.3ex plus .2ex}


\begin{document}

\clearpage
\thispagestyle{plain}

\renewcommand{\cfttoctitlefont}{\large\hfil\textbf}
\pagenumbering{roman} \setcounter{page}{5}
\def\contentsname{CONTENTS}


\setlength{\cftsecindent}{0em}  
\setlength{\cftsubsecindent}{25em} 
\setlength{\cftsubsubsecindent}{25em} 
\setlength{\cftbeforechapskip}{0em}
\renewcommand{\cftdot}{.}
\renewcommand{\cftdotsep}{0.1}
\setlength{\cftchapnumwidth}{1.0em}
\setlength{\cftsecnumwidth}{1.7em}
\setlength{\cftsubsecnumwidth}{2.4em}
\setlength{\cftsubsubsecnumwidth}{2.8em}
\renewcommand{\cftchapleader}{\cftdotfill{\cftsecdotsep}}
\renewcommand{\cftchapfont}{\rmfamily\mdseries}
\renewcommand{\cftchappagefont}{\normalfont}
\renewcommand{\cftchapaftersnum}{.}
\renewcommand{\cftsecaftersnum}{.}
\renewcommand{\cftsubsecaftersnum}{.}
\renewcommand{\cftsubsubsecaftersnum}{.}

\newpage
\tableofcontents

\clearpage
\thispagestyle{plain}
\renewcommand{\cfttoctitlefont}{\large\hfil\textbf}
\pagenumbering{arabic} \setcounter{page}{1}

\addcontentsline{toc}{chapter}{Contents}



\chapter{A}
\section{Introduction}
\subsection{a}
\end{document}
  • Your example is far away from minimal and does not compile for me. Please reduce as much as you can. If you delete package by package, line by line, you will find the culprit part quickly. – LaRiFaRi Aug 18 '15 at 6:37
  • 1
    Some notes: Do not load color as you load the newer xcolor. Do not load packages twice (e.g. caption, amsmath, natbib...). Load babel with a language (e.g. \usepackage[english]{babel}. Use siunitx and not units. Load hyperref last (valid for most cases). report does not define a \mainmatter. \makeatletter\makeatother is just needed around parts with @. Do not surround too much with it. And in general. Do not load packages and options which you do not use and do not know. If they are missing later, you can add them again. – LaRiFaRi Aug 18 '15 at 6:45
  • Thanks for your comment @LaRiFaRi. By the way, Do you know the exact code for arranging the distance in table of contents ? – jenny Aug 18 '15 at 6:50
  • Please clarify what you want and minimize your code. The title of "Contents" can be restored to be in the middle by deleting \renewcommand{\cftaftertoctitle}{\hfill}. – LaRiFaRi Aug 18 '15 at 6:57
  • 1
    When I remove \usepackage[tocfullflat]{tocstyle} and change \setlength{\cftsecindent}{2em} \setlength{\cftsubsecindent}{3em} \setlength{\cftsubsubsecindent}{4em} I guess it works ! Thanks for all your help @LaRiFaRi – jenny Aug 18 '15 at 8:25
1

Remove the tocfullflat option from the package tocstyle.

% arara: pdflatex
% arara: pdflatex

\documentclass[12pt, a4paper]{report}
\usepackage{geometry}
\geometry{verbose,tmargin=25mm,bmargin=25mm,lmargin=30mm,rmargin=25mm}
\setlength{\parskip}{\medskipamount}
\usepackage{tocloft}
\usepackage{times}
\renewcommand{\baselinestretch}{1.5}
%\renewcommand{\cftaftertoctitle}{\hfill} % if you want this title centred, this has to go away
\usepackage{minitoc}
\usepackage{tocstyle} % removed the flat toc option here
\usepackage{titlesec}
\titleformat{\chapter}[block]
{\normalfont\fontsize{14pt}{12pt}\selectfont\bfseries
    \centering} {\MakeUppercase \thechapter.}{1pt}{\MakeUppercase}
\titleformat{\section}
{\normalfont\fontsize{12pt}{14pt}\selectfont\bfseries}{\thesection .}{1pt}{}
\titleformat{\subsection}
{\normalfont\fontsize{12pt}{14pt}\selectfont\bfseries}{\thesubsection .}{1pt}{}
%\titleformat{\subsubsection}
%{\normalfont\fontsize{12pt}{14pt}\selectfont\bfseries}{\thesubsubsection .}{1pt}{} % not used here
\titlespacing*{\chapter} {0pt}{12pt}{0.3ex plus .2ex}
\titlespacing*{\section} {0pt}{12pt}{0.3ex plus .2ex}
\titlespacing*{\subsection}{0pt}{12pt}{0.3ex plus .2ex}
%\titlespacing*{\subsubsection}{0pt}{12pt}{0.3ex plus .2ex} % not used here

\begin{document}    
    \renewcommand{\cfttoctitlefont}{\large\hfil\textbf}
    \pagenumbering{roman} \setcounter{page}{5}
    \def\contentsname{CONTENTS} 

    \setlength{\cftsecindent}{0em}  
    \setlength{\cftsubsecindent}{25em} 
    \tableofcontents
    \clearpage
    \pagenumbering{arabic} \setcounter{page}{1} 
    \addcontentsline{toc}{chapter}{Contents}    

    \chapter{A}
    \section{Introduction}
    \subsection{a}
\end{document}

enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.