I have the following code to get a beautiful concept boxes with optional header for every new concept discussed. The code changes the concept number using the counter but I also need to reset it to 1 again in the next chapter. The code is being taken from this group only, hence not everything i understand in it. Kindly help what needs to be done to reset the counter variable "theorem" to 1 again in the next chapter.

    % Preview preamble

    %% LyX 2.0.4 created this file.  For more info, see http://www.lyx.org/.
    %% Do not edit unless you really know what you are doing.


    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.



    left=30mm, %% or inner=20mm
    right=15mm, %% or outer=15mm
    top=30mm, bottom=25mm,


    \draw[overlay,remember picture,opacity=0.5] node [right,text width=15cm, rounded corners, fill=gray!30, inner sep=2ex]{};
    \draw[thick,overlay,remember picture, gray!50] (0,-.1)--(12.8,-.1);
    \draw[ultra thick,overlay,remember picture, gray!70] (0,-.2)--(12.8,-.2);
    \draw[thick,overlay,remember picture, gray!40] (0,-.3)--(12.8,-.3);
    \draw[ultra thick,overlay,remember picture,gray!70] (0,-.2) -- (-20,-.2);
    \shade[yshift=6pt,ball color=gray,overlay] (0,-.2) circle (9pt);

    %\draw[overlay,remember picture,opacity=0.5] node [right,text width=12cm, rounded corners, fill=gray!50, inner sep=2ex]{};
    \draw[yshift=-2pt,remember picture, line width=2pt, overlay, gray!30, rounded corners] (12,-.4) -- (0,-.4) -- (0,.8)  -- (12,.8) -- cycle;
    \draw[thick,overlay,remember picture, gray!50] (0,-.1)--(12,-.1);
    \draw[ultra thick,overlay,remember picture, gray!70] (0,-.2)--(20,-.2);
    \draw[thick,overlay,remember picture, gray!40] (0,-.3)--(12,-.3);
    \draw[ultra thick,overlay,remember picture,gray!70] (0,-.2) -- (-20,-.2);
    \shade[ball color=gray!90,overlay] (0,-.2) circle (3pt);
    \shade[ball color=gray!90,overlay] (12,-.2) circle (3pt);

    \draw[yshift=6pt,overlay,remember picture,opacity=0.5] node [right,text width=15.5cm, rounded corners, fill=gray!30, inner sep=15pt]{};
    \draw[yshift=-2pt,remember picture, line width=4pt, overlay, gray, rounded corners] (16,-.4) -- (-0.5,-.4) -- (-0.5,1)  -- (16,1) -- cycle;
    \shade[overlay,ball color=gray] (16,0.2) circle (8pt);

    \draw[overlay,remember picture,opacity=0.5] node [right,text width=0.4\textwidth, rounded corners, fill=gray!30, inner sep=2ex]{};
    \draw[thick,overlay,remember picture, gray!50] (0,-.1)--(7.5,-.1);
    \draw[ultra thick,overlay,remember picture, gray!70] (0,-.2)--(7.5,-.2);
    \draw[thick,overlay,remember picture, gray!40] (0,-.3)--(7.5,-.3);
    %\draw[ultra thick,overlay,remember picture,gray!70] (0,-.2) -- (-20,-.2);
    \shade[yshift=6pt,ball color=gray,overlay] (0,-.2) circle (8pt);
    \shade[ball color=gray,overlay](7.5,0) circle (8pt);

    %%%%%%%% This is to get a Concept


   %  this is the start of the code which is our interest 

    \renewcommand\thetheorem{Concept ~\arabic{theorem}}
          \node[anchor=west,rounded corners,draw,thick,shading=axis,left color=gray!20,xshift=10cm,minimum height=.7cm,minimum width=2cm] at (P-|O) 
    tikzsetting={shading=axis,top color=gray!10},


   %%  this is the end of the code which is of our interest 


    \chapter{chapter one}
    first chapter first concept
    \chapter{chapter two}
    second chapter first concept

This is a code created by Lyx

The counter code is commented as code required by us above. And the counter variable to reset is named "theorem"

  • It would really be helpful if you used this code to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Oct 6 '12 at 6:10
  • 1
    I tried adding a standard preamble and making an example document, but it doesn't compile. Please, transform this into a minimal example that can be run. – egreg Oct 6 '12 at 8:23
  • I have rewritten the complete code so that it would help everybody trying to help me. – nichas Oct 6 '12 at 9:01

I don't know how to do this with LyX. However, in order that the theorem number is reset at every chapter, the definition should be


This will number theorems as "chapter.theorem", so the first theorem in chapter one will be "1.1" and the third in chapter two will be "2.3". If you want the chapter number only, issue


just after the previous declaration.

| improve this answer | |
  • This works best for me. It reorders the numbering of the Illustration back to 1 in every new chapter. – nichas Oct 11 '12 at 5:58

When you specify a new counter, you can use the optional argument to reset this new counter whenever an old counter is stepped: \newcounter{newcounter}[oldcounter]. This means that every time oldcounter is stepped, newcounter is reset to zero. If you want to add such behaviour to a counter that already exists (e.g. provided by some package) or you want to remove such behaviour (e.g. all sections have increasing numbers even after a new chapter command), you can use the chngcntr package, which provides the commands \counterwithin and \counterwithout.





















enter image description here

| improve this answer | |

I am not sure from your code which counter needs resetting, but here is a way to automatically reset a counter at the start of a chapter. We copy the existing definition of \chapter to \OldChapter:


Now, change the chapter macro to first set the value of myCounter to 1 as desired, then resssue the previous defintion of what was chapter (but now available as OldChapter:


So in the example below I set the counter to 50 before the chapter, and the output we get is:

enter image description here






Counter at start of chapter is \arabic{myCounter}

Counter before start of chapter is \arabic{myCounter}

Counter at start of chapter is \arabic{myCounter}

| improve this answer | |
  • 2
    I think you can use \newcounter{myCounter}[chapter] to reset it. – Tom Bombadil Oct 6 '12 at 6:19
  • 1
    @TomBombadil: Well, where is the fun in that!! :-) Did not know about that, so thanks. However, that resets it to 0, not 1 as desired. But perhaps it should actually be 0 as it might be incremented prior to use. – Peter Grill Oct 6 '12 at 6:21
  • The idea suggested by Tom Bombadil works for me. \newcounter{myCounter}[chapter] – nichas Oct 6 '12 at 10:05
  • 1
    @nichas: If you want to add/remove such behaviour to/from a counter that already exists, you can use the commands \counterwithin and \counterwithout from the chngcntr package. – Tom Bombadil Oct 6 '12 at 12:26
  • @TomBombadil: You want to post your comments as an answers as it seems that is what the OP is using. – Peter Grill Oct 10 '12 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.