# Create custom counter [duplicate]

I want in a document of mine to keep a lot of notes so I would like to create a custom counter so every note to be numbered like this:

0001

0002

0003

0004

(They are deliberately bold as this is the style I would like)

I would like the counter to work like the enumerate environment so to add a keyword in front of the note I want to number and also to be able to reset it.

The reasons I don't use the enumerate environment are:

1. I want the numbers to be bold

2. I want custom formatting of the numbers i.e. 0001 etc...

3. I really want to see how I can create something like that.

## marked as duplicate by Alan Munn, Stefan Pinnow, user13907, Maarten Dhondt, ZarkoAug 24 '16 at 5:37

• Do you mean 'create' your own from scratch, or use a package like fmtcount? – jon Aug 24 '16 at 4:22
• @jon I had no idea that there was a package...Also I don't really know if it is difficult or not. Basically I thought that a counter could be pretty simple if you know what you are doing... – Adam Aug 24 '16 at 4:36
• Related (probably duplicate, since the main issue here is formatting the counter.) You can use it in an environment as you see fit. How to output a counter with leading zeros? – Alan Munn Aug 24 '16 at 4:39
• Well, creating a counter is dead easy: in LaTeX, just \newcounter{xyz} creates a counter called xyz. Padding zeroes so you can get output like: 0001, 0014, 0589, 9999. is a more tricky. – jon Aug 24 '16 at 4:52
• @jon For simplicity's sake I can compromise. How can it be used? – Adam Aug 24 '16 at 5:09

For example, with including the boldness into the appearance of the counter:

\documentclass{article}

\newcounter{custom}
\renewcommand*{\thecustom}{%
\textbf{%
\ifnum\value{custom}<1000 0\fi
\ifnum\value{custom}<100 0\fi
\ifnum\value{custom}<10 0\fi
\arabic{custom}%
}%
}

\begin{document}
\thecustom,
\refstepcounter{custom}\thecustom,
\refstepcounter{custom}\thecustom
\label{abc}

\setcounter{custom}{123}\thecustom,
\setcounter{custom}{7654}\thecustom,
ref: \ref{abc}
\end{document}


An alternative would be to make the numbers bold in the markup macros for the notes only. Then the referenced numbers would appear in normal font.

• Thank you! Every time I have to increase the counter I have to right \refstepcounter{custom}\thecustom? – Adam Aug 24 '16 at 5:35
• @Adam The value of the counter can also be changed by \stepcounter{<counter>} or \addtocounter{<counter>}{<amount>}. Only \refstepcounter allows the counter to be referenced and \label with \ref will work for this counter. – Heiko Oberdiek Aug 24 '16 at 5:50