Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\documentclass[11pt]{book}
\usepackage[svgnames]{xcolor}
\makeatletter
\let\stdl@section\l@section
\renewcommand*{\l@section}[2]{%
  \stdl@section{\textcolor{blue}{#1}}{\textcolor{blue}{#2}}}
\let\stdl@subsection\l@subsection
\renewcommand*{\l@subsection}[2]{%
  \stdl@subsection{\textcolor{DarkGreen}{#1}}{\textcolor{DarkGreen}{#2}}}
\makeatother
\setcounter{tocdepth}{2}
\begin{document}
\tableofcontents

\chapter*{chapter1}
\addcontentsline{toc}{chapter}{Chapter1}
\section{Section One}
\subsection{Subsection One}
\subsection{Subsection Two}
\section{Section Two}
\subsection{Subsection One}
\subsection{Subsection Two}
\end{document}

Now it has a preceding zero in front of the section numbers. How can I get rid of zero. For reference I am attaching an image as well. enter image description here

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

this will get rid of the zero and period in both the toc and the body of the document:

\makeatletter
\renewcommand{\thesection}{%
  \ifnum\c@chapter<1 \@arabic\c@section
  \else \thechapter.\@arabic\c@section
  \fi
}
\makeatother

this assumes that the chapter counter is already properly defined, as it is in the book and report classes.

share|improve this answer
    
It worked great, thanks –  Aku Feb 20 '12 at 17:01
add comment

Add this to your preamble:

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

This line above removes the chapter number from the section number. Unchanged, this would look something like

\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}

The changed output:

screenshot 1

and

screenshot 2

share|improve this answer
    
it worked as well, thank you –  Aku Feb 20 '12 at 17:01
add comment

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.