我试图在LaTex中创建一个循环,但它只会在第一次打印出来。这是我与之合作的要点,但我的循环不能正常工作。
\documentclass[12pt]{article}
%%% FOR LOOP CODE
\usepackage{ifthen}
\newcommand{\forLoop}[5][1]{%
\setcounter{#4}{#2} %
\ifthenelse{ \value{#4}<#3 }%
{%
#5 %
\addtocounter{#4}{#1} %
\forLoop[#1]{\value{#4}}{#3}{#4}{#5} %
}%
{%
#5 %
}%
}%
%% END FOR LOOP CODE
\begin{document}
Practice loop
\newcounter{index}
\section{Example 1}
\forLoop[2]{1}{5}{index}
{
This is inside the for loop: iteration \theindex\\
}
\end{document}
答案 0 :(得分:1)
有a number of ways to create a loop in LaTeX,所以没有必要重新发明轮子:
\documentclass{article}
\usepackage{multido}
\newcommand{\forLoop}[4][1]{\multido{\i=#2+#1}{#3}{#4}}
\setlength{\parindent}{0pt}% Just for this example
\begin{document}
\section{Example}
\forLoop[2]{1}{5}
{%
This is inside the for loop: iteration \i\endgraf
}
\end{document}