# Reset counter \section in \part*

I'm a rookie with LaTeX, I'm using LyX, but I think this is a LaTeX problem.

Im using this LaTeX preamble for reset counter after parts

\usepackage{chngcntr}
\counterwithin*{section}{part}


But it only works with \part and no with \part*... I need to have no-numbered parts. What can I do? I don't find anything on the net and my attempts don't work (counterwith, part*...).

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Reinstate Monica - M. Schröder Oct 4 '15 at 15:17
• you're right, since \part* doesn't step the part counter. we need more informations about class used. – touhami Oct 4 '15 at 15:19
• Here's some questions which address similar issues, numbering one counter within starred and unstarred versions of another: 1 2 3 – Arun Debray Oct 4 '15 at 15:21
• Do you always use unnumbered parts? – Werner Oct 4 '15 at 15:26
• Thanks all, but Christian answer works like a charm :D. – analca3 Oct 4 '15 at 15:34

## 1 Answer

This works for article.cls \parts since there are no \chapters which must be reset too. It's regardless whether \part or \part* is used, the \setcounter{section}{0} just before \part does no harm and is done automatically here.

\documentclass{article}

%\usepackage{chngcntr}
%\counterwithin*{section}{part}

\usepackage{xpatch}

\xpretocmd{\part}{\setcounter{section}{0}}{}{}

\begin{document}

\part*{A part}

\section{A section in part}
\section{Another section in part}

\part*{Another part}

\section{A section in another part}

\section{Another section in another part}

\end{document}


• @analca3: It works even without LyX (;-) – user31729 Oct 4 '15 at 15:36
• \setcounter{section}{-1}\stepcounter{section} is better – touhami Oct 4 '15 at 15:36
• @touhami: Why? I don't suppose that somebody will need a \label to the section just before \part starts. – user31729 Oct 4 '15 at 15:40
• just in case some one start the part with subsection this help to reset all counters. (by the way for crossreference one need \refstepcounter, but you know that) – touhami Oct 4 '15 at 15:43
• @touhami: Yes, \refstepcounter -- I was confused for a moment. But since the format updates the underlying counters (subsection) are reset even with setcounter. – user31729 Oct 4 '15 at 15:48