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: 10360
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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Post Reply