Mitali Mitali - 2 months ago 10
LaTeX Question

Numbering the subsection in LaTeX

In Chapter-3(section), I want subsections to be numbered as 3.1 ,3.2 ,3.3 and so on. But it appears as 2.4, 2.5. I tried using

\setcounter{subsection}{3}
, but it didn't help.

Following is the code:

%previous code

\cleardoublepage
\section*{Chapter 3}
\subsection*{Product Design}
\line(1,0){400}
\setcounter{subsection}{3}
\subsection{Product Perspective}

%rest of the code





Output appears as following:

Output

Answer

This answer might be a long stretch, but from this question and a previous question, I think I know what you are really after. If this is completely wrong, please let me know and I will delete this answer.

I assume that you want your document to look like the following:

table of contents chapter

To achieve that, you should use the report document class, which gives you an additional level of sectioning, the \chapter. Each chapter contains multiple sections, and each section contains subsections, subsubsections, paragraphs and so on. The basic setup for your document would be

\documentclass{report}
\begin{document}

% Frontmatter
\tableofcontents

% Main part
\chapter{Introduction}
    My project is awesome! In this chapter, I am telling you why.

\chapter{Product Design}
    \section{Product Perspective}
    The product is supposed to be very nice and cool.
    It shall satisfy all conditions and look awesome.

\end{document}

Now, to achieve the title formatting you are asking for in this question, we load the titlesec package and configure \chapter as shown below:

% Title formating
\usepackage{titlesec}
    \titleformat{\chapter}[display]
        {\normalfont\Large\bfseries}    % Make title \large and bold
        {\huge Chapter~\thechapter}     % Write Chapter X in \huge font
        {20pt}                          % 20pt distance between Chapter X and title
        {}
        [\vspace{1ex}\titlerule]        % Add a line below chapter title

If you print the document two-sided, and want all chapters to start on the right side of a double-page, then you can simply change replace \documentclass{report} by the following line, and you don't need to call \cleardoublepage before each chapter. This also makes the margins symmetrical.

\documentclass[twoside, openright]{report}

Then, in the previous question you also had an abstract and acknowledgements, which have roman page numbering. By default, LaTeX doesn't put unnumbered chapters like "Abstract" in the Table of Contents, so we have to do that manually. This is done as follows:

% Frontmatter
\pagenumbering{roman}    % Frontmatter with roman page numbering

\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}    % Add unnumbered chapter to table of contents
    This is the short version of my work.

\chapter*{Acknowledgement}
\addcontentsline{toc}{chapter}{Acknowledgement}    % Add unnumbered chapter to table of contents
    I would like to thank everybody who helped me.

of course, you then have to switch back to arabic page numbers before the first chapter. The entire code with the parts discussed above is shown below.

\documentclass{report}

% Title formating
\usepackage{titlesec}
    \titleformat{\chapter}[display]
        {\normalfont\Large\bfseries}    % Make title \large and bold
        {\huge Chapter~\thechapter}     % Write Chapter X in \huge font
        {20pt}                          % 20pt distance between Chapter X and title
        {}
        [\vspace{1ex}\titlerule]        % Add a line below chapter title

\begin{document}

% Frontmatter
\pagenumbering{roman}    % Frontmatter with roman page numbering

\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}    % Add unnumbered chapter to table of contents
    This is the short version of my work.

\chapter*{Acknowledgement}
\addcontentsline{toc}{chapter}{Acknowledgement}    % Add unnumbered chapter to table of contents
    I would like to thank everybody who helped me.

\tableofcontents

% Main part
\cleardoublepage
\pagenumbering{arabic} % Main part with arabic page numbering

\chapter{Introduction}
    My project is awesome! In this chapter, I am telling you why.

\chapter{Product Design}
    \section{Product Perspective}
    The product is supposed to be very nice and cool.
    It shall satisfy all conditions and look awesome.

\end{document}

I hope this is really how you want your document to look. If not - or if you have any other questions on what I showed you here, please write a comment. Finally, there is a separate site, which is only for questions on TeX, LaTeX and friends, and questions on LaTeX should be posted there.