
Gostaria de incluir gráficos que tenham um nome de arquivo com zeros à esquerda. Os nomes dos arquivos são:
pic_001_test.png pic_002_test.png . . . pic_028_test.png
Consigo gerar zeros à esquerda em a, \forloop
mas não consigo usá-los no \includegraphics
comando:
\documentclass{article}
\usepackage{forloop}
\usepackage{graphicx}
\usepackage{fmtcount}
\begin{document}
\newcommand{\filename}{}
\newcounter{i}
\forloop{i}{1}{\value{i} < 4}{
\begin{figure}
\renewcommand{\filename}{pic\_\padzeroes[3]{\decimal{i}}\_test.pdf}
\includegraphics[scale=0.6]{pic_00\arabic{i}_test.png}
\caption{Screenshot\_\arabic{i}}
\filename
\end{figure}
}
\end{document}
O código a seguir não funciona devido a "! sequência de controle indefinida":
\newcommand{\filename}{}
\newcounter{i}
\forloop{i}{1}{\value{i} < 4}{
\begin{figure}
\renewcommand{\filename}{pic\_\padzeroes[3]{\decimal{i}}\_test.pdf}
\includegraphics[scale=0.6]{\filename}
\caption{Screenshot\_\arabic{i}}
\end{figure}
}
Responder1
LaTeX conhece o (expansível)\two@digits
o que parece suficiente para o seu uso (embora também possa ser estendido, se necessário):
\documentclass{article}
\usepackage{forloop}
\usepackage[draft]{graphicx}
\newcounter{filename}
\makeatletter
\newcommand{\twodigits}{\two@digits}
\makeatother
\begin{document}
\forloop{filename}{1}{\value{filename} < 4}{
\begin{figure}
\includegraphics[scale=0.6]{pic_0\twodigits{\value{filename}}_test.png}
\caption{Screenshot\_\thefilename: pic\_0\twodigits{\value{filename}}\_test.png}
\end{figure}
}
\end{document}
Como você está usando sublinhados nos nomes dos arquivos, pareceu haver alguma replicação para evitar problemas de impressão e uso.
Responder2
O nome do arquivo deve ser expansível:
\renewcommand*{\filename}{%
pic_%
\ifnum\value{i}<100 0\fi
\ifnum\value{i}<10 0\fi
\number\value{i}%
_.pdf%
}%
\includegraphics[scale=0.6]{\filename}
Observe que uma macro com o nome do arquivo, que oculta a extensão, deve começar do início do argumento do nome do arquivo \includegraphics
.
Responder3
Isso também deve funcionar:
% in preamble:
\makeatletter
% notice this will use the value of i at the time of macro use
% not at the time of definition here
\newcommand*{\filename}{%
pic_%
\expandafter\@gobble\the\numexpr 1000+\value{i}%
_.pdf%
}%
\makeatother
% in body:
\includegraphics[scale=0.6]{\filename}
assumindo que i
o contador LaTeX não exceda 999 como valor.