Iteration in LaTeX

后端 未结 2 472
无人及你
无人及你 2021-01-29 22:44

I would like to use some iteration control flow to simplify the following LaTeX code.

  \\begin{sidewaystable}
  \\caption{A glance of images}
  \\centering
  \\         


        
相关标签:
2条回答
  • 2021-01-29 23:07

    You may use pgffor package, a tool provided by pgf. The basic syntax is:

    \foreach \n in {0,...,22}{do something}
    

    Notably, this for loop is not restricted to integers, for example:

    \foreach \n in {apples,burgers,cake}{Let's eat \n.\par}
    
    0 讨论(0)
  • 2021-01-29 23:16

    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
    
    0 讨论(0)
提交回复
热议问题