0

I have changed my chapter and section and I would like the 'table of content' to be the same.

This is the code, I've used for the chapter and section:

\titleformat{\chapter}{\raggedleft\Huge}{\textcolor{gray}{CHAPTER} \textcolor{alizarin}{\thechapter}}{10pt}{\Huge}[\titlerule] %chapter

\titleformat{\section}{\bfseries\raggedright\Large}{\thesection}{10pt}{\Large} %section

And it looks like this:

enter image description here

So, I would like to change the table of content to \raggedright and be underlined like this, how can I do that?

Hope someone can help :D

Here is my main doc:

\documentclass{report}
%\usepackage[left=1.5 cm,right=1.5cm,top=2cm,bottom=2cm]{geometry}

\input{Necessary/preamble.tex}

%%%-------------Headlines
\usepackage{titlesec}
%chapter
\titleformat{\chapter}{\raggedleft\Huge}{\textcolor{gray}{CHAPTER} \textcolor{alizarin}{\thechapter}}{10pt}{\Huge}[\titlerule]
\titlespacing{\chapter}{0pt}{0pt}{25pt}
%sections
\titleformat{\section}{\bfseries\raggedright\Large}{\thesection}{10pt}{\Large}
\titlespacing{\section}{0pt}{10pt}{10pt}
%subsection
\titleformat{\subsection}{\bfseries\raggedright\large}{\thesubsection}{10pt}{\large}
\titlespacing{\subsection}{}{10pt}{10pt}

%-------------------Header/Footer
\usepackage{lastpage}
\lhead{Title}
\rhead{29.01.23}
\cfoot{} 
\rfoot{Page \thepage \hspace{1pt} of \pageref{LastPage}}

\begin{document}

%Frontpage
\input{Necessary/frontpage.tex}
\newpage

%table of contents
\pagestyle{empty}
\tableofcontents
\newpage
\pagestyle{fancy}

%%input all my sections

\end{document}

And my preamble

\usepackage[utf8]{inputenc}
\usepackage[english]{babel} 
\usepackage[a4paper, total={6in, 9in}]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L]{\fontsize{10}{12}}
\linespread{1.5}
\usepackage[toc,page]{appendix} 
\usepackage{multicol}  
\usepackage{textgreek}
\usepackage{setspace} 
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}} 
\usepackage{etoolbox} 
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{} 
\usepackage{parskip} %noindent

%%%-------------------

\AtBeginDocument{%
  \addtocontents{toc}{\protect\thispagestyle{empty}}%
  \addtocontents{lof}{\protect\thispagestyle{empty}}%
}

\usepackage[backend=biber,style=numeric-comp,autocite=inline,sorting=nty]{biblatex}
\addbibresource{references.bib}
\usepackage{hyperref} 
\usepackage{bookmark} 
\usepackage{xcolor}
\hypersetup{
    colorlinks,
    linkcolor={black!50!black}, 
    citecolor={black!50!black}, 
    urlcolor={black!80!black} 
} 

\usepackage{graphicx} 
\usepackage{float} 
\usepackage{rotating} 
\usepackage{subcaption} 
\usepackage{wrapfig}
\usepackage[labelfont={bf, it}]{caption}
\usepackage{amsmath,tocloft}
\numberwithin{figure}{subsection}

\usepackage[table,xcdraw]{xcolor} 
\usepackage[export]{adjustbox}
%\usepackage{multirow}
\usepackage{tabularx}
\usepackage{floatrow} 
\usepackage{booktabs} 
\usepackage{colortbl}
\usepackage{xcolor}
\usepackage{multirow}
\usepackage{caption}
\usepackage{longtable}
\numberwithin{table}{subsection}% tables numbered within subsection
\usepackage[singlelinecheck=false]{caption} 

