0

I use \subsection{example} and on the toc shows 1.4.1 Example. But on the text only shows 1.4 Example. The numbered after chapter number 1 and section number 4 is missing. How to add the number for subsection?

Btw i have tried to see some duplicates. Tried their codes but didn't work.

My duplicate: enter link description here

MWE :

\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}
17
  • 1
    please upload you entire working code as a MWE – js bibra Aug 5 '20 at 13:18
  • @jsbibra please see my update – user516076 Aug 5 '20 at 13:30
  • Please make sure your example actually compiles. Never just ignore compilation errors, After adding two missing } and a d in \blintext, a \ before setcounter, removing the blank lines in the titleformat setup. The example compiles just fine and the subsection is numbered in TOC and doc. – daleif Aug 5 '20 at 13:48
  • @daleif if there's a typo it's my fault. But there's no typo on my main doc. And it still missing. The number behind subsection i mean – user516076 Aug 5 '20 at 14:00
  • Please copy and paste from your main document so that there's no typo. And please trim the main document down to the minimal necessary, probably by copying everything to a new file. – Teepeemm Aug 5 '20 at 14:02
2

After getting the MWE to actually compile, the problem boils down to this:

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

which is wrong, note the \thesection, it should be

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

to match the fact that it is for \subsection

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.