如何在 Overleaf Latex 中将章节标题与章节号居中

如何在 Overleaf Latex 中将章节标题与章节号居中

我对 Latex 还不太熟悉,想根据教授提供的模板制作报告。我想将章节标题和章节编号居中,并在其下方添加下划线。我尝试了很多方法,但只有章节标题居中,章节编号却居中。有人能帮我吗?

目前,我看到的章节名称如下:[1]:https://i.stack.imgur.com/VCsiO.png

我想要实现的目标:[2]:https://i.stack.imgur.com/8GrvS.png

我尝试过许多答案中提到的居中方法\chapter*{\centering Introduction},但那只是将标题居中,Introduction而不是标题。有人能帮我把章节标题和编号居中,并在其下方添加下划线,这样看起来会更专业吗?

\documentclass[a4paper,12pt]{book}
\usepackage{fontspec}  
\usepackage{microtype}  
\usepackage{polyglossia}
\setdefaultlanguage{english}
\usepackage[english]{selnolig}
\usepackage{geometry}
\usepackage[usegeometry,
            margin=20mm,
            twoside=semi]
           {typearea} 

\usepackage{acronym}
    \renewcommand*{\acsfont}[1]{{\rmfamily #1}} 
\usepackage[export]{adjustbox}
\usepackage[font=small,labelfont=bf]{caption}
\usepackage{csquotes}
\usepackage{graphicx}  
\usepackage{icomma} 
\usepackage{ltablex}   
\usepackage{newfile}   
\usepackage{overpic}   
\usepackage[hyphens]{url}
\usepackage{url}
\usepackage[
  backend=biber,
  style=ieee,
  urldate=long, 
  dateabbrev=false
]{biblatex}
\addbibresource{literatur.bib} 


\usepackage{float}
\makeatletter
\def\ScaleIfNeeded{
    \ifdim\Gin@nat@width>\linewidth
        \linewidth
        \else
        \Gin@nat@width
        \fi
}
\makeatother
\setkeys{Gin}{width=\ScaleIfNeeded}

\parindent 2em         
\parskip 0.5em          

\pagestyle{headings}

\input{commons_en.tex}

\newoutputstream{xmpstream}
\openoutputfile{\jobname.xmpdata}{xmpstream}
    \newcommand{\dummyspace}{ }

    \addtostream{xmpstream}{\protect\Title{\dctitle}}
    \addtostream{xmpstream}{\protect\Author{\dcauthorfirstname  \dcauthorlastname}}
    \addtostream{xmpstream}{\protect\Keywords{Compiler\protect\sep\dummyspace
                                              Database\protect\sep\dummyspace
                                              Index}}
    \addtostream{xmpstream}{\protect\Publisher{My University}}
\closeoutputstream{xmpstream}

\usepackage{hyperref}
\usepackage[a-1b]{pdfx}

\hypersetup{unicode,
            pdftitle={\dctitle},
            pdfauthor={\dcauthorfirstname~\dcauthorlastname},
            pdfsubject={\dcsubject},
            hidelinks}

\pdfinfo{
    /Title(\dctitle)
    /Author(\dcauthorfirstname\ \dcauthorlastname)
    /Subject(\dcsubject)
}

\usepackage{makeidx}         
\makeindex                    

\setcounter{secnumdepth}{4}    
\setcounter{tocdepth}{4}       


\author{\dcauthorfirstname~\dcauthorlastname}
\title{\dctitle}
\date{\today}


\begin{document}
\frontmatter

\begin{titlepage}
    \sffamily
    \newgeometry{left=2cm,top=2cm,bottom=2cm,right=2cm}

    \centering{
        \begin{tabularx}{\linewidth}{lp{1.5em}|p{1.5em}X}
            \includegraphics[width=0.33\textwidth,valign=c]{\tulogo}
            & & &
            {\huge\bfseries Department of Human Psychology}
        \end{tabularx}

        \vfill\vfill

        {\Huge\bfseries \dctitle}
        \vfill\vfill

        {\huge \dcsubject\\[1ex]

        for obtaining the academic degree}
        \vfill

        \LARGE B.\,Com.
        \vfill

        \dcauthortitle~\dcauthorfirstname~\dcauthorlastname\\[1ex]
       Registration Number: \dcmatriculation
    }
    \vfill\vfill\vfill
    
    \large
    \begin{tabular}[t]{ll}
        \textbf{Internal supervisor:}  & ABCD\\
        \textbf{External supervisor:}  & WXYZ.
    \end{tabular}

\end{titlepage}

\pagestyle{empty}

\ \\[90ex]
\null\vfill
{
    \ \\
    \textbf{\dcauthorlastname, \dcauthorfirstname}\\
    \dctitle\\
    \dcsubject, Department of Social Science\\
    My University,~%
        \ifcase\month%
            \or January%
            \or February%
            \or March%
            \or April%
            \or May%
            \or June%
            \or July%
            \or August%
            \or September%
            \or October%
            \or November%
            \or December%
        \fi%
    ~\number\year
}
\par\vfill\null

%-----------------------------
% Acknowledgements
%-----------------------------
\section*{\centering Acknowledgements}
\input{tex/1.Acknowledgements.tex}

\vfill
\thispagestyle{empty}
%-----------------------------
% Abstract
%-----------------------------
\section*{\centering Abstract}
\input{tex/2.Abstract.tex}

\vfill
\thispagestyle{empty}

\section*{\centering About}
\input{tex/3.About}

\vfill
\clearpage{\pagestyle{empty}\cleardoublepage}

\pagestyle{headings}


%-----------------------------
% Lists
%-----------------------------
\tableofcontents            \clearpage{\pagestyle{empty}\cleardoublepage}
\listoffigures              \clearpage{\pagestyle{empty}\cleardoublepage}
\listoftables               \clearpage{\pagestyle{empty}\cleardoublepage}
%\lstlistoflistings
\input{tex/acronyms_en.tex}    \clearpage{\pagestyle{empty}\cleardoublepage}    
\mainmatter 
\acresetall

%---------------------------------------------------------------------------------------------------
\chapter{\centering Introduction}
\input{tex/4.Introduction.tex}

\chapter{Conclusion}
\input{tex/10.Conclusion.tex}

\chapter{Future Scope}
\input{tex/11.FutureScope.tex}

\begin{appendix}

\chapter{Appendix}
\label{chap:Appendix}
\input{tex/appendix0_en.tex}

\end{appendix}

\backmatter

\printindex


\addcontentsline{toc}{chapter}{Bibliography}
\printbibliography

\clearpage
\thispagestyle{empty}
\addcontentsline{toc}{chapter}{Statement of Authorship}

\newgeometry{left=2cm,right=3.5cm,top=2cm,bottom=2cm}

\newlength\us
\settowidth{\us}{-\dcauthorfirstname~\dcauthorlastname-}

\begin{overpic}[width=\linewidth]{pics/selbstaendigkeitserklaerung}
    \put (6.5,81.71) {\small\sffamily \dcauthorlastname}
    \put (6.5,78.15) {\small\sffamily \dcauthorfirstname}
    \put (6.5,74.60) {\small\sffamily \dcauthorbirthdate}
    \put (6.5,71.05) {\small\sffamily \dcmatriculation}
    \put (5,32.69)   {\small\sffamily \today}
    \put (45.8,57.46){\small\sffamily \dcsubject}
    \put (38,32.6)   {\rule[-0.1ex]{\us}{0.5pt}}
\end{overpic}
\restoregeometry

\end{document}

答案1

只需使用titlesec。将以下几行添加到你的序言中:

\usepackage{titlesec}
\titleformat{\chapter}[display]{\bfseries\filcenter}{\huge\chaptername~\thechapter}{3.8ex}{\Huge}[\vskip 1ex{\titlerule[1pt]}]

在此处输入图片描述

相关内容