How to draw a Cayley table
up vote
10
down vote
favorite
I'm trying to make a Cayley table like the one in the following question, but I don't want the labels, for example, on top (Capacity) and on the left side (the w's and v's). I just would like to reproduce the exact same table without the 'extra' bits on the side.
I forgot to mention I want a 5x5 table (25 entries inside the table), but still with the "outer" headings.
I managed to do this. However, this is long-winded I think:
[
begin{tabular}{>{$}l<{$}|*{6}{>{$}l<{$}}}
~ & 1 & a & a^2 & a^3 & a^4 \
hlinevrule height 12pt width 0pt
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{tabular}
]
EDIT:
setlengthextrarowheight{3pt}
noindentbegin{tabular}{c | c c c c c}
& 1 & a & a^2 & a^3 & a^4 \
cline{1-6}
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{tabular}
tables
New contributor
A.E is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 5 more comments
up vote
10
down vote
favorite
I'm trying to make a Cayley table like the one in the following question, but I don't want the labels, for example, on top (Capacity) and on the left side (the w's and v's). I just would like to reproduce the exact same table without the 'extra' bits on the side.
I forgot to mention I want a 5x5 table (25 entries inside the table), but still with the "outer" headings.
I managed to do this. However, this is long-winded I think:
[
begin{tabular}{>{$}l<{$}|*{6}{>{$}l<{$}}}
~ & 1 & a & a^2 & a^3 & a^4 \
hlinevrule height 12pt width 0pt
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{tabular}
]
EDIT:
setlengthextrarowheight{3pt}
noindentbegin{tabular}{c | c c c c c}
& 1 & a & a^2 & a^3 & a^4 \
cline{1-6}
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{tabular}
tables
New contributor
A.E is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
the answer provided was excellent in the above link, I would appreciate if I can get a similar answer.
– A.E
23 hours ago
3
Just take Gonzalo's answer and delete first line (the one which containsCapacity) and two left columns and two right ones.
– Ignasi
23 hours ago
1
array, nottabular.
– egreg
23 hours ago
1
You Need to put $a^2$ when you want to use math!
– GiuTeX
22 hours ago
1
@A.E As it is, the added code produces tons of errors.
– egreg
22 hours ago
|
show 5 more comments
up vote
10
down vote
favorite
up vote
10
down vote
favorite
I'm trying to make a Cayley table like the one in the following question, but I don't want the labels, for example, on top (Capacity) and on the left side (the w's and v's). I just would like to reproduce the exact same table without the 'extra' bits on the side.
I forgot to mention I want a 5x5 table (25 entries inside the table), but still with the "outer" headings.
I managed to do this. However, this is long-winded I think:
[
begin{tabular}{>{$}l<{$}|*{6}{>{$}l<{$}}}
~ & 1 & a & a^2 & a^3 & a^4 \
hlinevrule height 12pt width 0pt
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{tabular}
]
EDIT:
setlengthextrarowheight{3pt}
noindentbegin{tabular}{c | c c c c c}
& 1 & a & a^2 & a^3 & a^4 \
cline{1-6}
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{tabular}
tables
New contributor
A.E is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I'm trying to make a Cayley table like the one in the following question, but I don't want the labels, for example, on top (Capacity) and on the left side (the w's and v's). I just would like to reproduce the exact same table without the 'extra' bits on the side.
I forgot to mention I want a 5x5 table (25 entries inside the table), but still with the "outer" headings.
I managed to do this. However, this is long-winded I think:
[
begin{tabular}{>{$}l<{$}|*{6}{>{$}l<{$}}}
~ & 1 & a & a^2 & a^3 & a^4 \
hlinevrule height 12pt width 0pt
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{tabular}
]
EDIT:
setlengthextrarowheight{3pt}
noindentbegin{tabular}{c | c c c c c}
& 1 & a & a^2 & a^3 & a^4 \
cline{1-6}
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{tabular}
tables
tables
New contributor
A.E is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
A.E is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 15 hours ago
Peter Mortensen
52136
52136
New contributor
A.E is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 23 hours ago
A.E
827
827
New contributor
A.E is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
A.E is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
A.E is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
the answer provided was excellent in the above link, I would appreciate if I can get a similar answer.
– A.E
23 hours ago
3
Just take Gonzalo's answer and delete first line (the one which containsCapacity) and two left columns and two right ones.
– Ignasi
23 hours ago
1
array, nottabular.
– egreg
23 hours ago
1
You Need to put $a^2$ when you want to use math!
– GiuTeX
22 hours ago
1
@A.E As it is, the added code produces tons of errors.
– egreg
22 hours ago
|
show 5 more comments
the answer provided was excellent in the above link, I would appreciate if I can get a similar answer.
– A.E
23 hours ago
3
Just take Gonzalo's answer and delete first line (the one which containsCapacity) and two left columns and two right ones.
– Ignasi
23 hours ago
1
array, nottabular.
– egreg
23 hours ago
1
You Need to put $a^2$ when you want to use math!
– GiuTeX
22 hours ago
1
@A.E As it is, the added code produces tons of errors.
– egreg
22 hours ago
the answer provided was excellent in the above link, I would appreciate if I can get a similar answer.
– A.E
23 hours ago
the answer provided was excellent in the above link, I would appreciate if I can get a similar answer.
– A.E
23 hours ago
3
3
Just take Gonzalo's answer and delete first line (the one which contains
Capacity) and two left columns and two right ones.– Ignasi
23 hours ago
Just take Gonzalo's answer and delete first line (the one which contains
Capacity) and two left columns and two right ones.– Ignasi
23 hours ago
1
1
array, not tabular.– egreg
23 hours ago
array, not tabular.– egreg
23 hours ago
1
1
You Need to put $a^2$ when you want to use math!
– GiuTeX
22 hours ago
You Need to put $a^2$ when you want to use math!
– GiuTeX
22 hours ago
1
1
@A.E As it is, the added code produces tons of errors.
– egreg
22 hours ago
@A.E As it is, the added code produces tons of errors.
– egreg
22 hours ago
|
show 5 more comments
4 Answers
4
active
oldest
votes
up vote
9
down vote
accepted
Basically I've just taken the answer to the question you linked and changed few lines to adapt to your needs.
Here's the code, followed by the output you will get and a brief explanation of what's going on.
The code below produces 2 tables, in one there's written ANYTHING in the top left corner, in the second one there's a white space (just don't put anything in the column "argument".
documentclass[10pt]{article}
usepackage{array}
begin{document}
setlengthextrarowheight{3pt}
noindentbegin{tabular}{c | c c c c c}
ANYTHING & 0 & 1 & 2 & 3 & 4 \
cline{1-6}
0 & 0 & 0 & 0 & 0 & 0 \
1 & 0 & 0 & $a^2$ & 25 & 25 \
2 & $a^2$ & 0 & 20 & 25 & 25 \
2 & 0 & $a^2$ & 20 & 25 & 25 \
2 & 0 & 0 & 20 & 25 & 25 \
end{tabular}
noindentbegin{tabular}{c | c c c c c}
& 0 & 1 & 2 & 3 & 4 \
cline{1-6}
0 & 0 & 0 & 0 & 0 & 0 \
1 & 0 & 0 & $a^2$ & 25 & 25 \
2 & $a^2$ & 0 & 20 & 25 & 25 \
2 & 0 & $a^2$ & 20 & 25 & 25 \
2 & 0 & 0 & 20 & 25 & 25 \
end{tabular}
end{document}


How does it work? A table is done with the environment {tabular}, which requires as argument the numer of columns (or rows... just read the documentation to know more) which is specified by the argument {c | c c c c c}: 6 columns divided by a line between the first and the second col. The 'c' stands for centered meaning that the column will be aligned to the center, if you want you can change it to l (left) or r (right).
Then in the tables all the entries are done by spacing them with &, and the cline takes as argument the number of columns that you want it to span: from column 1 to column 6.
The command setlengthextrarowheight{3pt} adds some extra row height (how surprising!).
Package {array} is needed for the length extrarowheight.
1
this is good however I wanted a 5x5 table
– A.E
23 hours ago
1
Cheers pal, much appreciated.
– A.E
23 hours ago
1
if you could briefly explain what you did line by line, It would be more beneficial so I know what you've done
– A.E
23 hours ago
1
much appreciated
– A.E
22 hours ago
I added more on the meaning of thec's in{tabular}environment.
– GiuTeX
22 hours ago
|
show 5 more comments
up vote
11
down vote
Your input is almost good, but you can do better.
documentclass{article}
usepackage{amsmath}
usepackage{array}
begin{document}
This is a Cayley table
[
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
This is the same, but with some more spacing,
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
end{document}
With array, each cell is assumed to be in math mode. The setting of extrarowheight will not propagate to other instances of array, because [...] forms a group.

1
I prefer the method above as it is easier to follow(in my eyes anyway) but thanks for your answer
– A.E
22 hours ago
1
What does*inl|*mean?
– manooooh
22 hours ago
2
@manooooh*{6}{l}is short forllllll
– samcarter
22 hours ago
3
@manooooh The*refers to the following:*{6}{l}means “repeatlsix times”.
– egreg
22 hours ago
@jfbu Right, fixed
– egreg
22 hours ago
add a comment |
up vote
9
down vote
Some automatizing is in order here
documentclass{article}
usepackage{amsmath, amssymb}
usepackage{array}
usepackage{xinttools}
usepackage{bnumexpr}
begin{document}
This is a Cayley table
[
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
This is the same, but with some more spacing,
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
Again, but illustrating that $a=4$ generates a cyclic sub-group of order
$5$ of $(mathbb{Z}/11mathbb{Z})^*$:
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{c|*{5}{c}}
& 1 & a & a^2 & a^3 & a^4 \
hline
xintFor #1 in {0, 1, 2, 3, 4}:
{ifnum #1=0 1else a^{#1}fi
xintFor #2 in {0, 1, 2, 3, 4}:
{%
&thebnumexpr 4^(#1+#2) /: 11relax
}%
\
}%
end{array}
]
and $a=2$ generates the full group:
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{c|*{10}{c}}
& 1 & a xintFor*#1 in {23456789}:{&a^{#1}}\
hline
xintFor* #1 in {0123456789}:
{ifnum #1=0 1else a^{#1}fi
xintFor* #2 in {0123456789}:
{%
&thebnumexpr 2^(#1+#2) /: 11relax
}%
\
}%
end{array}
]
end{document}

+1 I'm always amazed at how efficientxinttoolsis!
– Andrew
8 hours ago
@Andrew your expl3 answer does look efficient too:)
– jfbu
7 hours ago
add a comment |
up vote
4
down vote
Perhaps I over automate, but I'd want to have a macro CayleyTable that produces the Cayley table of the corresponding cyclic group, so that the commands:
CayleyTable{3}
CayleyTable{4}
CayleyTable[x]{9}
would produce:

(The an optional argument gives the name of the generator, which defaults to a). Arguably, CyclicGroupCayleyTable would be a better name. In any case,
here's the code:
documentclass{article}
usepackage{array}
setlength{extrarowheight}{3pt}% local setting
usepackage{xparse}
ExplSyntaxOn
int_new:N l_n_int
tl_new:N l_gen_tl
cs_new_protected:Npn print_exponent #1 {% {l_gen_tl}^{#1}
int_compare:nTF {#1=0}{1}{l_gen_tl int_compare:nT{#1>1}{^{#1}}}
}
cs_new_protected:Npn print_Cayley_header:n #1 {
& print_exponent {int_eval:n{#1-1}}
}
cs_new_protected:Npn print_Cayley_cell:nn #1 #2 {
& print_exponent {int_eval:n { int_mod:nn {#1+#2-2}{l_n_int}} }
}
cs_new_protected:Npn print_Cayley_row:n #1 {
print_exponent {int_eval:n {#1-1}}
int_step_inline:nn {l_n_int} {print_Cayley_cell:nn {##1}{#1}} \
}
NewDocumentCommandCayleyTable{ O{a} m}{
tl_set:Nn l_gen_tl {#1}
int_set:Nn l_n_int {#2}
[
begin{array}{c|*{int_eval:n{l_n_int+1}}{c}}
int_step_function:nN {l_n_int} print_Cayley_header:n
\hline
int_step_function:nN {l_n_int} print_Cayley_row:n
end{array}
]
}
ExplSyntaxOff
begin{document}
CayleyTable{3}
CayleyTable{4}
CayleyTable[x]{9}
end{document}
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
9
down vote
accepted
Basically I've just taken the answer to the question you linked and changed few lines to adapt to your needs.
Here's the code, followed by the output you will get and a brief explanation of what's going on.
The code below produces 2 tables, in one there's written ANYTHING in the top left corner, in the second one there's a white space (just don't put anything in the column "argument".
documentclass[10pt]{article}
usepackage{array}
begin{document}
setlengthextrarowheight{3pt}
noindentbegin{tabular}{c | c c c c c}
ANYTHING & 0 & 1 & 2 & 3 & 4 \
cline{1-6}
0 & 0 & 0 & 0 & 0 & 0 \
1 & 0 & 0 & $a^2$ & 25 & 25 \
2 & $a^2$ & 0 & 20 & 25 & 25 \
2 & 0 & $a^2$ & 20 & 25 & 25 \
2 & 0 & 0 & 20 & 25 & 25 \
end{tabular}
noindentbegin{tabular}{c | c c c c c}
& 0 & 1 & 2 & 3 & 4 \
cline{1-6}
0 & 0 & 0 & 0 & 0 & 0 \
1 & 0 & 0 & $a^2$ & 25 & 25 \
2 & $a^2$ & 0 & 20 & 25 & 25 \
2 & 0 & $a^2$ & 20 & 25 & 25 \
2 & 0 & 0 & 20 & 25 & 25 \
end{tabular}
end{document}


How does it work? A table is done with the environment {tabular}, which requires as argument the numer of columns (or rows... just read the documentation to know more) which is specified by the argument {c | c c c c c}: 6 columns divided by a line between the first and the second col. The 'c' stands for centered meaning that the column will be aligned to the center, if you want you can change it to l (left) or r (right).
Then in the tables all the entries are done by spacing them with &, and the cline takes as argument the number of columns that you want it to span: from column 1 to column 6.
The command setlengthextrarowheight{3pt} adds some extra row height (how surprising!).
Package {array} is needed for the length extrarowheight.
1
this is good however I wanted a 5x5 table
– A.E
23 hours ago
1
Cheers pal, much appreciated.
– A.E
23 hours ago
1
if you could briefly explain what you did line by line, It would be more beneficial so I know what you've done
– A.E
23 hours ago
1
much appreciated
– A.E
22 hours ago
I added more on the meaning of thec's in{tabular}environment.
– GiuTeX
22 hours ago
|
show 5 more comments
up vote
9
down vote
accepted
Basically I've just taken the answer to the question you linked and changed few lines to adapt to your needs.
Here's the code, followed by the output you will get and a brief explanation of what's going on.
The code below produces 2 tables, in one there's written ANYTHING in the top left corner, in the second one there's a white space (just don't put anything in the column "argument".
documentclass[10pt]{article}
usepackage{array}
begin{document}
setlengthextrarowheight{3pt}
noindentbegin{tabular}{c | c c c c c}
ANYTHING & 0 & 1 & 2 & 3 & 4 \
cline{1-6}
0 & 0 & 0 & 0 & 0 & 0 \
1 & 0 & 0 & $a^2$ & 25 & 25 \
2 & $a^2$ & 0 & 20 & 25 & 25 \
2 & 0 & $a^2$ & 20 & 25 & 25 \
2 & 0 & 0 & 20 & 25 & 25 \
end{tabular}
noindentbegin{tabular}{c | c c c c c}
& 0 & 1 & 2 & 3 & 4 \
cline{1-6}
0 & 0 & 0 & 0 & 0 & 0 \
1 & 0 & 0 & $a^2$ & 25 & 25 \
2 & $a^2$ & 0 & 20 & 25 & 25 \
2 & 0 & $a^2$ & 20 & 25 & 25 \
2 & 0 & 0 & 20 & 25 & 25 \
end{tabular}
end{document}


How does it work? A table is done with the environment {tabular}, which requires as argument the numer of columns (or rows... just read the documentation to know more) which is specified by the argument {c | c c c c c}: 6 columns divided by a line between the first and the second col. The 'c' stands for centered meaning that the column will be aligned to the center, if you want you can change it to l (left) or r (right).
Then in the tables all the entries are done by spacing them with &, and the cline takes as argument the number of columns that you want it to span: from column 1 to column 6.
The command setlengthextrarowheight{3pt} adds some extra row height (how surprising!).
Package {array} is needed for the length extrarowheight.
1
this is good however I wanted a 5x5 table
– A.E
23 hours ago
1
Cheers pal, much appreciated.
– A.E
23 hours ago
1
if you could briefly explain what you did line by line, It would be more beneficial so I know what you've done
– A.E
23 hours ago
1
much appreciated
– A.E
22 hours ago
I added more on the meaning of thec's in{tabular}environment.
– GiuTeX
22 hours ago
|
show 5 more comments
up vote
9
down vote
accepted
up vote
9
down vote
accepted
Basically I've just taken the answer to the question you linked and changed few lines to adapt to your needs.
Here's the code, followed by the output you will get and a brief explanation of what's going on.
The code below produces 2 tables, in one there's written ANYTHING in the top left corner, in the second one there's a white space (just don't put anything in the column "argument".
documentclass[10pt]{article}
usepackage{array}
begin{document}
setlengthextrarowheight{3pt}
noindentbegin{tabular}{c | c c c c c}
ANYTHING & 0 & 1 & 2 & 3 & 4 \
cline{1-6}
0 & 0 & 0 & 0 & 0 & 0 \
1 & 0 & 0 & $a^2$ & 25 & 25 \
2 & $a^2$ & 0 & 20 & 25 & 25 \
2 & 0 & $a^2$ & 20 & 25 & 25 \
2 & 0 & 0 & 20 & 25 & 25 \
end{tabular}
noindentbegin{tabular}{c | c c c c c}
& 0 & 1 & 2 & 3 & 4 \
cline{1-6}
0 & 0 & 0 & 0 & 0 & 0 \
1 & 0 & 0 & $a^2$ & 25 & 25 \
2 & $a^2$ & 0 & 20 & 25 & 25 \
2 & 0 & $a^2$ & 20 & 25 & 25 \
2 & 0 & 0 & 20 & 25 & 25 \
end{tabular}
end{document}


How does it work? A table is done with the environment {tabular}, which requires as argument the numer of columns (or rows... just read the documentation to know more) which is specified by the argument {c | c c c c c}: 6 columns divided by a line between the first and the second col. The 'c' stands for centered meaning that the column will be aligned to the center, if you want you can change it to l (left) or r (right).
Then in the tables all the entries are done by spacing them with &, and the cline takes as argument the number of columns that you want it to span: from column 1 to column 6.
The command setlengthextrarowheight{3pt} adds some extra row height (how surprising!).
Package {array} is needed for the length extrarowheight.
Basically I've just taken the answer to the question you linked and changed few lines to adapt to your needs.
Here's the code, followed by the output you will get and a brief explanation of what's going on.
The code below produces 2 tables, in one there's written ANYTHING in the top left corner, in the second one there's a white space (just don't put anything in the column "argument".
documentclass[10pt]{article}
usepackage{array}
begin{document}
setlengthextrarowheight{3pt}
noindentbegin{tabular}{c | c c c c c}
ANYTHING & 0 & 1 & 2 & 3 & 4 \
cline{1-6}
0 & 0 & 0 & 0 & 0 & 0 \
1 & 0 & 0 & $a^2$ & 25 & 25 \
2 & $a^2$ & 0 & 20 & 25 & 25 \
2 & 0 & $a^2$ & 20 & 25 & 25 \
2 & 0 & 0 & 20 & 25 & 25 \
end{tabular}
noindentbegin{tabular}{c | c c c c c}
& 0 & 1 & 2 & 3 & 4 \
cline{1-6}
0 & 0 & 0 & 0 & 0 & 0 \
1 & 0 & 0 & $a^2$ & 25 & 25 \
2 & $a^2$ & 0 & 20 & 25 & 25 \
2 & 0 & $a^2$ & 20 & 25 & 25 \
2 & 0 & 0 & 20 & 25 & 25 \
end{tabular}
end{document}


How does it work? A table is done with the environment {tabular}, which requires as argument the numer of columns (or rows... just read the documentation to know more) which is specified by the argument {c | c c c c c}: 6 columns divided by a line between the first and the second col. The 'c' stands for centered meaning that the column will be aligned to the center, if you want you can change it to l (left) or r (right).
Then in the tables all the entries are done by spacing them with &, and the cline takes as argument the number of columns that you want it to span: from column 1 to column 6.
The command setlengthextrarowheight{3pt} adds some extra row height (how surprising!).
Package {array} is needed for the length extrarowheight.
edited 22 hours ago
answered 23 hours ago
GiuTeX
642216
642216
1
this is good however I wanted a 5x5 table
– A.E
23 hours ago
1
Cheers pal, much appreciated.
– A.E
23 hours ago
1
if you could briefly explain what you did line by line, It would be more beneficial so I know what you've done
– A.E
23 hours ago
1
much appreciated
– A.E
22 hours ago
I added more on the meaning of thec's in{tabular}environment.
– GiuTeX
22 hours ago
|
show 5 more comments
1
this is good however I wanted a 5x5 table
– A.E
23 hours ago
1
Cheers pal, much appreciated.
– A.E
23 hours ago
1
if you could briefly explain what you did line by line, It would be more beneficial so I know what you've done
– A.E
23 hours ago
1
much appreciated
– A.E
22 hours ago
I added more on the meaning of thec's in{tabular}environment.
– GiuTeX
22 hours ago
1
1
this is good however I wanted a 5x5 table
– A.E
23 hours ago
this is good however I wanted a 5x5 table
– A.E
23 hours ago
1
1
Cheers pal, much appreciated.
– A.E
23 hours ago
Cheers pal, much appreciated.
– A.E
23 hours ago
1
1
if you could briefly explain what you did line by line, It would be more beneficial so I know what you've done
– A.E
23 hours ago
if you could briefly explain what you did line by line, It would be more beneficial so I know what you've done
– A.E
23 hours ago
1
1
much appreciated
– A.E
22 hours ago
much appreciated
– A.E
22 hours ago
I added more on the meaning of the
c's in {tabular} environment.– GiuTeX
22 hours ago
I added more on the meaning of the
c's in {tabular} environment.– GiuTeX
22 hours ago
|
show 5 more comments
up vote
11
down vote
Your input is almost good, but you can do better.
documentclass{article}
usepackage{amsmath}
usepackage{array}
begin{document}
This is a Cayley table
[
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
This is the same, but with some more spacing,
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
end{document}
With array, each cell is assumed to be in math mode. The setting of extrarowheight will not propagate to other instances of array, because [...] forms a group.

1
I prefer the method above as it is easier to follow(in my eyes anyway) but thanks for your answer
– A.E
22 hours ago
1
What does*inl|*mean?
– manooooh
22 hours ago
2
@manooooh*{6}{l}is short forllllll
– samcarter
22 hours ago
3
@manooooh The*refers to the following:*{6}{l}means “repeatlsix times”.
– egreg
22 hours ago
@jfbu Right, fixed
– egreg
22 hours ago
add a comment |
up vote
11
down vote
Your input is almost good, but you can do better.
documentclass{article}
usepackage{amsmath}
usepackage{array}
begin{document}
This is a Cayley table
[
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
This is the same, but with some more spacing,
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
end{document}
With array, each cell is assumed to be in math mode. The setting of extrarowheight will not propagate to other instances of array, because [...] forms a group.

1
I prefer the method above as it is easier to follow(in my eyes anyway) but thanks for your answer
– A.E
22 hours ago
1
What does*inl|*mean?
– manooooh
22 hours ago
2
@manooooh*{6}{l}is short forllllll
– samcarter
22 hours ago
3
@manooooh The*refers to the following:*{6}{l}means “repeatlsix times”.
– egreg
22 hours ago
@jfbu Right, fixed
– egreg
22 hours ago
add a comment |
up vote
11
down vote
up vote
11
down vote
Your input is almost good, but you can do better.
documentclass{article}
usepackage{amsmath}
usepackage{array}
begin{document}
This is a Cayley table
[
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
This is the same, but with some more spacing,
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
end{document}
With array, each cell is assumed to be in math mode. The setting of extrarowheight will not propagate to other instances of array, because [...] forms a group.

Your input is almost good, but you can do better.
documentclass{article}
usepackage{amsmath}
usepackage{array}
begin{document}
This is a Cayley table
[
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
This is the same, but with some more spacing,
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
end{document}
With array, each cell is assumed to be in math mode. The setting of extrarowheight will not propagate to other instances of array, because [...] forms a group.

edited 22 hours ago
answered 22 hours ago
egreg
696k8518503113
696k8518503113
1
I prefer the method above as it is easier to follow(in my eyes anyway) but thanks for your answer
– A.E
22 hours ago
1
What does*inl|*mean?
– manooooh
22 hours ago
2
@manooooh*{6}{l}is short forllllll
– samcarter
22 hours ago
3
@manooooh The*refers to the following:*{6}{l}means “repeatlsix times”.
– egreg
22 hours ago
@jfbu Right, fixed
– egreg
22 hours ago
add a comment |
1
I prefer the method above as it is easier to follow(in my eyes anyway) but thanks for your answer
– A.E
22 hours ago
1
What does*inl|*mean?
– manooooh
22 hours ago
2
@manooooh*{6}{l}is short forllllll
– samcarter
22 hours ago
3
@manooooh The*refers to the following:*{6}{l}means “repeatlsix times”.
– egreg
22 hours ago
@jfbu Right, fixed
– egreg
22 hours ago
1
1
I prefer the method above as it is easier to follow(in my eyes anyway) but thanks for your answer
– A.E
22 hours ago
I prefer the method above as it is easier to follow(in my eyes anyway) but thanks for your answer
– A.E
22 hours ago
1
1
What does
* in l|* mean?– manooooh
22 hours ago
What does
* in l|* mean?– manooooh
22 hours ago
2
2
@manooooh
*{6}{l} is short for llllll– samcarter
22 hours ago
@manooooh
*{6}{l} is short for llllll– samcarter
22 hours ago
3
3
@manooooh The
* refers to the following: *{6}{l} means “repeat l six times”.– egreg
22 hours ago
@manooooh The
* refers to the following: *{6}{l} means “repeat l six times”.– egreg
22 hours ago
@jfbu Right, fixed
– egreg
22 hours ago
@jfbu Right, fixed
– egreg
22 hours ago
add a comment |
up vote
9
down vote
Some automatizing is in order here
documentclass{article}
usepackage{amsmath, amssymb}
usepackage{array}
usepackage{xinttools}
usepackage{bnumexpr}
begin{document}
This is a Cayley table
[
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
This is the same, but with some more spacing,
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
Again, but illustrating that $a=4$ generates a cyclic sub-group of order
$5$ of $(mathbb{Z}/11mathbb{Z})^*$:
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{c|*{5}{c}}
& 1 & a & a^2 & a^3 & a^4 \
hline
xintFor #1 in {0, 1, 2, 3, 4}:
{ifnum #1=0 1else a^{#1}fi
xintFor #2 in {0, 1, 2, 3, 4}:
{%
&thebnumexpr 4^(#1+#2) /: 11relax
}%
\
}%
end{array}
]
and $a=2$ generates the full group:
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{c|*{10}{c}}
& 1 & a xintFor*#1 in {23456789}:{&a^{#1}}\
hline
xintFor* #1 in {0123456789}:
{ifnum #1=0 1else a^{#1}fi
xintFor* #2 in {0123456789}:
{%
&thebnumexpr 2^(#1+#2) /: 11relax
}%
\
}%
end{array}
]
end{document}

+1 I'm always amazed at how efficientxinttoolsis!
– Andrew
8 hours ago
@Andrew your expl3 answer does look efficient too:)
– jfbu
7 hours ago
add a comment |
up vote
9
down vote
Some automatizing is in order here
documentclass{article}
usepackage{amsmath, amssymb}
usepackage{array}
usepackage{xinttools}
usepackage{bnumexpr}
begin{document}
This is a Cayley table
[
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
This is the same, but with some more spacing,
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
Again, but illustrating that $a=4$ generates a cyclic sub-group of order
$5$ of $(mathbb{Z}/11mathbb{Z})^*$:
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{c|*{5}{c}}
& 1 & a & a^2 & a^3 & a^4 \
hline
xintFor #1 in {0, 1, 2, 3, 4}:
{ifnum #1=0 1else a^{#1}fi
xintFor #2 in {0, 1, 2, 3, 4}:
{%
&thebnumexpr 4^(#1+#2) /: 11relax
}%
\
}%
end{array}
]
and $a=2$ generates the full group:
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{c|*{10}{c}}
& 1 & a xintFor*#1 in {23456789}:{&a^{#1}}\
hline
xintFor* #1 in {0123456789}:
{ifnum #1=0 1else a^{#1}fi
xintFor* #2 in {0123456789}:
{%
&thebnumexpr 2^(#1+#2) /: 11relax
}%
\
}%
end{array}
]
end{document}

+1 I'm always amazed at how efficientxinttoolsis!
– Andrew
8 hours ago
@Andrew your expl3 answer does look efficient too:)
– jfbu
7 hours ago
add a comment |
up vote
9
down vote
up vote
9
down vote
Some automatizing is in order here
documentclass{article}
usepackage{amsmath, amssymb}
usepackage{array}
usepackage{xinttools}
usepackage{bnumexpr}
begin{document}
This is a Cayley table
[
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
This is the same, but with some more spacing,
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
Again, but illustrating that $a=4$ generates a cyclic sub-group of order
$5$ of $(mathbb{Z}/11mathbb{Z})^*$:
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{c|*{5}{c}}
& 1 & a & a^2 & a^3 & a^4 \
hline
xintFor #1 in {0, 1, 2, 3, 4}:
{ifnum #1=0 1else a^{#1}fi
xintFor #2 in {0, 1, 2, 3, 4}:
{%
&thebnumexpr 4^(#1+#2) /: 11relax
}%
\
}%
end{array}
]
and $a=2$ generates the full group:
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{c|*{10}{c}}
& 1 & a xintFor*#1 in {23456789}:{&a^{#1}}\
hline
xintFor* #1 in {0123456789}:
{ifnum #1=0 1else a^{#1}fi
xintFor* #2 in {0123456789}:
{%
&thebnumexpr 2^(#1+#2) /: 11relax
}%
\
}%
end{array}
]
end{document}

Some automatizing is in order here
documentclass{article}
usepackage{amsmath, amssymb}
usepackage{array}
usepackage{xinttools}
usepackage{bnumexpr}
begin{document}
This is a Cayley table
[
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
This is the same, but with some more spacing,
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{l|*{5}{l}}
& 1 & a & a^2 & a^3 & a^4 \
hline
1 & 1 & a & a^2 & a^3 & a^4 \
a & a & a^2 & a^3 & a^4 & a^5 \
a^2 & a^2 & a^3 & a^4 & a^5 & a^6 \
a^3 & a^3 & a^4 & a^5 & a^6 & a^7 \
a^4 & a^4 & a^5 & a^6 & a^7 & a^8 \
end{array}
]
Again, but illustrating that $a=4$ generates a cyclic sub-group of order
$5$ of $(mathbb{Z}/11mathbb{Z})^*$:
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{c|*{5}{c}}
& 1 & a & a^2 & a^3 & a^4 \
hline
xintFor #1 in {0, 1, 2, 3, 4}:
{ifnum #1=0 1else a^{#1}fi
xintFor #2 in {0, 1, 2, 3, 4}:
{%
&thebnumexpr 4^(#1+#2) /: 11relax
}%
\
}%
end{array}
]
and $a=2$ generates the full group:
[
setlength{extrarowheight}{3pt}% local setting
begin{array}{c|*{10}{c}}
& 1 & a xintFor*#1 in {23456789}:{&a^{#1}}\
hline
xintFor* #1 in {0123456789}:
{ifnum #1=0 1else a^{#1}fi
xintFor* #2 in {0123456789}:
{%
&thebnumexpr 2^(#1+#2) /: 11relax
}%
\
}%
end{array}
]
end{document}

answered 22 hours ago
jfbu
44k65142
44k65142
+1 I'm always amazed at how efficientxinttoolsis!
– Andrew
8 hours ago
@Andrew your expl3 answer does look efficient too:)
– jfbu
7 hours ago
add a comment |
+1 I'm always amazed at how efficientxinttoolsis!
– Andrew
8 hours ago
@Andrew your expl3 answer does look efficient too:)
– jfbu
7 hours ago
+1 I'm always amazed at how efficient
xinttools is!– Andrew
8 hours ago
+1 I'm always amazed at how efficient
xinttools is!– Andrew
8 hours ago
@Andrew your expl3 answer does look efficient too
:)– jfbu
7 hours ago
@Andrew your expl3 answer does look efficient too
:)– jfbu
7 hours ago
add a comment |
up vote
4
down vote
Perhaps I over automate, but I'd want to have a macro CayleyTable that produces the Cayley table of the corresponding cyclic group, so that the commands:
CayleyTable{3}
CayleyTable{4}
CayleyTable[x]{9}
would produce:

(The an optional argument gives the name of the generator, which defaults to a). Arguably, CyclicGroupCayleyTable would be a better name. In any case,
here's the code:
documentclass{article}
usepackage{array}
setlength{extrarowheight}{3pt}% local setting
usepackage{xparse}
ExplSyntaxOn
int_new:N l_n_int
tl_new:N l_gen_tl
cs_new_protected:Npn print_exponent #1 {% {l_gen_tl}^{#1}
int_compare:nTF {#1=0}{1}{l_gen_tl int_compare:nT{#1>1}{^{#1}}}
}
cs_new_protected:Npn print_Cayley_header:n #1 {
& print_exponent {int_eval:n{#1-1}}
}
cs_new_protected:Npn print_Cayley_cell:nn #1 #2 {
& print_exponent {int_eval:n { int_mod:nn {#1+#2-2}{l_n_int}} }
}
cs_new_protected:Npn print_Cayley_row:n #1 {
print_exponent {int_eval:n {#1-1}}
int_step_inline:nn {l_n_int} {print_Cayley_cell:nn {##1}{#1}} \
}
NewDocumentCommandCayleyTable{ O{a} m}{
tl_set:Nn l_gen_tl {#1}
int_set:Nn l_n_int {#2}
[
begin{array}{c|*{int_eval:n{l_n_int+1}}{c}}
int_step_function:nN {l_n_int} print_Cayley_header:n
\hline
int_step_function:nN {l_n_int} print_Cayley_row:n
end{array}
]
}
ExplSyntaxOff
begin{document}
CayleyTable{3}
CayleyTable{4}
CayleyTable[x]{9}
end{document}
add a comment |
up vote
4
down vote
Perhaps I over automate, but I'd want to have a macro CayleyTable that produces the Cayley table of the corresponding cyclic group, so that the commands:
CayleyTable{3}
CayleyTable{4}
CayleyTable[x]{9}
would produce:

(The an optional argument gives the name of the generator, which defaults to a). Arguably, CyclicGroupCayleyTable would be a better name. In any case,
here's the code:
documentclass{article}
usepackage{array}
setlength{extrarowheight}{3pt}% local setting
usepackage{xparse}
ExplSyntaxOn
int_new:N l_n_int
tl_new:N l_gen_tl
cs_new_protected:Npn print_exponent #1 {% {l_gen_tl}^{#1}
int_compare:nTF {#1=0}{1}{l_gen_tl int_compare:nT{#1>1}{^{#1}}}
}
cs_new_protected:Npn print_Cayley_header:n #1 {
& print_exponent {int_eval:n{#1-1}}
}
cs_new_protected:Npn print_Cayley_cell:nn #1 #2 {
& print_exponent {int_eval:n { int_mod:nn {#1+#2-2}{l_n_int}} }
}
cs_new_protected:Npn print_Cayley_row:n #1 {
print_exponent {int_eval:n {#1-1}}
int_step_inline:nn {l_n_int} {print_Cayley_cell:nn {##1}{#1}} \
}
NewDocumentCommandCayleyTable{ O{a} m}{
tl_set:Nn l_gen_tl {#1}
int_set:Nn l_n_int {#2}
[
begin{array}{c|*{int_eval:n{l_n_int+1}}{c}}
int_step_function:nN {l_n_int} print_Cayley_header:n
\hline
int_step_function:nN {l_n_int} print_Cayley_row:n
end{array}
]
}
ExplSyntaxOff
begin{document}
CayleyTable{3}
CayleyTable{4}
CayleyTable[x]{9}
end{document}
add a comment |
up vote
4
down vote
up vote
4
down vote
Perhaps I over automate, but I'd want to have a macro CayleyTable that produces the Cayley table of the corresponding cyclic group, so that the commands:
CayleyTable{3}
CayleyTable{4}
CayleyTable[x]{9}
would produce:

(The an optional argument gives the name of the generator, which defaults to a). Arguably, CyclicGroupCayleyTable would be a better name. In any case,
here's the code:
documentclass{article}
usepackage{array}
setlength{extrarowheight}{3pt}% local setting
usepackage{xparse}
ExplSyntaxOn
int_new:N l_n_int
tl_new:N l_gen_tl
cs_new_protected:Npn print_exponent #1 {% {l_gen_tl}^{#1}
int_compare:nTF {#1=0}{1}{l_gen_tl int_compare:nT{#1>1}{^{#1}}}
}
cs_new_protected:Npn print_Cayley_header:n #1 {
& print_exponent {int_eval:n{#1-1}}
}
cs_new_protected:Npn print_Cayley_cell:nn #1 #2 {
& print_exponent {int_eval:n { int_mod:nn {#1+#2-2}{l_n_int}} }
}
cs_new_protected:Npn print_Cayley_row:n #1 {
print_exponent {int_eval:n {#1-1}}
int_step_inline:nn {l_n_int} {print_Cayley_cell:nn {##1}{#1}} \
}
NewDocumentCommandCayleyTable{ O{a} m}{
tl_set:Nn l_gen_tl {#1}
int_set:Nn l_n_int {#2}
[
begin{array}{c|*{int_eval:n{l_n_int+1}}{c}}
int_step_function:nN {l_n_int} print_Cayley_header:n
\hline
int_step_function:nN {l_n_int} print_Cayley_row:n
end{array}
]
}
ExplSyntaxOff
begin{document}
CayleyTable{3}
CayleyTable{4}
CayleyTable[x]{9}
end{document}
Perhaps I over automate, but I'd want to have a macro CayleyTable that produces the Cayley table of the corresponding cyclic group, so that the commands:
CayleyTable{3}
CayleyTable{4}
CayleyTable[x]{9}
would produce:

(The an optional argument gives the name of the generator, which defaults to a). Arguably, CyclicGroupCayleyTable would be a better name. In any case,
here's the code:
documentclass{article}
usepackage{array}
setlength{extrarowheight}{3pt}% local setting
usepackage{xparse}
ExplSyntaxOn
int_new:N l_n_int
tl_new:N l_gen_tl
cs_new_protected:Npn print_exponent #1 {% {l_gen_tl}^{#1}
int_compare:nTF {#1=0}{1}{l_gen_tl int_compare:nT{#1>1}{^{#1}}}
}
cs_new_protected:Npn print_Cayley_header:n #1 {
& print_exponent {int_eval:n{#1-1}}
}
cs_new_protected:Npn print_Cayley_cell:nn #1 #2 {
& print_exponent {int_eval:n { int_mod:nn {#1+#2-2}{l_n_int}} }
}
cs_new_protected:Npn print_Cayley_row:n #1 {
print_exponent {int_eval:n {#1-1}}
int_step_inline:nn {l_n_int} {print_Cayley_cell:nn {##1}{#1}} \
}
NewDocumentCommandCayleyTable{ O{a} m}{
tl_set:Nn l_gen_tl {#1}
int_set:Nn l_n_int {#2}
[
begin{array}{c|*{int_eval:n{l_n_int+1}}{c}}
int_step_function:nN {l_n_int} print_Cayley_header:n
\hline
int_step_function:nN {l_n_int} print_Cayley_row:n
end{array}
]
}
ExplSyntaxOff
begin{document}
CayleyTable{3}
CayleyTable{4}
CayleyTable[x]{9}
end{document}
edited 9 hours ago
answered 9 hours ago
Andrew
29.1k34177
29.1k34177
add a comment |
add a comment |
A.E is a new contributor. Be nice, and check out our Code of Conduct.
A.E is a new contributor. Be nice, and check out our Code of Conduct.
A.E is a new contributor. Be nice, and check out our Code of Conduct.
A.E is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f459639%2fhow-to-draw-a-cayley-table%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
the answer provided was excellent in the above link, I would appreciate if I can get a similar answer.
– A.E
23 hours ago
3
Just take Gonzalo's answer and delete first line (the one which contains
Capacity) and two left columns and two right ones.– Ignasi
23 hours ago
1
array, nottabular.– egreg
23 hours ago
1
You Need to put $a^2$ when you want to use math!
– GiuTeX
22 hours ago
1
@A.E As it is, the added code produces tons of errors.
– egreg
22 hours ago