在序言中添加章节的第四小节时出错

在序言中添加章节的第四小节时出错

我正在尝试添加第三小节的第四小节。示例:4.1.3.1。我正在尝试添加最后的第四小节,但到目前为止还无法做到。

这是我的序言:

\documentclass[12pt,letterpaper]{article}
\usepackage[margin=1in]{geometry}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{xfrac}
\usepackage[retainorgcmds]{IEEEtrantools}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{subfig}
\usepackage{float}%keeps figures in the text where the page the code is written
\usepackage{pgfplots}
\usepackage{tikz}
\tikzset{
    mybox/.style={rounded rectangle,draw=black,align=center},
}
\usetikzlibrary{backgrounds,intersections}
\usetikzlibrary{positioning,shapes.misc}
\usepackage[edges]{forest}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
\usetikzlibrary{arrows.meta,
    positioning,
    quotes,
    shadows, shapes.misc}
%Fonts
%\usepackage{times}
%\usepackage{kpfonts}    % for nice fonts
%\usepackage{times}
\usepackage{setspace} 
\usepackage{microtype} 
\usepackage{booktabs}   % for nice tables
\usepackage{multirow} % tables feature
\usepackage[flushleft]{threeparttable}
\usepackage{array}%position table cell text
%\usepackage{bbold}         % for bold math
\usepackage{dsfont}
\usepackage{listings}   % for inserting code
\usepackage{verbatim}   % useful for program listings
\usepackage{color}  
\usepackage[colorlinks=true, linkcolor=blue, urlcolor=blue, citecolor=blue]{hyperref}
% use for hypertext
\usepackage[colorinlistoftodos]{todonotes}%used to add notes on PDF
%\usepackage{natbib}
%\bibpunct{(}{)}{;}{;}{,}{,}
\usepackage[colon]{natbib}%package for bibliography
\setcounter{secnumdepth}{3} %the depth of section numbering 0 means no numbering of any section, sub-section and on.
%used for begining theorems and propostions numbered according to the section they are in
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{assumption}[theorem]{Assumption}
\newtheorem{definition}[theorem]{Definition}
\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{capt-of}
\setlength{\parskip}{1em}
\usepackage{amssymb} 
%% Shortcuts
\newcommand{\td}[2]{\dfrac{d #1}{d #2}}
\newcommand{\std}[2]{\dfrac{d^2 #1}{d {#2}^2}}
\newcommand{\ctd}[3]{\dfrac{d^2 #1}{d #2 d #3}}

\newcommand{\pd}[2]{\dfrac{\partial #1}{\partial #2}}
\newcommand{\spd}[2]{\dfrac{\partial^2 #1}{\partial {#2}^2}}
\newcommand{\cpd}[3]{\dfrac{\partial^2 #1}{\partial #2 \partial #3}}

\newcommand{\pdi}[2]{\partial #1/\partial #2}

\newcommand{\LR}{\Leftrightarrow}
\newcommand{\Lg}{\mathcal{L}}
\newcommand{\half}{\tfrac{1}{2}}
\newcommand{\eqp}{\phantom{=}}
\newcommand{\eqs}{\buildrel s \over =}
\newcommand{\me}{\mathrm{e}}
\makeatletter
\newcommand*\rel@kern[1]{\kern#1\dimexpr\macc@kerna}
\newcommand*\widebar[1]{%
    \begingroup
    \def\mathaccent##1##2{%
        \rel@kern{0.8}%
        \overline{\rel@kern{-0.8}\macc@nucleus\rel@kern{0.2}}%
        \rel@kern{-0.2}%
    }%
    \macc@depth\@ne
    \let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
    \mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
    \macc@set@skewchar\relax
    \let\mathaccentV\macc@nested@a
    \macc@nested@a\relax111{#1}%
    \endgroup
}
\makeatother
%
\makeatletter
\def\subsection{\@startsection{subsection}{1}%
    \z@{.5\linespacing\@plus.7\linespacing}{-.5em}%
    {\normalfont\itshape}}
\def\@sect#1#2#3#4#5#6[#7]#8{%
    \edef\@toclevel{\ifnum#2=\@m 0\else\number#2\fi}%
    \ifnum #2>\c@secnumdepth \let\@secnumber\@empty
    \else \@xp\let\@xp\@secnumber\csname the#1\endcsname\fi
    \@tempskipa #5\relax
    \ifnum #2>\c@secnumdepth
    \let\@svsec\@empty
    \else
    \refstepcounter{#1}%
    \edef\@secnumpunct{%
        \ifdim\@tempskipa>\z@ % not a run-in section heading
        \@ifnotempty{#8}{.\@nx\enspace}%
        \else
        \@ifempty{#8}{.}{.\@nx\enspace}%
        \fi
    }%
    \@ifempty{#8}{%
        \ifnum #2=\tw@ \def\@secnumfont{\bfseries}\fi}{}%
    \protected@edef\@svsec{%
        \ifnum#2<\@m
        \@ifundefined{#1name}{}{%
            \ignorespaces\csname #1name\endcsname\space
        }%
        \fi
        \@seccntformat{#1}%
    }%
    \fi
    \ifdim \@tempskipa>\z@ % then this is not a run-in section heading
    \begingroup #6\relax
    \@hangfrom{\hskip #3\relax\@svsec}{\interlinepenalty\@M #8\par}%
    \endgroup
    \ifnum#2>\@m \else \@tocwrite{#1}{#8}\fi
    \else
    \def\@svsechd{#6\hskip #3\@svsec
        \@ifnotempty{#8}{\ignorespaces#8\unskip
            %\@addpunct.
        }%
        \ifnum#2>\@m \else \@tocwrite{#1}{#8}\fi
    }%
    \fi
    \global\@nobreaktrue
    \@xsect{#5}}
\makeatother

代码的最后一部分尝试添加子节:

%
\makeatletter
\def\subsection{\@startsection{subsection}{1}%
    \z@{.5\linespacing\@plus.7\linespacing}{-.5em}%
    {\normalfont\itshape}}
\def\@sect#1#2#3#4#5#6[#7]#8{%
    \edef\@toclevel{\ifnum#2=\@m 0\else\number#2\fi}%
    \ifnum #2>\c@secnumdepth \let\@secnumber\@empty
    \else \@xp\let\@xp\@secnumber\csname the#1\endcsname\fi
    \@tempskipa #5\relax
    \ifnum #2>\c@secnumdepth
    \let\@svsec\@empty
    \else
    \refstepcounter{#1}%
    \edef\@secnumpunct{%
        \ifdim\@tempskipa>\z@ % not a run-in section heading
        \@ifnotempty{#8}{.\@nx\enspace}%
        \else
        \@ifempty{#8}{.}{.\@nx\enspace}%
        \fi
    }%
    \@ifempty{#8}{%
        \ifnum #2=\tw@ \def\@secnumfont{\bfseries}\fi}{}%
    \protected@edef\@svsec{%
        \ifnum#2<\@m
        \@ifundefined{#1name}{}{%
            \ignorespaces\csname #1name\endcsname\space
        }%
        \fi
        \@seccntformat{#1}%
    }%
    \fi
    \ifdim \@tempskipa>\z@ % then this is not a run-in section heading
    \begingroup #6\relax
    \@hangfrom{\hskip #3\relax\@svsec}{\interlinepenalty\@M #8\par}%
    \endgroup
    \ifnum#2>\@m \else \@tocwrite{#1}{#8}\fi
    \else
    \def\@svsechd{#6\hskip #3\@svsec
        \@ifnotempty{#8}{\ignorespaces#8\unskip
            %\@addpunct.
        }%
        \ifnum#2>\@m \else \@tocwrite{#1}{#8}\fi
    }%
    \fi
    \global\@nobreaktrue
    \@xsect{#5}}
\makeatother

但是,从第一节开始,我就收到有关未定义控制序列的错误。有什么建议吗?为了获取第四个子节,我尝试使用 \paragraph{Fourth Subsection}。

答案1

所示的序言重新定义了整个 latex 部分标题机制,使用了\@tocwrite它未定义的命令。不清楚重新定义的目的是什么,article类已经支持 4 级编号标题。

在此处输入图片描述

\documentclass[12pt,letterpaper]{article}
\setcounter{secnumdepth}{4}
\begin{document}
\section{aa}
\subsection{aa}
\subsubsection{aa}
\paragraph{aa}
\end{document}

相关内容