\usepackage{enumerate} 
%%%sorted list
\usepackage{datatool}% http://ctan.org/pkg/datatool
\newcommand{\sortitem}[2][\relax]{%
  \DTLnewrow{list}% Create a new entry
  \ifx#1\relax
    \DTLnewdbentry{list}{sortlabel}{#2}% Add entry sortlabel (no optional argument)
  \else
    \DTLnewdbentry{list}{sortlabel}{#1}% Add entry sortlabel (optional argument)
  \fi%
  \DTLnewdbentry{list}{description}{#2}% Add entry description
}
\newenvironment{sortedlist}{%
  \DTLifdbexists{list}{\DTLcleardb{list}}{\DTLnewdb{list}}% Create new/discard old list
}{%
  \DTLsort{sortlabel}{list}% Sort list
  \begin{itemize}%
    \DTLforeach*{list}{\theDesc=description}{%
      \item \theDesc}% Print each item
  \end{itemize}%
}

\usepackage{textcomp}
\usepackage{gensymb} 

\usepackage[breakable, theorems, skins]{tcolorbox}
\tcbset{enhanced}
\DeclareRobustCommand{\mybox}[2][gray!20]{%Angiver farve af boks
\begin{tcolorbox}[   %% Adjust the following parameters at will.
        breakable,
        left=0pt,
        right=0pt,
        top=0pt,
        bottom=0pt,
        colback=#1,
        colframe=#1,
        width=\dimexpr\textwidth\relax, 
        enlarge left by=0mm,
        boxsep=5pt,
        arc=0pt,outer arc=0pt,
        ]
        #2
\end{tcolorbox}}
\usepackage{minted} %Code highlight

\usepackage{epstopdf}
\usepackage[normalem]{ulem}
\useunder{\uline}{\ul}{}
\usepackage[T1]{fontenc} 
\usepackage{array}
\usepackage{tabu}
\usepackage{rotating}
\usepackage{amsmath}
\usepackage{times}
\usepackage[none]{hyphenat}
\sloppy
\usepackage[demo]{graphicx} 
\usepackage{eso-pic} 
\usepackage{lipsum} 
\usepackage[version=4]{mhchem}
\usepackage{xfrac}
\usepackage{amsfonts}
\usepackage{enumitem}
\usepackage{microtype}
\usepackage{breakcites} 
\usepackage{soul} 
\usepackage{comment} 

\definecolor{alizarin}{rgb}{0.82, 0.1, 0.26}
10
  • Add after \titleformat{... : \renewcommand{\contentsname}{Contents \hfill} Sep 16, 2022 at 15:25
  • I've tried that now, and it does not work
    – Ellen
    Sep 18, 2022 at 9:17
  • 1
    Please provide a compilable code from \documentclass{... to \end{document}. Otherwise it might be impossible to help. Sep 18, 2022 at 14:44
  • I've added it now, does it help? :)
    – Ellen
    Sep 20, 2022 at 13:40
  • Very good. Please also add preamble.tex. Test your posted code in a new directory: it must compile without errors and generate the posted figure and the table of contents you don't like and wanted to change. Meanwhile I added a tentative answer. Sep 20, 2022 at 14:44

1 Answer 1

0

Try this code.

I added some dummy text the check the headers.

a

% !TeX TS-program = pdflatex

\documentclass{report}

\input{newpreamble.tex} % changed <<<<<<<<<<<<<<<<

%%%-------------Headlines
\usepackage{titlesec}
%chapter
\titleformat{\chapter}{\raggedleft\Huge}{\textcolor{gray}{CHAPTER} \textcolor{red}{\thechapter}}{10pt}{\Huge}[\titlerule]

\titlespacing{\chapter}{0pt}{0pt}{25pt}
%sections
\titleformat{\section}{\bfseries\raggedright\Large}{\thesection}{10pt}{\Large}
\titlespacing{\section}{0pt}{10pt}{10pt}
%subsection
\titleformat{\subsection}{\bfseries\raggedright\large}{\thesubsection}{10pt}{\large}
\titlespacing{\subsection}{}{10pt}{10pt}

%%-------------------Header/Footer
\usepackage{lastpage}
\lhead{Development and functional evaluation\\ of CAR T cells targeting EGFRvIII} % changed <<<<<<<<<<<<
\rhead{29.01.23}
\cfoot{} %fjerner automatisk pagenumber centralt
\rfoot{Page \thepage\ of \pageref{LastPage}}

\usepackage{kantlipsum} % added ONLY for dummy text

\begin{document}
    
    %Frontpage
%   \input{Necessary/frontpage.tex}
%   \newpage
        
    \tableofcontents
    \thispagestyle{empty}%<<<<<<<<<<<<<<<<<< here
    \newpage
    
    \pagestyle{fancy}
    
    \chapter{Introduction}
    
    \kant[1-10]
    
    \section{Sec. One}
    
    \kant[11-20]
    
    \chapter*{Introduction 2}
    
    %%input all my sections
    
\end{document}

This is newpreamble.tex

%% file newpreamble.tex

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\addto\captionsenglish{\renewcommand{\contentsname}{\textcolor{gray}{CONTENTS}\hfill}}% added <<<<< <<<<<<<<<<<<<<
 
\usepackage[a4paper, total={6in, 9in}]{geometry}
\usepackage{xcolor} 
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L]{\fontsize{10}{12}}

\setlength{\headheight}{25pt}% added <<<<<
\addtolength{\topmargin}{-10pt}% added <<<<<

\linespread{1.5}
\usepackage[toc,page]{appendix} 
\usepackage{multicol}  
\usepackage{textgreek}
\usepackage{setspace} 
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}} 
\usepackage{etoolbox} 
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{} 
\usepackage{parskip} %noindent

%%%-------------------

\AtBeginDocument{%
    \addtocontents{toc}{\protect\thispagestyle{empty}}%
    \addtocontents{lof}{\protect\thispagestyle{empty}}%
}

\usepackage[backend=biber,style=numeric-comp,autocite=inline,sorting=nty]{biblatex}
%%%%\addbibresource{references.bib} % missing <<<<<<<<<<

\usepackage{graphicx} 
\usepackage{float} 
\usepackage{rotating} 
\usepackage{subcaption} 
%%%\numberwithin{table}{subsection}% tables numbered within subsection
%%%\numberwithin{figure}{subsection}

\usepackage{wrapfig}
\usepackage[labelfont={bf, it}]{caption}
\usepackage{amsmath}
%%%\usepackage{tocloft}

%%%\usepackage[table,xcdraw]{xcolor} 
%%%\usepackage{xcolor} 
\usepackage[export]{adjustbox}
%%%%\usepackage{multirow}
\usepackage{tabularx}
%%%\usepackage{floatrow} 
\usepackage{booktabs} 
\usepackage{colortbl}
%%%%\usepackage{xcolor}
\usepackage{multirow}
\usepackage{caption}
\usepackage{longtable}
\usepackage[singlelinecheck=false]{caption} 
\usepackage{enumerate} 
%%%sorted list
\usepackage{datatool}% http://ctan.org/pkg/datatool
\newcommand{\sortitem}[2][\relax]{%
    \DTLnewrow{list}% Create a new entry
    \ifx#1\relax
    \DTLnewdbentry{list}{sortlabel}{#2}% Add entry sortlabel (no optional argument)
    \else
    \DTLnewdbentry{list}{sortlabel}{#1}% Add entry sortlabel (optional argument)
    \fi%
    \DTLnewdbentry{list}{description}{#2}% Add entry description
}
\newenvironment{sortedlist}{%
    \DTLifdbexists{list}{\DTLcleardb{list}}{\DTLnewdb{list}}% Create new/discard old list
}{%
    \DTLsort{sortlabel}{list}% Sort list
    \begin{itemize}%
        \DTLforeach*{list}{\theDesc=description}{%
            \item \theDesc}% Print each item
    \end{itemize}%
}

\usepackage{textcomp}
\usepackage{gensymb} 
\usepackage[breakable, theorems, skins]{tcolorbox}
\tcbset{enhanced}
\DeclareRobustCommand{\mybox}[2][gray!20]{%Angiver farve af boks
    \begin{tcolorbox}[   %% Adjust the following parameters at will.
        breakable,
        left=0pt,
        right=0pt,
        top=0pt,
        bottom=0pt,
        colback=#1,
        colframe=#1,
        width=\dimexpr\textwidth\relax, 
        enlarge left by=0mm,
        boxsep=5pt,
        arc=0pt,outer arc=0pt,
        ]
        #2
\end{tcolorbox}}
\usepackage{minted} %Code highlight

\usepackage{epstopdf}
\usepackage[normalem]{ulem}
%%%%\useunder{\uline}{\ul}{}
\usepackage[T1]{fontenc} 
\usepackage{array}
%%%%\usepackage{tabu}
\usepackage{rotating}
\usepackage{amsmath}
\usepackage{times}
\usepackage[none]{hyphenat}
\usepackage{graphicx} 
\usepackage{eso-pic} 
\usepackage{lipsum} 
\usepackage[version=4]{mhchem}
\usepackage{xfrac}
\usepackage{amsfonts}
\usepackage{enumitem}
\usepackage{microtype}
\usepackage{breakcites} 
\usepackage{soul} 
\usepackage{comment} 

\usepackage{bookmark} 
\usepackage{hyperref} 
\hypersetup{
    colorlinks,
    linkcolor={black!50!black}, 
    citecolor={black!50!black}, 
    urlcolor={black!80!black} 
} 

\definecolor{alizarin}{rgb}{0.82, 0.1, 0.26}

\sloppy

There were conflicting packages (float, floatrow), duplicates (xcolor), wrong order (hyperref). It is good practice to have only the packages needed for the job and add one at a time to test compatibility.

Using babel this is the way to change the title of the ToC:

\addto\captionsenglish{\renewcommand{\contentsname}{\textcolor{gray}{CONTENTS}\hfill}}

ADDED or using

\addto\captionsenglish{\renewcommand{\contentsname}{\hfill\textcolor{gray}{CONTENTS}}}%

b

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .