Can you repeat in LaTeX?

I am new to LaTeX and I have to say that I am really struggling with this. I found the \ newcommand command, which is similar to a function / method in common programming languages. You can give him arguments and that’s it.

I was wondering if I can somehow repeat in LaTeX? Basically, I would like to create a table with N + 1 columns, where the first row simply contains an empty cell, and then the numbers 1, 2, ..., N in other columns. I just want to give N as an argument to this "function" (newcommand).

Here is an example of what might look like what I'm looking for (although obviously this will not work):

\ newcommand {\ mytable} [2] {  
\ begin {tabular} {l | * {# 1} {c |}}% table with first argument + 1 columns  
  for (int i = 1; i <= # 1; i ++) "& i"% 'output' numbers in different columns  
  \\\ hline  
  letters & # 2% second argument should contain actual content for row  
  \\\ hline  
\ end {tabular}  
}

Call the following address:

\ mytable {3} {a & b & c}

The conclusion should be:

        | 1 | 2 | 3 |
-------- + --- + --- + --- +
letters | a | b | c |
-------- + --- + --- + --- +

Does anyone know if something like this is possible?

Thanks!

+3
source share
5 answers

Aunt google says yes .

+3
source

You can use tokens \loopor \repeat. Or a multidopackage.

+3
source

ifthen.

\begin{tabular}{l|*{10}{c|}}
\newcounter{count}
\whiledo{\value{count}<10}{
\ifthenelse{\value{count}=0}{}{\the\value{count}}
\ifthenelse{\value{count}<9}{&}{\\}
\stepcounter{count}
}
letters&a&b&c&d&e&f&g&h&i\\
\end{tabular}
+3

, . . eplain , ., , .

+2

( , ) perltex

+2

All Articles