for 루프에 앞에 0이 있는 포함 그래픽

for 루프에 앞에 0이 있는 포함 그래픽

파일 이름 앞에 0이 붙은 그래픽을 포함하고 싶습니다. 파일 이름은 다음과 같습니다:

pic_001_test.png
pic_002_test.png
.
.
.
pic_028_test.png

a에서 앞에 0을 출력할 수 있지만 명령 \forloop에서는 사용할 수 없습니다 \includegraphics.

\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}

다음 코드는 "! 정의되지 않은 제어 시퀀스"로 인해 작동하지 않습니다.

\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}
}

답변1

LaTeX는 (확장 가능)을 알고 있습니다.\two@digits이는 귀하의 용도에 충분해 보입니다(필요한 경우 확장할 수도 있음).

\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}

파일 이름에 밑줄을 사용하고 있으므로 인쇄 및 사용 문제를 피하기 위해 일부 복제가 발생한 것 같습니다.

답변2

파일 이름은 확장 가능해야 합니다.

\renewcommand*{\filename}{%
  pic_%
  \ifnum\value{i}<100 0\fi
  \ifnum\value{i}<10 0\fi
  \number\value{i}%
  _.pdf%
}%
\includegraphics[scale=0.6]{\filename}

확장자를 숨기는 파일 이름을 가진 매크로는 의 파일 이름 인수의 시작 부분부터 시작해야 합니다 \includegraphics.

답변3

이것도 작동합니다:

% 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}

LaTeX 카운터의 값이 999를 초과하지 않는다고 가정합니다 i.

관련 정보