TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a problem while trying to figure out a structure for report document.

At this moment I have:

\chapter[Chapter 1]{}
\section{Section 1}
\subsection{Subsection 1}
\subsection{Subsection 2}
\section{Section 2}

Effect of that in ToC is:

1. Chapter 1
1.1 Section 1
1.1.1 Subsection 1
1.1.2 Subsection 2
1.2 Section 2

What I'm looking for is:

Chapter 1
1 Section 1
1.1 Subsection 1
1.2 Subsection 2
2 Section 2

I already tried using \addcontentsline{toc}{chapter}{Chapter 1}, but obviously it solved problem only with chapter and wrong numeration for sections and subsections is still happening.
I've tested changing \chapter to \part as well. Unfortunately effect is not satisfying since it causes even more problems to fix in ToC and document structure.

share|improve this question
    
Welcome to TeX.SX. Do you want to have this numeration in ToC only or in the body as well? – Christian Hupfer Feb 21 at 11:52
    
Thanks. Numeration in the body must be the same as numeration in ToC. – Estyere Feb 21 at 11:53
    
See my answer below please then-- I think this is what you want to achieve. – Christian Hupfer Feb 21 at 11:58
up vote 2 down vote accepted

This removes the \thechapter counter output from the \thesection counter formatting. Since \thesubsection etc. are recursively using \thesection etc. this will provide the correct numbering for all sectioning commands.

Please note that this will change the numbering within the body as well!

Most likely, the spacing should be changed!

\documentclass{book}


\renewcommand{\thesection}{\arabic{section}}

\begin{document}
\tableofcontents

\chapter[Chapter 1]{}
\section{Section 1}
\subsection{Subsection 1}
\subsection{Subsection 2}
\section{Section 2}

\end{document}
share|improve this answer
    
Mixed with \addcontentsline{toc}{chapter}{}, done it's job perfectly, thanks a lot! – Estyere Feb 21 at 12:17

If you want normal numbering in the body, you can use the \p@section feature.

\documentclass{report}

\makeatletter
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\p@section}{\thechapter.}
\renewcommand{\p@subsection}{\thechapter.}
\renewcommand{\@seccntformat}[1]{%
  \csname p@#1\endcsname\csname the#1\endcsname\quad
}
\makeatother


\begin{document}
\tableofcontents

\chapter{Chapter 1}\label{ch1}
\section{Section 1}\label{sec1}
\subsection{Subsection 1}\label{ssec1}
\subsection{Subsection 2}
\section{Section 2}

\ref{ch1}; \ref{sec1}; \ref{ssec1}

\end{document}

enter image description here

If you also want to remove the number next to the chapter title in the TOC, you can either patch \@makechapterhead or \l@chapter.

The latter method consists in adding

\let\original@l@chapter\l@chapter
\renewcommand{\l@chapter}[2]{%
  \begingroup\let\numberline\@gobble\original@l@chapter{#1}{#2}\endgroup
}

just before \makeatother in the code above.

The other method requires etoolbox:

\documentclass{report}
\usepackage{etoolbox}

\makeatletter
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\p@section}{\thechapter.}
\renewcommand{\p@subsection}{\thechapter.}
\renewcommand{\@seccntformat}[1]{%
  \csname p@#1\endcsname\csname the#1\endcsname\quad
}
\patchcmd{\@chapter}{\numberline}{\@gobble}{}{}
\makeatother


\begin{document}
\tableofcontents

\chapter{Chapter 1}\label{ch1}
\section{Section 1}\label{sec1}
\subsection{Subsection 1}\label{ssec1}
\subsection{Subsection 2}
\section{Section 2}

\ref{ch1}; \ref{sec1}; \ref{ssec1}

\end{document}

enter image description here

You can also get the same with tocloft.

share|improve this answer
    
@Mico That's a job for tocloft, of course. – egreg Feb 21 at 13:23
    
@Mico I added a couple of ways – egreg Feb 21 at 13:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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