7

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*...).

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

1 Answer 1

10

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}

enter image description here

5
  • @analca3: It works even without LyX (;-)
    – user31729
    Commented Oct 4, 2015 at 15:36
  • 1
    \setcounter{section}{-1}\stepcounter{section} is better
    – touhami
    Commented Oct 4, 2015 at 15:36
  • @touhami: Why? I don't suppose that somebody will need a \label to the section just before \part starts.
    – user31729
    Commented Oct 4, 2015 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
    Commented Oct 4, 2015 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
    Commented Oct 4, 2015 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .