\titlesec 和 chapter§ion 缺少零错误

\titlesec 和 chapter§ion 缺少零错误

我在这里找了好久,想找到一个可能的答案,但还是找不到。我甚至参考了 titlesec .pdf 说明,但仍然没有头绪。我的\chapter主体部分出现了问题,提示缺少一个零。

Chapter 1.
! Missing number, treated as zero.
<to be read again> 
                   \relax 
l.39 \chapter{Spanning Tree Protocol Concepts}

我的第一章出现了错误。

我正在输入笔记,对于每个章节,我想显示“第 1 章”,然后显示“这是章节的标题”。我不想对部分进行编号,这就是我使用的原因\section*。有什么想法吗?

\documentclass{report}
\usepackage[letterpaper,margin=1in]{geometry}
%\usepackage{fancyhdr}
\usepackage{amsmath ,amsthm ,amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{tabto}
\usepackage{enumitem}
\usepackage{bookmark}
\usepackage{booktabs}
\usepackage{titlesec}
\usepackage{parskip}
%\usepackage{indentfirst} used to indent first paragraph


%%%CHAPTER FORMAT/SPACING
\titleformat{\chapter}[display] %cmd and shape
    {\normalfont\LARGE\bfseries} %textformat    \typeoffont\size\ifits bold?
{Chapter \thechapter}%Label
    {1pt} %seperaton from num to title name
    {} %before code (blank means default)
\titlespacing{\chapter}{}{}{4pt} %cmd left margin befoe titel and after title
%%%SECTION FROMAT/SPACING
\titleformat{\section}
    {\normalfont\Large\bfseries}
    {\thesection}{}{}
\titlespacing{\section}{}{5pt}{5pt}
\linespread{0.7}
\setlist{nosep}
\setlength{\intextsep}{1pt}
\setlength{\parskip}{0pt}


\begin{document}
%\maketitle{ICND2 Note}
\part{LAN Switching}
\chapter{Spanning Tree Protocol Concepts}
    \section*{Spanning Tree Protocol IEEE 802.1}%\pdfbookmark{STP}    {ch:1:sec:2}
        -Prevents loops when redundant links are used\\
        -STP main goals 
        \begin{enumerate}
            \item All devices in a VLAN can send frames to all others
            \item Frames do not loop around (short life)
        \end{enumerate}
        -Checks each interface before send and receiving to prevent loops \\
        -Consist of 2 states \textbf{Forwarding} \& \textbf{Blocking}
    \section*{The Need for Spanning Tree} %\\pdfbookmark{Need for STP}
/end{document}

答案1

该命令\titlespacing需要三种长度。

所以他们应该是这样的

\titlespacing{\chapter}{0pt}{0pt}{4pt}

\titlespacing{\section}{0pt}{5pt}{5pt}

另外你/end{document}还有\end{document}

我不知道您想要实现什么,但这是您修改后的 MWE:

\documentclass{report}
\usepackage[letterpaper,margin=1in]{geometry}
%\usepackage{fancyhdr}
\usepackage{amsmath ,amsthm ,amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{tabto}
\usepackage{enumitem}
\usepackage{bookmark}
\usepackage{booktabs}
\usepackage{titlesec}
\usepackage{parskip}
%\usepackage{indentfirst} used to indent first paragraph


%%%CHAPTER FORMAT/SPACING
\titleformat{\chapter}[display] %cmd and shape
    {\normalfont\LARGE\bfseries} %textformat    \typeoffont\size\ifits bold?
{Chapter \thechapter}%Label
    {1pt} %seperaton from num to title name
    {} %before code (blank means default)
\titlespacing{\chapter}{0pt}{0pt}{4pt} %cmd left margin befoe titel and after title
%%%SECTION FROMAT/SPACING
\titleformat{\section}
    {\normalfont\Large\bfseries}
    {\thesection}{1em}{}
\titlespacing{\section}{0pt}{5pt}{5pt}
\linespread{0.7}
\setlist{nosep}
\setlength{\intextsep}{1pt}
\setlength{\parskip}{0pt}


\begin{document}
%\maketitle{ICND2 Note}
\part{LAN Switching}
\chapter{Spanning Tree Protocol Concepts}
    \section*{Spanning Tree Protocol IEEE 802.1}%\pdfbookmark{STP}    {ch:1:sec:2}
        -Prevents loops when redundant links are used\\
        -STP main goals
        \begin{enumerate}
            \item All devices in a VLAN can send frames to all others
            \item Frames do not loop around (short life)
        \end{enumerate}
        -Checks each interface before send and receiving to prevent loops \\
        -Consist of 2 states \textbf{Forwarding} \& \textbf{Blocking}
    \section*{The Need for Spanning Tree} %\\pdfbookmark{Need for STP}
\end{document} 

输出

在此处输入图片描述

请注意,你还缺少长度

\titleformat{\section}
    {\normalfont\Large\bfseries}
    {\thesection}{}{}

它应该是这样的

\titleformat{\section}
    {\normalfont\Large\bfseries}
    {\thesection}{1em}{}

您只是没有注意到这一点,因为在 MWE 中您只有未编号的部分。

答案2

我建议进行一个小的改进:以连字符开头的行具有 itemize 结构,因此我过去使用 es进行enumitem格式化。缺少长度作为第 4 个参数:itemizeendash\titleformat{\section}{…}

\documentclass{report}
\usepackage[letterpaper,margin=1in]{geometry}
%\usepackage{fancyhdr}
\usepackage{amsmath ,amsthm ,amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{tabto}
\usepackage{enumitem}
\usepackage{bookmark}
\usepackage{booktabs}
\usepackage{titlesec}
\usepackage{parskip}
%\usepackage{indentfirst} used to indent first paragraph

\setlist[itemize, 1]{标签 = \textendash}

%%%CHAPTER FORMAT/SPACING
\titleformat{\chapter}[display] %cmd and shape
    {\normalfont\LARGE\bfseries} %textformat \typeoffont\size\ifits bold?
{Chapter \thechapter}%Label
    {1pt} %seperation from num to title name
    {} %before code (blank means default)
\titlespacing{\chapter}{0pt}{0pt}{4pt} %cmd left margin befoe titel and after title
%%%SECTION FORMAT/SPACING
\titleformat{\section}
    {\normalfont\Large\bfseries}
    {\thesection}{0.5em}{}
\titlespacing{\section}{0pt}{5pt}{5pt}
\linespread{0.7}
\setlist{nosep}
\setlength{\intextsep}{1pt}
\setlength{\parskip}{0pt}


\begin{document}

%\maketitle{ICND2 Note}
\part{LAN Switching}
\chapter{Spanning Tree Protocol Concepts}
    \section*{Spanning Tree Protocol IEEE 802.1}%\pdfbookmark{STP} {ch:1:sec:2}
\begin{itemize}[wide = 0pt]
        \item Prevents loops when redundant links are used
        \item STP main goals
        \begin{enumerate}[wide = 1.9em, leftmargin=3.15em]
            \item All devices in a VLAN can send frames to all others Text text text text text text text text text text text text text text text text text text text text text text
            \item Frames do not loop around (short life)
        \end{enumerate}
        \item Checks each interface before send and receiving to prevent loops 
        \item Consist of 2 states \textbf{Forwarding} \& \textbf{Blocking}
\end{itemize}
    \section*{The Need for Spanning Tree} %\\pdfbookmark{Need for STP}

\end{document} 

在此处输入图片描述

相关内容