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

29antonioac
  • 195
  • 1
  • 6

1 Answers1

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

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