Text Formatting ⇒ Print Leading Zeros on a Counter
-
- Posts: 1
- Joined: Tue Jul 12, 2011 7:27 pm
Print Leading Zeros on a Counter
I would like to use a counter to automatically include image files (for example, I have images im001.png, im002.ping, ... im999.png). How can I use the counter to correctly get the fact that there are leading zeros in the file names? Is there a way to "print out" a counter (or other variable) with leading zeros in this way?
NEW: TikZ book now 40% off at Amazon.com for a short time.

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Print Leading Zeros on a Counter
Define a counter which tests several conditions like shown below.
To read a single graphics file you then need to insert the counter accordingly.
Best regards and welcome to the board
Thorsten
Code: Select all
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\newcounter{image}
\renewcommand*{\theimage}{%
\ifnum\value{image}<100 0\fi%
\ifnum\value{image}<10 0\fi%
\arabic{image}%
}
\begin{document}
\theimage
\setcounter{image}{10}
\theimage
\setcounter{image}{100}
\theimage
\end{document}
Code: Select all
\includegraphics{im\theimage}
Best regards and welcome to the board
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10