GeneralUnderstanding Counters

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
generator
Posts: 9
Joined: Sat Apr 03, 2010 5:56 am

Understanding Counters

Post by generator »

I'd like to know how to set up custom counters. It seems that every counter I create has a section number attached. I'd like to be able to create a counter that doesn't have additional numbers attached.

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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Understanding Counters

Post by gmedina »

Hi,

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}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
generator
Posts: 9
Joined: Sat Apr 03, 2010 5:56 am

Re: Understanding Counters

Post by generator »

Thanks! That solves my problems :D
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Understanding Counters

Post by localghost »

Now that the problem is solved, please be so kind and mark the topic accordingly as clearly written in Section 3 of the Board Rules (to be read before posting). Please keep that in mind for the future so that further reminders will not be necessary.


Thorsten
Post Reply