Text FormattingOutput of a counter BEFORE counting

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Output of a counter BEFORE counting

Post by Stefan Kottwitz »

hugovdberg wrote: When defining a new environment you should probably use \addtocounter and not \setcounter in case you want to use two lists which total to the same counter.
Yes, something like this. The exact way depends on the requirements, but here's a way for summarizing counters also over several environments.

Code: Select all

\documentclass{article}
\usepackage{totcount}
\newtotcounter{Nature}
\newtotcounter{Other}
\newcommand{\currentcountername}{}
\newenvironment{totenumerate}[2][0]{%
  \renewcommand{\currentcountername}{#2}
  \setcounter{\currentcountername}{#1}%
  \enumerate}{%
  \endenumerate%
  \addtocounter{\currentcountername}{\value{enumi}}
}  
\begin{document}
\noindent The total number will be \total{Nature},
the number together with all others is \total{Other}.
\begin{totenumerate}{Nature}
  \item{First item}
  \item{Second item}
  \item{Third item}
  \item{Fourth item}
\end{totenumerate}
More to follow:
\begin{totenumerate}[\value{Nature}]{Other}
  \item{First other item}
  \item{Second other item}
\end{totenumerate}
\end{document}
Stefan
LaTeX.org admin

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

Post Reply