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.

I'd like to have in my document the main parts (chapter, section) not numbered, but having numbered subsections and subsubsections. I'd like that the numbers restart in each new unit.

I was trying to change the numbering by adding to preable:

\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}

but the numbering continue in whole document and don't restart in each section, I guess it restarts after each numbered section of a higher level.

What I'd like to achive is to have in the body of document *chapter and *section; subsubsection always numbered and subsection sometimes starred, sometimes not.

Here is minimal working example:

\documentclass{book}
\usepackage{fontspec}
\usepackage{polyglossia}

\setmainlanguage{polish}
\setotherlanguage[locale=mashriq]{arabic}
\setromanfont[Mapping=tex-text]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.3,Mapping=arabicdigits]{Scheherazade}

\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{0}

\begin{document}

\chapter*{Pierwszy}
\addcontentsline{toc}{chapter}{Pierwszy}

\section*{Jakaś część}
\subsection{To też}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection{I to również}
\subsubsection{ccc}
\subsubsection{dddd}

\section*{Inna część}
\subsection*{A to podpunkt}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection*{I to}
\subsubsection{ccc}
\subsubsection{dddd}



\chapter*{Drugi}
\addcontentsline{toc}{chapter}{Drugi}

\section*{Jakaś część}
\subsection*{To też}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection*{I to również}
\subsubsection{ccc}
\subsubsection{dddd}

\section*{Inna część}
\subsection{A to podpunkt}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection{I to}
\subsubsection{ccc}
\subsubsection{dddd}

\tableofcontents

\end{document}

Maybe I'm trying to achive what I wont with wrong tool. Thanks for any hints.

share|improve this question
1  
I don't think packages like fontspec and polyglossia are relevant, you can remove them (as well as their options) from your example, so that one doesn't need xetex to compile the MWE. –  T. Verron Dec 5 '12 at 17:00
    
What should happen to the subsubsection counter when you use \subsection*? Should it reset or not? –  Werner Dec 5 '12 at 17:07
    
@T.Verron I could remove it if my goal was only compile the MWE, but I need this solution to compile a document where I do need xetex. That's why I'm keeping fontspec and polyglossia here. –  maria Dec 5 '12 at 17:10
    
@Werner Starred versions give no numbering in the output. And I would like to have subsubsections numbered... –  maria Dec 5 '12 at 17:12
    
@maria: That doesn't answer the question. What should happen to the counter associated with \subsubsection when you have an unnumbered (or starred) \subsection? Typically, using \subsection would restart the \subsubsection counter, while using \subsection* would not restart the \subsubsection counter. –  Werner Dec 5 '12 at 17:18
show 1 more comment

1 Answer 1

up vote 8 down vote accepted

I don't really think this is a good idea, but the book is yours. The numbers should help readers in orienting themselves in the book.

But here's a way to do it.

\documentclass{book}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{fancyhdr} % this is necessary
\usepackage{kantlipsum} % this is only to provide mock text

\setmainlanguage{polish}
\setmainfont[Ligatures=TeX]{Linux Libertine O}

\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{0}

%%% ADDED CODE
\makeatletter
\def\@seccntformat#1{\csname mythe#1\endcsname}
\def\mythesubsection{\thesubsection\quad}
\def\mythesubsubsection{\thesubsubsection\quad}
\let\latex@subsection\subsection
\def\subsection{\@ifstar{\refstepcounter{subsection}\latex@subsection*}{\latex@subsection}}
\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}
\let\latex@l@chapter\l@chapter
\def\l@chapter#1#2{\begingroup\let\numberline\@gobble\latex@l@chapter{#1}{#2}\endgroup}
\makeatother

\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE]{\slshape\leftmark}
\fancyhead[LO]{\slshape\rightmark}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}
%%% END ADDED CODE

\begin{document}

\chapter{Pierwszy}

\section{Jakaś część}
\subsection{To też}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection{I to również}
\subsubsection{ccc}
\subsubsection{dddd}

\section{Inna część}
\subsection*{A to podpunkt}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection*{I to}
\subsubsection{ccc}
\subsubsection{dddd}



\chapter{Drugi}

\section{Jakaś część}
\subsection*{To też}
\subsubsection{aaa}
\kant[1]

\subsubsection{bbb}
\kant[1]

\subsection*{I to również}
\subsubsection{ccc}
\kant[1]

\subsubsection{dddd}
\kant


\section{Inna część}
\subsection{A to podpunkt}
\subsubsection{aaa}
\subsubsection{bbb}
\subsection{I to}
\subsubsection{ccc}
\subsubsection{dddd}

\tableofcontents

\end{document}

Some explanations are in order.

  1. The easiest and best documented hack is the one with fancyhdr, where the way the headers are defined is set. The hack consists in removing the "Chapter n" or section number bit from the headers by redefining \chaptermark and \sectionmark.

  2. Each sectioning command from \section and below executes \@seccntformat{<level>}, where <level> stands for section, subsection and so on. The usual definition is

    \def\@seccntformat#1{\csname the#1\endcsname\quad}
    

    and I redefine it as

    \def\@seccntformat#1{\csname mythe#1\endcsname}
    

    so \mythesection and so on will be executed in turn or nothing at all if the command is not defined. Therefore it's sufficient to define \mythesubsection and \mythesubsubsection.

  3. I redefine also \@makechapterhead, removing the part where "Chapter n" is set.

  4. \subsection is redefined so that the number is stepped anyway. One might prefer

    \def\subsection{%
      \@ifstar
        {\setcounter{subsubsection}{0}\latex@subsection*}
        {\latex@subsection}}
    

    so that the subsection number is not stepped, but only the subsubsection counter is reset to 0.

  5. Finally \l@chapter is modified so that \numberline will ignore its argument and the chapter number will not appear in the table of contents.

share|improve this answer
1  
+1 for "not a good idea" –  Brent.Longborough Dec 5 '12 at 17:12
    
@egreg Thanks a lot, it works now exactly how I wanted! As for letting main parts of document unnumbered, I agree with you, but here I have some special thing to do and it would really be more clear like that. –  maria Dec 5 '12 at 17:33
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.