LyXHow to reset section numbering by part?

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
idoshlom
Posts: 7
Joined: Fri Feb 21, 2014 1:38 pm

How to reset section numbering by part?

Post by idoshlom »

Hello,

I'm using the article class, and I would like the section numbering to restart after every Part.
Specifically, I want something like this:
PART I
Section 1
Section 2
...

PART II
Section 1
Section 2
...

I know that I can do this by inserting some LATEX code into the preamble, but I have no idea how to do this.

Help much appreciated!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to reset section numbering by part?

Post by Johannes_B »

Code: Select all

\documentclass{article}
\usepackage{blindtext}
\usepackage{chngcntr}
\counterwithin*{section}{part}
\begin{document}
\part{some thing}
\section{words}
\blindtext
\section{numbers}
\blindtext
\part{some other}
\section{trees}
\blindtext
\section{mobile phones}
\blindtext
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
idoshlom
Posts: 7
Joined: Fri Feb 21, 2014 1:38 pm

Re: How to reset section numbering by part?

Post by idoshlom »

Hey, thanks for the reply, but I'm not quite sure how to use this code. I tried simply copy-pasting it into the preamble but it didn't work. What should I be doing?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to reset section numbering by part?

Post by Johannes_B »

This is a complete minimal example, this is valent LaTeX code. There are not only LyX people around.

LyX produces stuff like that in the background, you never see it. But in this case you need to add

Code: Select all

\usepackage{chngcntr}
\counterwithin*{section}{part}
to your preamble.

BTW: You can click on »Open in writelatex« above the full example above to see the output.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
idoshlom
Posts: 7
Joined: Fri Feb 21, 2014 1:38 pm

Re: How to reset section numbering by part?

Post by idoshlom »

OK I understand.
I hit "Open in writelatex" on the first code you posted and it's exactly what I need.
As for the lyx code you posted, I added it to the preamble but that still didn't work for some reason :(

I attached below a screenshot of the preamble box, and of the lyx output that still numbers the second section as "2".
Attachments
Untitled.png
Untitled.png (127.74 KiB) Viewed 37321 times
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: How to reset section numbering by part?

Post by Johannes_B »

I don't have LyX installed, so i can't test anything.

What happens if you export to pdf?

You might need to wait, till someone with more LyX experience comes along.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
idoshlom
Posts: 7
Joined: Fri Feb 21, 2014 1:38 pm

Re: How to reset section numbering by part?

Post by idoshlom »

Weird: Exporting to PDF actually displays the correct form, meaning both sections are labeled "1"...!
This is still not a perfect fix since I like using Lyx because I can see the formatting in the lyx document itself (in which it is incorrect).
Thanks very much for your help!
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: How to reset section numbering by part?

Post by Johannes_B »

LyX and LaTeX are seperated systems. LyX does things, creates a tex-file and LaTeX typesets it. With the code above, you put just the things needed to the tex. This is completely independent of LyX. If you want to have this implemented directly (visibly) in LyX, please send a mail to the LyX-support team.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
StarValkyrie
Posts: 89
Joined: Fri Jan 24, 2014 12:42 am

How to reset section numbering by part?

Post by StarValkyrie »

What's happening is that, behind the scenes, there's a layout file that tells LyX what to put on the screen and that still has the old counters in it. Luckily this is a really simple fix because LyX has this feature called Local Layout so you can change the layout just for this one document. Go into Document Settings, select Local Layout from the list, paste the contents of the Code section below into the box and click the Validate button, then click OK.

Code: Select all

Counter section
        Within               part
End
idoshlom
Posts: 7
Joined: Fri Feb 21, 2014 1:38 pm

Re: How to reset section numbering by part?

Post by idoshlom »

Hi, thanks very much!
The combination of both of your solutions is perfect.
If I could add another minor question - is there a way to reset the equation numbering as well? So that it begins numbering from (1) every new Part?

Again thanks alot!
Post Reply