General ⇒ Understanding Counters
Understanding Counters
I'd also like to know how to display counters by themselves. I've only been able to use them in conjunction with other objects, but I'd like to display counters alone.
Any example code would be greatly appreciated.
Links to information on counters would also help.
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
Understanding Counters
the following example contains the definition of a counter and illustrates the basic commands for manipulation of counters (the comments are explanatory):
Code: Select all
\documentclass{article}
% declare a new counter
\newcounter{MyCount}
% a command to report the value of the counter
% using \the as prefix you can get the value of the counter
\newcommand\MyCValue{\noindent The value of \texttt{MyCount} is \theMyCount\par}
\begin{document}
\MyCValue
% increase the value of the counter
\stepcounter{MyCount}
\MyCValue
% add some value to a counter
\addtocounter{MyCount}{5}
\MyCValue
% change the representation of the counter from arabic to Alphabetic
% you can use \alph, \Alph, \Roman, \roman, and \arabic (default)
\renewcommand\theMyCount{\Alph{MyCount}}
\MyCValue
% set the value of a counter
\setcounter{MyCount}{3}
\MyCValue
\end{document}
Re: Understanding Counters

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Understanding Counters
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10