Text Formatting ⇒ Output of a counter BEFORE counting
-
- Posts: 9
- Joined: Sun Feb 26, 2012 3:03 pm
Output of a counter BEFORE counting
Hi,
perhaps this is simple, but I just can't get my head around it... is there a way to output a final counter value before the counter actually starts? For example, an output like:
Item count:2
1. first item
2. second item
I am using MacTex with the XeLaTex processor on TexWorks.
Please help, it is sort of urgent. Thanks
perhaps this is simple, but I just can't get my head around it... is there a way to output a final counter value before the counter actually starts? For example, an output like:
Item count:2
1. first item
2. second item
I am using MacTex with the XeLaTex processor on TexWorks.
Please help, it is sort of urgent. Thanks
NEW: TikZ book now 40% off at Amazon.com for a short time.

-
- Posts: 9
- Joined: Sun Feb 26, 2012 3:03 pm
Re: Output of a counter BEFORE counting
Solved, thanks.
- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
Re: Output of a counter BEFORE counting
Hi,
welcome to the board!
If fellow readers would solve your problem, they would post the solution. Generally it would be good if you would post your solution also if you found it yourself. Imagine, google users would come here searching for their problems and find it discussed, but only a "Solved" without any solution... would be frustrating.
So if you would find the time later, it would be nice if you would add a solution. I guess it could be done by storing the final counter value in the .aux file.
Stefan
welcome to the board!
If fellow readers would solve your problem, they would post the solution. Generally it would be good if you would post your solution also if you found it yourself. Imagine, google users would come here searching for their problems and find it discussed, but only a "Solved" without any solution... would be frustrating.
So if you would find the time later, it would be nice if you would add a solution. I guess it could be done by storing the final counter value in the .aux file.
Stefan
LaTeX.org admin
-
- Posts: 9
- Joined: Sun Feb 26, 2012 3:03 pm
Output of a counter BEFORE counting
So, I didn't solve it after all... I thought the package totcount would help me, but not really. Here is the problem:
If I write something like:
then I can use
On the other hand, if I use
than the items are enumerated correctly (1,2,3...), but I can't seem to use \total{Nature} anywhere.
Any suggestions?
Btw. I am not using
If I write something like:
Code: Select all
Code, edit and compile here:
\vskip 5mm\newtotcounter{Nature}\begin{enumerate}\usecounter{Nature}\item{Blablabla}\end{enumerate}
\total{Nature}
anywhere in the text and it turns out fine. BUT, all the items in the list start with a zero.On the other hand, if I use
Code: Select all
Code, edit and compile here:
\vskip 5mm\begin{enumerate}\newtotcounter{Nature}\item{Blablabla}\end{enumerate}
Any suggestions?
Btw. I am not using
\usepackage{enumerate}
, it is just the usual enumerate
environment.-
- Posts: 9
- Joined: Sun Feb 26, 2012 3:03 pm
Output of a counter BEFORE counting
OK, so here is the simple workaround:
use package totcount and do:
and then you can use
use package totcount and do:
Code: Select all
Code, edit and compile here:
\newtotcounter{Nature}\begin{enumerate}\addtocounter{Nature}{1}\item{Blablabla}\addtocounter{Nature}{1}\item{Second item}\end{enumerate}
\total{Nature}
anywhere in the text and still your enumeration will look fine. Hopefully it helps someone.
Last edited by Stefan Kottwitz on Sun Feb 26, 2012 8:25 pm, edited 1 time in total.
- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
Output of a counter BEFORE counting
Hi,
Thanks for sharing your solution!
Stefan
\stepcounter{Nature}
(or \refstepcounter{Nature}
) would be a bit easier to write.Thanks for sharing your solution!
Stefan
LaTeX.org admin
-
- Posts: 133
- Joined: Sat Feb 25, 2012 6:12 pm
Output of a counter BEFORE counting
Wouldn't it be even nicer to instead of manually adding
Makes it a lot easier. If you use only one counter you could include the counter name in the macro of course, but then I'd rename the new command a bit to distinguish it better from the default \item.
\addtocounter
every item declare a macro, for example:Code: Select all
Code, edit and compile here:
\documentclass{amsart}\usepackage{totcount}\newcommand{\Item}[1]{\stepcounter{#1}\item}\begin{document}\total{Nature}\newtotcounter{Nature}\begin{enumerate}\Item{Nature}Blablabla\Item{Nature}Second item\end{enumerate}\end{document}
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
Output of a counter BEFORE counting
You could set the total counter to be the most recent value of the enumerate counter
Stefan
enumi
:Code: Select all
Code, edit and compile here:
\documentclass{article}\usepackage{totcount}\newtotcounter{Nature}\begin{document}The total number will be \total{Nature}.\begin{enumerate}\item{First item}\item{Second item}\item{Third item}\item{Fourth item}\end{enumerate}\setcounter{Nature}{\value{enumi}}\end{document}
LaTeX.org admin
- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
Output of a counter BEFORE counting
hugovdberg wrote:Wouldn't it be even nicer to instead of manually adding\addtocounter
every item declare a macro
Good idea, which is flexible.
If each item of an environment would be counted, it would be good to define a new enumerate environment (with a different name) which works like
enumerate
but updates the total counter in the environment's end definition, as in my previous post.Stefan
LaTeX.org admin
-
- Posts: 133
- Joined: Sat Feb 25, 2012 6:12 pm
Output of a counter BEFORE counting
When defining a new environment you should probably useStefan_K wrote:hugovdberg wrote:Wouldn't it be even nicer to instead of manually adding\addtocounter
every item declare a macro
Good idea, which is flexible.
If each item of an environment would be counted, it would be good to define a new enumerate environment (with a different name) which works likeenumerate
but updates the total counter in the environment's end definition, as in my previous post.
Stefan
\addtocounter
and not \setcounter
in case you want to use two lists which total to the same counter. When you have only one list this makes no difference as the initial value is zero anyway, am I wrong?Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit