更改目录中的标题

更改目录中的标题

我已经改变了我的章节和部分,我希望“目录”保持不变。

这是我用于章节和部分的代码:

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

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

它看起来像这样:

在此处输入图片描述

所以,我想将目录更改为 \raggedright 并像这样加下划线,我该怎么做?

希望有人能帮忙:D

这是我的主要文档:

\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}

我的序言

\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}

答案1

尝试一下这个代码。

我添加了一些虚拟文本来检查标题。

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}

这是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

存在冲突的软件包(floatfloatrow)、重复的软件包(xcolor)、错误的顺序(hyperref)。最好只保留作业所需的软​​件包,然后一次添加一个以测试兼容性。

使用 babel 来改变 ToC 的标题的方法如下:

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

添加或使用

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

b

相关内容