LaTeX中的for循环和表格

3

这是我的表格的LaTeX代码:

  \begin{table}{| c || c | c | c || c | c | c | }  
  \caption{Examples of the concepts. \label{tab:conceptsimgs}}\\   
  \hline  
  \backslashbox{Concept}{Class} &\multicolumn{3}{|c||}{Negative Class} & \multicolumn{3}{|c|}{Positive Class}  \\  
  \hline  

  \forloop{themenumber}{1}{\value{themenumber} < 4}{  
        %\hline   
        \arabic{themenumber}  
        \forloop{classnumber}{0}{\value{classnumber} < 2}{  
            \forloop{imagenumber}{1}{\value{imagenumber} < 4}{  
                & 0  
            }  
        }  
        \\  
        \hline  
  }  

  \end{table}

然而,结果中有些问题。如下图所示,在表格末尾有一些额外的内容:

http://www. freeimagehosting. net/image.php?c702bfc838.png

我该如何解决?

1个回答

2

这是一个棘手的问题。我创建了一个最小化的示例来演示问题,见下文。尝试编译它并查看结果。

问题在于,你似乎运气不佳 - tabular 不喜欢 forloop 的输出,它无法忽略最后一个 \addtocounter 命令。也许你可以找到其他用于循环的包。如果你不能从下面的代码中解决问题,请写一条评论。

\documentclass{article}
\usepackage{forloop}

\newcounter{themenumber}  
\newcounter{test}

\begin{document}
% this is your table (minimal example)
\begin{tabular}{| c |}  
  \forloop{themenumber}{1}{\value{themenumber} < 2}{x\\ \hline}   
\end{tabular}
\vspace{2cm}

% this is what you wanted to have
\begin{tabular}{| c |}  
x \\ \hline
\end{tabular}
\vspace{2cm}

% this is what forloop produces
\begin{tabular}{| c |}  
x \\ \hline \addtocounter{test}{1}
\end{tabular}

\end{document}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接