在LaTeX迭代 [英] Iteration in LaTeX
问题描述
我想使用一些迭代控制流来简化下面的LaTeX代码。
\ begin {sidewaystable}
\ caption {一目了然的图像}
\centering
\ begin {tabular} {| c || c | ç| c | c | ç|| c | c | ç| C | C | }
\ hline
\backslashbox {Theme} {Class}& \multicolumn {5} {| c |} {Class 0}& \multicolumn {5} {| c |} {Class 1} \\
\hline
\hline
1&
\includegraphics [scale = 2] {../../ results / 1 / 0_1.eps}
& \includegraphics [scale = 2] {../../ results / 1 / 0_2.eps}
& \includegraphics [scale = 2] {../../ results / 1 / 0_3.eps}
& \includegraphics [scale = 2] { ../../results/1/0_4.eps}
& \includegraphics [scale = 2] {../../ results / 1 / 0_5.eps}
& amp; \\ \\includegraphics [scale = 2] {../../ results / 1 / 1_1.eps}
& \includegraphics [scale = 2] {../../ results / 1 / 1_2.eps }
& \includegraphics [scale = 2] {../../ results / 1 / 1_3.eps}
& \includegraphics [scale = 2] {../ .. /results/1/1_4.eps}
& \includegraphics [scale = 2] {../../ results / 1 / 1_5.eps} \\\
\hline
...同样为2,3,...,22
\hline
23&
\includegraphics [scale = 2] {../../ results / 23 / 0_1.eps}
& \includegraphics [scale = 2] {../../ results / 23 / 0_2.eps}
& \includegraphics [scale = 2] {../../ results / 23 / 0_3.eps}
& \includegraphics [scale = 2] { ../../results/23/0_4.eps}
& \includegraphics [scale = 2] {../../ results / 23 / 0_5.eps}
& \\ \\includegraphics [scale = 2] {../../ results / 23 / 1_1.eps}
& \includegraphics [scale = 2] {../../ results / 23 / 1_2.eps }
& \includegraphics [scale = 2] {../../ results / 23 / 1_3.eps}
& \includegraphics [scale = 2] {../ .. /results/23/1_4.eps}
& \includegraphics [scale = 2] {../../ results / 23 / 1_5.eps} \\\
\hline
\\ end {表格}
\ end {sidewaystable}
<我知道 forloop包为循环提供了。但我不知道如何将其应用于我的案件?或者其他方法不是通过forloop?
如果我还想简单地另一个类似的情况,唯一的区别是目录不会从1,2,到23,但以一些任意的顺序,如3,2,6,9,...,甚至是一个字符串列表,如dira,dirc,dird,dirb,... 。如何使LaTeX代码进入循环呢?
类似这样的事情将照顾你的表格的正文:
\ newcounter {themenumber}
\ newcounter {classnumber}
\ newcounter {imagenumber}
\forloop {themenumber} {1} {\ value {themenumber}< 24} {
%\ hline< - 这里错误
\ arabic {themenumber}
\forloop {classnumber} {0} {\ value {classnumber}< 2} {
\forloop {imagenumber} {1} {\ value {imagenumber}< 6} {
& \includegraphics [scale = 2] {
../../results/\arabic{themenumber}/\arabic{classnumber}_\arabic{imagenumber}.eps
}
$ h
code $ pre
我必须注释掉第一个 \hline
因为它给了我一个错误:
除了领导,您不能在这里使用'\ hrule'。
我不确定这意味着什么;如果你真的不能没有双线,我可以看看更多。
另外请注意,您必须使用<
;
$ <至于你的更新:我会简单地声明一个命令,采用你正在循环的参数。就像这样:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ b \fordir {dira}
\fordir {dirb}
\fordir {dirc}
\点数
I would like to use some iteration control flow to simplify the following LaTeX code.
\begin{sidewaystable}
\caption{A glance of images}
\centering
\begin{tabular}{| c ||c| c| c |c| c|| c |c| c|c|c| }
\hline
\backslashbox{Theme}{Class} &\multicolumn{5}{|c|}{Class 0} & \multicolumn{5}{|c|}{Class 1} \\
\hline
\hline
1 &
\includegraphics[scale=2]{../../results/1/0_1.eps}
&\includegraphics[scale=2]{../../results/1/0_2.eps}
&\includegraphics[scale=2]{../../results/1/0_3.eps}
&\includegraphics[scale=2]{../../results/1/0_4.eps}
&\includegraphics[scale=2]{../../results/1/0_5.eps}
&\includegraphics[scale=2]{../../results/1/1_1.eps}
&\includegraphics[scale=2]{../../results/1/1_2.eps}
&\includegraphics[scale=2]{../../results/1/1_3.eps}
&\includegraphics[scale=2]{../../results/1/1_4.eps}
&\includegraphics[scale=2]{../../results/1/1_5.eps} \\
\hline
... % similarly for 2, 3, ..., 22
\hline
23 &
\includegraphics[scale=2]{../../results/23/0_1.eps}
&\includegraphics[scale=2]{../../results/23/0_2.eps}
&\includegraphics[scale=2]{../../results/23/0_3.eps}
&\includegraphics[scale=2]{../../results/23/0_4.eps}
&\includegraphics[scale=2]{../../results/23/0_5.eps}
&\includegraphics[scale=2]{../../results/23/1_1.eps}
&\includegraphics[scale=2]{../../results/23/1_2.eps}
&\includegraphics[scale=2]{../../results/23/1_3.eps}
&\includegraphics[scale=2]{../../results/23/1_4.eps}
&\includegraphics[scale=2]{../../results/23/1_5.eps} \\
\hline
\end{tabular}
\end{sidewaystable}
I learn that the forloop package provides the for
loop. But I am not sure how to apply it to my case? Or other methods not by forloop?
If I also want to simply another similar case, where the only difference is that the directory does not run from 1, 2, to 23, but in some arbitrary order such as 3, 2, 6, 9,..., or even a list of strings such as dira, dirc, dird, dirb,.... How do I make the LaTeX code into loops then?
Something like this will take care of the body of your tabular:
\newcounter{themenumber}
\newcounter{classnumber}
\newcounter{imagenumber}
\forloop{themenumber}{1}{\value{themenumber} < 24}{
% \hline <-- Error here
\arabic{themenumber}
\forloop{classnumber}{0}{\value{classnumber} < 2}{
\forloop{imagenumber}{1}{\value{imagenumber} < 6}{
& \includegraphics[scale=2]{
../../results/\arabic{themenumber}/\arabic{classnumber}_\arabic{imagenumber}.eps
}
}
}
\\
\hline
}
I had to comment out the first \hline
because it gave me an error:
You can't use `\hrule' here except with leaders.
I'm not sure what that means; if you really cannot live without the double line, I can look into it more.
Also note that you have to use <
; for example, <= 24
will not work.
As to your update: I would simply declare a command that takes the argument that you're looping over. Something like this:
\newcommand\fordir[1]{do something complex involving directory named #1}
\fordir{dira}
\fordir{dirb}
\fordir{dirc}
\dots
这篇关于在LaTeX迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!