\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

我建議一個小的改進:以連字符開頭的行具有逐項結構,因此我過去使用 es進行enumitem格式化。的第四個參數缺少長度: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]{label = \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} 

在此輸入影像描述

相關內容