LaTeX 中的 forloop 和 table

发布于 2024-08-27 15:01:41 字数 822 浏览 4 评论 0原文

这是我的表的 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。免费图像托管。 net/image.php?c702bfc838.png

我该如何修复它?

Here is the LaTeX code for my table:

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

Something is wrong in the result however. There is some extra thing at the end of the table, as shown in here:

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

How can I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡の花香 2024-09-03 15:01:41

那是一件令人讨厌的事情。我创建了一个演示该问题的最小示例,请参见下文。尝试编译它并查看结果。

关键是,你似乎不走运 - 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}

That's a nasty one. I've created a minimal example that demonstrates the problem, see below. Try to compile this and take a look at the results.

The point is, you seem to be out of luck — tabular does not like the output of forloop, it cannot disregard the last \addtocounter command. Maybe you can find some other package for loops.
You should be able to figure out the rest from the code below, if not, write a comment.

\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}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文