缺少编号的小节

缺少编号的小节

我使用\subsection{example}和 ,目录中显示1.4.1 Example。但文本上只显示。章节号和节号1.4 Example后面的编号丢失了。如何添加小节的编号?14

顺便说一句,我尝试查看一些重复项。尝试了他们的代码,但没有用。

我的副本:在此处输入链接描述

分数维:

\documentclass[a4paper,12pt,oneside,openany]{book}
\usepackage{pgf, tikz}
\usepackage[a4paper, inner=4cm, outer=3cm, top=4cm, bottom=3cm]{geometry}
\usepackage{geometry}
\usepackage[onehalfspacing]{setspace}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{setspace}
\usepackage[titles]{tocloft}
\usepackage{tocbibind}
\usepackage{indentfirst}
\usepackage{blindtext}
\usepackage{tocloft}
\usepackage{etoolbox}
\usepackage{enumitem}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsfonts}

\patchcmd{\section}{\bfseries}{\bfseries\boldmath}{}{}
\setlength{\cftbeforesecskip}{10pt}
\setlength{\cftbeforesubsecskip}{10pt}
\fancyhf{}
\cfoot{\thepage}
\linespread{1.5}
\pagestyle{plain}
\renewcommand\cftchapdotsep{\cftdotsep}
\titleformat{\chapter}[block]
    {\normalfont\bfseries\centering}
    {}{0pt}{}
\titleformat{\section}
    {\normalfont\bfseries}
    {\thesection}{1em}{}
\titleformat{\subsection}
    {\normalfont\bfseries}
    {\thesection}{1em}{}
\titlespacing*{\chapter}{0pt}{10pt}{20pt}
\titlespacing*{\section}{0pt}{0pt}{0pt}
\titlespacing*{\subsection}{0pt}{0pt}{0pt}

\addtocontents{toc}{\protect\null\protect\hfill{Halaman}\protect\par}
\setlength\parindent{1.25cm} 
\setcounter{secnumdepth}{2} %I TRIED THIS BUT DID'NT WORK


\begin{document}


\frontmatter %

\pagestyle{fancy}   
\renewcommand{\headrulewidth}{0pt}


\begin{spacing}{0.1}
    \tableofcontents
%   \listoffigures
%   \listoftables
\end{spacing}


\mainmatter 
\pagestyle{fancyplain}
\fancyhf{}
\fancyhead[R]{\thepage}
\renewcommand{\headrulewidth}{0pt}

\refstepcounter{chapter}
\chapter*{\textbf{BAB 1. PENDAHULUAN}}
\addtocontents{toc}{\setlength{\cftbeforechapskip}{20pt}}
\addcontentsline{toc}{chapter}{\textbf{BAB 1. PENDAHULUAN}}  
\thispagestyle{empty}

\vspace{15pt}
\section{\textbf{Batasan Masalah}}  
\blindtext

\vspace{15pt}
\section{\textbf{Tujuan Penelitian}}  
\blindtext  

\vspace{15pt}
\section{\textbf{Manfaat Penelitian}}  
\blindtext 

\vspace{15pt}
\section{\textbf{Kebaruan Penelitian}}  
\blindtext

\subsection{Subsection 1}
\blindtext
\subsection{Subsection 2}
\blindtext

\end{document}

答案1

在让 MWE 实际编译之后,问题归结为:

\titleformat{\subsection}
    {\normalfont\bfseries}
    {\thesection}{1em}{}

这是错误的,请注意\thesection,应该是

\titleformat{\subsection}
    {\normalfont\bfseries}
    {\thesubsection}{1em}{}

为了匹配它是为了\subsection

相关内容