Text Formatting ⇒ Output of a counter BEFORE counting
-
- Posts: 9
- Joined: Sun Feb 26, 2012 3:03 pm
Output of a counter BEFORE counting
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.
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
-
- Posts: 9
- Joined: Sun Feb 26, 2012 3:03 pm
Re: Output of a counter BEFORE counting
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
Re: Output of a counter BEFORE counting
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
-
- Posts: 9
- Joined: Sun Feb 26, 2012 3:03 pm
Output of a counter BEFORE counting
If I write something like:
Code: Select all
\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
\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
use package totcount and do:
Code: Select all
\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.- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
Output of a counter BEFORE counting
\stepcounter{Nature}
(or \refstepcounter{Nature}
) would be a bit easier to write.Thanks for sharing your solution!
Stefan
-
- Posts: 133
- Joined: Sat Feb 25, 2012 6:12 pm
Output of a counter BEFORE counting
\addtocounter
every item declare a macro, for example:Code: Select all
\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}
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
Output of a counter BEFORE counting
enumi
:Code: Select all
\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}
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- 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
-
- 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?