forloop and table in LaTeX

♀尐吖头ヾ 提交于 2019-12-07 12:21:03

问题


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?


回答1:


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}


来源:https://stackoverflow.com/questions/2564728/forloop-and-table-in-latex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!