How to display chapter/section counter value?
up vote
2
down vote
favorite
I'm building a documentclass[...]{book}
latex file. Each chapter has some sections. Each section has some exercises. The exercises are displayed on exercise
command. In the preamble I did:
newcommand{exercise}{
paragraph{Exercício x}
}
How can I set x = chapter . section . mycounter
?
The mycounter
counter has to reset at beginning of each new section (I don't care about chapter because all exercises will be inside a section).
Thanks in advance.
counters
New contributor
add a comment |
up vote
2
down vote
favorite
I'm building a documentclass[...]{book}
latex file. Each chapter has some sections. Each section has some exercises. The exercises are displayed on exercise
command. In the preamble I did:
newcommand{exercise}{
paragraph{Exercício x}
}
How can I set x = chapter . section . mycounter
?
The mycounter
counter has to reset at beginning of each new section (I don't care about chapter because all exercises will be inside a section).
Thanks in advance.
counters
New contributor
thechapter.thesection.themycounter
? or better definethemycounter
asrenecommand{thechapter.thesection.arabic{mycounter}}
. welcome to tex.se!
– Zarko
2 days ago
@Zarko Under normal circumstancesthesection
already prints the chapter number, sothechapter.thesection
would duplicate the chapter number.
– Phelype Oleinik
2 days ago
@PhelypeOleinik, well, you explain this in your answer. but not knowing anything about op document, it is difficult to say what is usual ... :-).
– Zarko
2 days ago
@Zarko I completely agree :-)
– Phelype Oleinik
2 days ago
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm building a documentclass[...]{book}
latex file. Each chapter has some sections. Each section has some exercises. The exercises are displayed on exercise
command. In the preamble I did:
newcommand{exercise}{
paragraph{Exercício x}
}
How can I set x = chapter . section . mycounter
?
The mycounter
counter has to reset at beginning of each new section (I don't care about chapter because all exercises will be inside a section).
Thanks in advance.
counters
New contributor
I'm building a documentclass[...]{book}
latex file. Each chapter has some sections. Each section has some exercises. The exercises are displayed on exercise
command. In the preamble I did:
newcommand{exercise}{
paragraph{Exercício x}
}
How can I set x = chapter . section . mycounter
?
The mycounter
counter has to reset at beginning of each new section (I don't care about chapter because all exercises will be inside a section).
Thanks in advance.
counters
counters
New contributor
New contributor
New contributor
asked 2 days ago
Enrique René
134
134
New contributor
New contributor
thechapter.thesection.themycounter
? or better definethemycounter
asrenecommand{thechapter.thesection.arabic{mycounter}}
. welcome to tex.se!
– Zarko
2 days ago
@Zarko Under normal circumstancesthesection
already prints the chapter number, sothechapter.thesection
would duplicate the chapter number.
– Phelype Oleinik
2 days ago
@PhelypeOleinik, well, you explain this in your answer. but not knowing anything about op document, it is difficult to say what is usual ... :-).
– Zarko
2 days ago
@Zarko I completely agree :-)
– Phelype Oleinik
2 days ago
add a comment |
thechapter.thesection.themycounter
? or better definethemycounter
asrenecommand{thechapter.thesection.arabic{mycounter}}
. welcome to tex.se!
– Zarko
2 days ago
@Zarko Under normal circumstancesthesection
already prints the chapter number, sothechapter.thesection
would duplicate the chapter number.
– Phelype Oleinik
2 days ago
@PhelypeOleinik, well, you explain this in your answer. but not knowing anything about op document, it is difficult to say what is usual ... :-).
– Zarko
2 days ago
@Zarko I completely agree :-)
– Phelype Oleinik
2 days ago
thechapter.thesection.themycounter
? or better define themycounter
as renecommand{thechapter.thesection.arabic{mycounter}}
. welcome to tex.se!– Zarko
2 days ago
thechapter.thesection.themycounter
? or better define themycounter
as renecommand{thechapter.thesection.arabic{mycounter}}
. welcome to tex.se!– Zarko
2 days ago
@Zarko Under normal circumstances
thesection
already prints the chapter number, so thechapter.thesection
would duplicate the chapter number.– Phelype Oleinik
2 days ago
@Zarko Under normal circumstances
thesection
already prints the chapter number, so thechapter.thesection
would duplicate the chapter number.– Phelype Oleinik
2 days ago
@PhelypeOleinik, well, you explain this in your answer. but not knowing anything about op document, it is difficult to say what is usual ... :-).
– Zarko
2 days ago
@PhelypeOleinik, well, you explain this in your answer. but not knowing anything about op document, it is difficult to say what is usual ... :-).
– Zarko
2 days ago
@Zarko I completely agree :-)
– Phelype Oleinik
2 days ago
@Zarko I completely agree :-)
– Phelype Oleinik
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You have to define a counter exercise
with newcounter{exercise}
, then you say that it restarts at every section with counterwithin{exercise}{section}
.
To make thesection
(which prints the value of the section) to be chapter.section.exercise
you can use thesection.arabic{exercise}
because thesection
is already defined to print chapter.section
. Of course you could also use arabic{chapter}.arabic{section}.arabic{exercise}
, but then if any of them happened to be, for instance, with roman numbers, it would look inconsistent.
Finally, at each exercise you use refstepcounter{exercise}
to add one to it, and print theexercise
.
documentclass{book}
usepackage{lipsum}
newcounter{exercise}
counterwithin{exercise}{section}
renewcommandtheexercise{%
thesection.arabic{exercise}%
}
newcommand{exercise}{%
refstepcounter{exercise}%
paragraph{Exercício~theexercise}
}
begin{document}
chapter{I don't care about}
section{This section}
exercise lipsum[1]
exercise lipsum[2]
section{Another section}
exercise lipsum[3]
end{document}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You have to define a counter exercise
with newcounter{exercise}
, then you say that it restarts at every section with counterwithin{exercise}{section}
.
To make thesection
(which prints the value of the section) to be chapter.section.exercise
you can use thesection.arabic{exercise}
because thesection
is already defined to print chapter.section
. Of course you could also use arabic{chapter}.arabic{section}.arabic{exercise}
, but then if any of them happened to be, for instance, with roman numbers, it would look inconsistent.
Finally, at each exercise you use refstepcounter{exercise}
to add one to it, and print theexercise
.
documentclass{book}
usepackage{lipsum}
newcounter{exercise}
counterwithin{exercise}{section}
renewcommandtheexercise{%
thesection.arabic{exercise}%
}
newcommand{exercise}{%
refstepcounter{exercise}%
paragraph{Exercício~theexercise}
}
begin{document}
chapter{I don't care about}
section{This section}
exercise lipsum[1]
exercise lipsum[2]
section{Another section}
exercise lipsum[3]
end{document}
add a comment |
up vote
1
down vote
accepted
You have to define a counter exercise
with newcounter{exercise}
, then you say that it restarts at every section with counterwithin{exercise}{section}
.
To make thesection
(which prints the value of the section) to be chapter.section.exercise
you can use thesection.arabic{exercise}
because thesection
is already defined to print chapter.section
. Of course you could also use arabic{chapter}.arabic{section}.arabic{exercise}
, but then if any of them happened to be, for instance, with roman numbers, it would look inconsistent.
Finally, at each exercise you use refstepcounter{exercise}
to add one to it, and print theexercise
.
documentclass{book}
usepackage{lipsum}
newcounter{exercise}
counterwithin{exercise}{section}
renewcommandtheexercise{%
thesection.arabic{exercise}%
}
newcommand{exercise}{%
refstepcounter{exercise}%
paragraph{Exercício~theexercise}
}
begin{document}
chapter{I don't care about}
section{This section}
exercise lipsum[1]
exercise lipsum[2]
section{Another section}
exercise lipsum[3]
end{document}
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You have to define a counter exercise
with newcounter{exercise}
, then you say that it restarts at every section with counterwithin{exercise}{section}
.
To make thesection
(which prints the value of the section) to be chapter.section.exercise
you can use thesection.arabic{exercise}
because thesection
is already defined to print chapter.section
. Of course you could also use arabic{chapter}.arabic{section}.arabic{exercise}
, but then if any of them happened to be, for instance, with roman numbers, it would look inconsistent.
Finally, at each exercise you use refstepcounter{exercise}
to add one to it, and print theexercise
.
documentclass{book}
usepackage{lipsum}
newcounter{exercise}
counterwithin{exercise}{section}
renewcommandtheexercise{%
thesection.arabic{exercise}%
}
newcommand{exercise}{%
refstepcounter{exercise}%
paragraph{Exercício~theexercise}
}
begin{document}
chapter{I don't care about}
section{This section}
exercise lipsum[1]
exercise lipsum[2]
section{Another section}
exercise lipsum[3]
end{document}
You have to define a counter exercise
with newcounter{exercise}
, then you say that it restarts at every section with counterwithin{exercise}{section}
.
To make thesection
(which prints the value of the section) to be chapter.section.exercise
you can use thesection.arabic{exercise}
because thesection
is already defined to print chapter.section
. Of course you could also use arabic{chapter}.arabic{section}.arabic{exercise}
, but then if any of them happened to be, for instance, with roman numbers, it would look inconsistent.
Finally, at each exercise you use refstepcounter{exercise}
to add one to it, and print theexercise
.
documentclass{book}
usepackage{lipsum}
newcounter{exercise}
counterwithin{exercise}{section}
renewcommandtheexercise{%
thesection.arabic{exercise}%
}
newcommand{exercise}{%
refstepcounter{exercise}%
paragraph{Exercício~theexercise}
}
begin{document}
chapter{I don't care about}
section{This section}
exercise lipsum[1]
exercise lipsum[2]
section{Another section}
exercise lipsum[3]
end{document}
answered 2 days ago
Phelype Oleinik
20.2k54277
20.2k54277
add a comment |
add a comment |
Enrique René is a new contributor. Be nice, and check out our Code of Conduct.
Enrique René is a new contributor. Be nice, and check out our Code of Conduct.
Enrique René is a new contributor. Be nice, and check out our Code of Conduct.
Enrique René is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460488%2fhow-to-display-chapter-section-counter-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
thechapter.thesection.themycounter
? or better definethemycounter
asrenecommand{thechapter.thesection.arabic{mycounter}}
. welcome to tex.se!– Zarko
2 days ago
@Zarko Under normal circumstances
thesection
already prints the chapter number, sothechapter.thesection
would duplicate the chapter number.– Phelype Oleinik
2 days ago
@PhelypeOleinik, well, you explain this in your answer. but not knowing anything about op document, it is difficult to say what is usual ... :-).
– Zarko
2 days ago
@Zarko I completely agree :-)
– Phelype Oleinik
2 days ago