我的论文中 \subsection 命令的控制序列未定义

我的论文中 \subsection 命令的控制序列未定义

在写论文的时候遇到一个无法解决的问题:当我使用\chapter或\section时,不会出现任何错误;但是当我写\subsection或\subsubsection时,会返回错误“未定义的控制序列”;

这是我的主要论文.tex:

\PassOptionsToPackage{table}{xcolor}

\documentclass[a4paper,11pt,twoside]{report}
\usepackage[left=2.5cm,right=2.5cm,top=3.5cm,bottom=3.5cm]{geometry}

\include{thesis.preamble}
\usepackage{apalike} 
\usepackage{tabularray}

\usepackage{lmodern}
\usepackage{enumitem} 
\usepackage{multirow}
\usepackage[demo]{rotating}
\usepackage{amsmath,amssymb}
\usepackage[toc,page]{appendix}
\usepackage{hyperref}
\usepackage{fixltx2e}
\usepackage{epigraph}
\usepackage{listings}
\usepackage{soul}
\usepackage{pdfpages}
\usepackage{chemfig}
\usepackage{bm}
%\renewcommand{\glsnamefont}[1]{\textbf{#1}}
\usepackage[acronym,shortcuts,style=super,nonumberlist,automake,toc]{glossaries}
\makeglossaries



\newcommand{\matr}[1]{\mathbf{#1}}

\lstset{frame=tb,
  language=Java,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\coloraltlist{mauve},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=3  
}




  \newcommand\bh{\tikz[remember picture]
                    \node (begin highlight) {};
                 }
  \newcommand\eh{\tikz[remember picture]
                 \node (end highlight) {};
                 \tikz[remember picture, overlay] 
                 \draw[yellow,line width=10pt,opacity=0.3] (begin highlight) -- (end
                  highlight);
                 }



\usepackage{xcolor}
\hypersetup{
    colorlinks,
    linkcolor={red!50!black},
    citecolor={blue!50!black},
    urlcolor={blue!80!black}
}

%\usepackage[hidelinks]{hyperref}

\usepackage{titlesec, blindtext, color}
\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{20pt}}

\def\rotatechartwo#1{\reflectbox{#1}}


\newcommand{\textoverline}[1]{$\overline{\mbox{#1}}$}

% This section of packages is because of a bug with titlesec
\usepackage{titlesec}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\ttlh@hang}{\parindent\z@}{\parindent\z@\leavevmode}{}{}
\patchcmd{\ttlh@hang}{\noindent}{}{}{}
\makeatother

\titleformat{\chapter}[hang]{\normalfont\sffamily\huge\bfseries}{\thechapter.}{20pt}{\huge}   
  
\titleformat{\section}[hang]
 {\normalfont\sffamily\Large\bfseries}
 {\thesection.}{12pt}{\Large}
   
\titleformat{\subsection}[hang]{\normalfont\sffamily\Normalsize\bfseries}{\thesubsection.}{12pt}{\Normalsize}  
\titleformat{\subsubsection}[block]{\normalfont\sffamily\Normalsize\bfseries}{\Normalsize}{12pt}{}

\pagenumbering{arabic}

\begin{document}

\title{\LARGE {\bf MY tilte }\\
 \vspace*{6mm}
}

\author{JJ}
\submitdate{June 2023}

\maketitle
\preface
\mediumlinespacing
\input{Copyright/copyright}
\input{Abstract/abstract.tex}
\input{Acknowledgements/acknowledgements}
\input{Declaration/Declaration}
%\input{quotes/quotes}

\narrowlinespacing

\renewcommand{\baselinestretch}{0}\normalsize
\tableofcontents
\renewcommand{\baselinestretch}{1.0}\normalsize


\mediumlinespacing

\setacronymstyle{long-short}
% \newglossaryentry{5}{name={Variation of information},description={A metric that measures the information-theoretic distance based on the similarity/dissimilarity of information between two community partitions. References to VI in this thesis  are referring to the average distance between the ensemble of partitions that are optimised by the Louvain algorithm (usually 100 optimisations)}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% All Abbreviations

\newacronym{EEG}{EEG}{Electroencephalogram}


\glsaddall
\printglossaries

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\body


\input{Introduction/introduction}

\input{Chapter 2 Methods/Chapter2 Methods}

\addcontentsline{toc}{chapter}{Bibliography}
\bibliographystyle{apalike}
\bibliography{Bibliography/PhDthesisRef}


\input{Appendix/appendix}


\end{document}


对于章节输入,我有 \section 和 \subsection 命令,其中 \subsection 和 \subsubsection 上都会有错误标记。

例如在Introduction.tex中:

\chapter{Introduction}
\label{ch:introduction}

\section{Sleep, insomnia, and its interventions}
\label{sec:Intro-Sleep}

\subsection{Sleep disturbances, cognitive decline, and neurodegeneration}

\subsection 会出现错误标记“未定义控制序列”。尽管它似乎正在运行,因为子节将出现在 pdf 中。

如果相关的话,我很乐意提供进一步的 .sty 样式文件,提前谢谢您!

相关内容