Multicolumn and xintfor











up vote
2
down vote

favorite












This is my first time asking a question on Stack Exchange, although I'm a frequent reader.



I tried to build a tabular that generates a sort of array, with indexes displayed above. This is the code:



$A = $
raisebox{10pt}{
setcounter{N}{5}
begin{tabular}{|*{5}{c|}}
xintFor* #1 in {xintSeq{1}{value{N}}}do{xintifForFirst{tiny #1}{& mc{tiny #1}}}\
hline
$1$ & $3$ & $5$ & $7$ & $8$\
hline
end{tabular}
}


where newcommandmc[1]{multicolumn{1}{l}{#1}}.



enter image description here



I would like it to be exactly the way it is now, but without the first two vertical lines in the indexes row. If I use mc in the first block of xintifForFirst (as I did successfully for the second block) it doesn't compile and I can't understand why. The error I get is ! Misplaced omit.
multispan ->omit @multispan



Thanks in advance :-)



Edit: As suggested by Andrew I'm writing an example of the error I get:



documentclass{article}
usepackage{tabularx}
usepackage{xinttools}

newcounter{N}
newcommandmc[1]{multicolumn{1}{l}{#1}}

newcommand{myarray}[2]{
raisebox{8pt}{
begin{tabular}{|*{#1}{c|}}
setcounter{N}{#1}
xintFor* ##1 in {xintSeq{1}{value{N}}}do{xintifForFirst{mc{ tiny ##1}}{& mc{tiny ##1}}}\
hline
#2\
hline
end{tabular}
}
}

begin{document}
$B = $myarray{11}{$0$ & $0$ & $1$ & $0$ & $1$ & $0$ & $0$ & $1$ & $0$ & $1$ & $0$}
end{document}









share|improve this question









New contributor




Gemma Martini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. To highlight code-blocks, either indent them by four spaces or use the {} on the gui.
    – Andrew
    2 days ago












  • Thank you for your suggestions, I edited the question
    – Gemma Martini
    yesterday










  • I suspect that the error has something to do with the "implementation features" box in section 15.17 (page 188) of the xint manual, but I didn't manage to solve the problem. I'm sure that @jfbu will be able to to fix this instantly.
    – Andrew
    yesterday

















up vote
2
down vote

favorite












This is my first time asking a question on Stack Exchange, although I'm a frequent reader.



I tried to build a tabular that generates a sort of array, with indexes displayed above. This is the code:



$A = $
raisebox{10pt}{
setcounter{N}{5}
begin{tabular}{|*{5}{c|}}
xintFor* #1 in {xintSeq{1}{value{N}}}do{xintifForFirst{tiny #1}{& mc{tiny #1}}}\
hline
$1$ & $3$ & $5$ & $7$ & $8$\
hline
end{tabular}
}


where newcommandmc[1]{multicolumn{1}{l}{#1}}.



enter image description here



I would like it to be exactly the way it is now, but without the first two vertical lines in the indexes row. If I use mc in the first block of xintifForFirst (as I did successfully for the second block) it doesn't compile and I can't understand why. The error I get is ! Misplaced omit.
multispan ->omit @multispan



Thanks in advance :-)



Edit: As suggested by Andrew I'm writing an example of the error I get:



documentclass{article}
usepackage{tabularx}
usepackage{xinttools}

newcounter{N}
newcommandmc[1]{multicolumn{1}{l}{#1}}

newcommand{myarray}[2]{
raisebox{8pt}{
begin{tabular}{|*{#1}{c|}}
setcounter{N}{#1}
xintFor* ##1 in {xintSeq{1}{value{N}}}do{xintifForFirst{mc{ tiny ##1}}{& mc{tiny ##1}}}\
hline
#2\
hline
end{tabular}
}
}

begin{document}
$B = $myarray{11}{$0$ & $0$ & $1$ & $0$ & $1$ & $0$ & $0$ & $1$ & $0$ & $1$ & $0$}
end{document}









share|improve this question









New contributor




Gemma Martini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. To highlight code-blocks, either indent them by four spaces or use the {} on the gui.
    – Andrew
    2 days ago












  • Thank you for your suggestions, I edited the question
    – Gemma Martini
    yesterday










  • I suspect that the error has something to do with the "implementation features" box in section 15.17 (page 188) of the xint manual, but I didn't manage to solve the problem. I'm sure that @jfbu will be able to to fix this instantly.
    – Andrew
    yesterday















up vote
2
down vote

favorite









up vote
2
down vote

favorite











This is my first time asking a question on Stack Exchange, although I'm a frequent reader.



I tried to build a tabular that generates a sort of array, with indexes displayed above. This is the code:



$A = $
raisebox{10pt}{
setcounter{N}{5}
begin{tabular}{|*{5}{c|}}
xintFor* #1 in {xintSeq{1}{value{N}}}do{xintifForFirst{tiny #1}{& mc{tiny #1}}}\
hline
$1$ & $3$ & $5$ & $7$ & $8$\
hline
end{tabular}
}


where newcommandmc[1]{multicolumn{1}{l}{#1}}.



enter image description here



I would like it to be exactly the way it is now, but without the first two vertical lines in the indexes row. If I use mc in the first block of xintifForFirst (as I did successfully for the second block) it doesn't compile and I can't understand why. The error I get is ! Misplaced omit.
multispan ->omit @multispan



Thanks in advance :-)



Edit: As suggested by Andrew I'm writing an example of the error I get:



documentclass{article}
usepackage{tabularx}
usepackage{xinttools}

newcounter{N}
newcommandmc[1]{multicolumn{1}{l}{#1}}

newcommand{myarray}[2]{
raisebox{8pt}{
begin{tabular}{|*{#1}{c|}}
setcounter{N}{#1}
xintFor* ##1 in {xintSeq{1}{value{N}}}do{xintifForFirst{mc{ tiny ##1}}{& mc{tiny ##1}}}\
hline
#2\
hline
end{tabular}
}
}

begin{document}
$B = $myarray{11}{$0$ & $0$ & $1$ & $0$ & $1$ & $0$ & $0$ & $1$ & $0$ & $1$ & $0$}
end{document}









share|improve this question









New contributor




Gemma Martini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











This is my first time asking a question on Stack Exchange, although I'm a frequent reader.



I tried to build a tabular that generates a sort of array, with indexes displayed above. This is the code:



$A = $
raisebox{10pt}{
setcounter{N}{5}
begin{tabular}{|*{5}{c|}}
xintFor* #1 in {xintSeq{1}{value{N}}}do{xintifForFirst{tiny #1}{& mc{tiny #1}}}\
hline
$1$ & $3$ & $5$ & $7$ & $8$\
hline
end{tabular}
}


where newcommandmc[1]{multicolumn{1}{l}{#1}}.



enter image description here



I would like it to be exactly the way it is now, but without the first two vertical lines in the indexes row. If I use mc in the first block of xintifForFirst (as I did successfully for the second block) it doesn't compile and I can't understand why. The error I get is ! Misplaced omit.
multispan ->omit @multispan



Thanks in advance :-)



Edit: As suggested by Andrew I'm writing an example of the error I get:



documentclass{article}
usepackage{tabularx}
usepackage{xinttools}

newcounter{N}
newcommandmc[1]{multicolumn{1}{l}{#1}}

newcommand{myarray}[2]{
raisebox{8pt}{
begin{tabular}{|*{#1}{c|}}
setcounter{N}{#1}
xintFor* ##1 in {xintSeq{1}{value{N}}}do{xintifForFirst{mc{ tiny ##1}}{& mc{tiny ##1}}}\
hline
#2\
hline
end{tabular}
}
}

begin{document}
$B = $myarray{11}{$0$ & $0$ & $1$ & $0$ & $1$ & $0$ & $0$ & $1$ & $0$ & $1$ & $0$}
end{document}






tables multicolumn xint






share|improve this question









New contributor




Gemma Martini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Gemma Martini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday





















New contributor




Gemma Martini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Gemma Martini

113




113




New contributor




Gemma Martini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Gemma Martini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Gemma Martini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. To highlight code-blocks, either indent them by four spaces or use the {} on the gui.
    – Andrew
    2 days ago












  • Thank you for your suggestions, I edited the question
    – Gemma Martini
    yesterday










  • I suspect that the error has something to do with the "implementation features" box in section 15.17 (page 188) of the xint manual, but I didn't manage to solve the problem. I'm sure that @jfbu will be able to to fix this instantly.
    – Andrew
    yesterday




















  • Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. To highlight code-blocks, either indent them by four spaces or use the {} on the gui.
    – Andrew
    2 days ago












  • Thank you for your suggestions, I edited the question
    – Gemma Martini
    yesterday










  • I suspect that the error has something to do with the "implementation features" box in section 15.17 (page 188) of the xint manual, but I didn't manage to solve the problem. I'm sure that @jfbu will be able to to fix this instantly.
    – Andrew
    yesterday


















Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. To highlight code-blocks, either indent them by four spaces or use the {} on the gui.
– Andrew
2 days ago






Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. To highlight code-blocks, either indent them by four spaces or use the {} on the gui.
– Andrew
2 days ago














Thank you for your suggestions, I edited the question
– Gemma Martini
yesterday




Thank you for your suggestions, I edited the question
– Gemma Martini
yesterday












I suspect that the error has something to do with the "implementation features" box in section 15.17 (page 188) of the xint manual, but I didn't manage to solve the problem. I'm sure that @jfbu will be able to to fix this instantly.
– Andrew
yesterday






I suspect that the error has something to do with the "implementation features" box in section 15.17 (page 188) of the xint manual, but I didn't manage to solve the problem. I'm sure that @jfbu will be able to to fix this instantly.
– Andrew
yesterday












1 Answer
1






active

oldest

votes

















up vote
1
down vote













I don't know what packages you need to load to get your code to compile with xint - I tried usepackage{xint} but this was not sufficient.



Would you consider a tikz solution that produces



enter image description here



using the code



documentclass{article}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline]{foreach x [count=c] in {#1} {
node[array, label=above:{tiny c}]at (c/2,0){$x$};
}
}
}

begin{document}

$A = Array{1,3,5,7,8}$

end{document}


EDIT - adding colour



Adding colour is fairly straightforward. If you want to have different colours in each cell then you can produce:



enter image description here



using the code:



documentclass{article}
usepackage{xcolor}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline=(current bounding box.south)]{
foreach x/col [count=c] in {#1} {
node[array, fill=col!20, label=above:{tiny c}]at (c/2,0){$x$};
}
}
}

begin{document}

$A = Array{1/red,3/blue,5/white,7/green,8/white}$

end{document}


If you want the same colour in each cell then, assuming that the cell entries are always non-negative you can use an easier input syntax by using negative numbers for colour to produce



enter image description here



using the marginally more complicated code:



documentclass{article}
usepackage{xcolor}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline=(current bounding box.south)]{
foreach x [count=c] in {#1} {
ifnumx<0relax
node[array, fill=blue!20, label=above:{tiny c}]at (c/2,0){$thenumexpr-xrelax$};
else
node[array, label=above:{tiny c}]at (c/2,0){$x$};
fi
}
}
}

begin{document}

$A = Array{1,-3,5,-7,8}$

end{document}





share|improve this answer























  • It's usepackage{xinttools}...
    – Werner
    2 days ago










  • Thank you for your suggestion, but this implementation doesn't allow change of cell color by the user of the macro... Your solution is very elegant and I like it, but my version is more appropriate for my needs, except for the fact that it doesn't compile :-(
    – Gemma Martini
    yesterday










  • @GemmaMartini Colour is not mentioned in the OP but it is easy enough to incorporate. How do you want the cell colours to change?
    – Andrew
    yesterday










  • I would like to change the colour of some cells, when I pass them to the macro... Using my code I could have used $B = $myarray{11}{cellcolor{mycolor}$0$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & $0$ & $1$ & $0$ & $1$ & $0$}
    – Gemma Martini
    yesterday












  • @GemmaMartini See my edit
    – Andrew
    yesterday











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Gemma Martini is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460834%2fmulticolumn-and-xintfor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













I don't know what packages you need to load to get your code to compile with xint - I tried usepackage{xint} but this was not sufficient.



Would you consider a tikz solution that produces



enter image description here



using the code



documentclass{article}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline]{foreach x [count=c] in {#1} {
node[array, label=above:{tiny c}]at (c/2,0){$x$};
}
}
}

begin{document}

$A = Array{1,3,5,7,8}$

end{document}


EDIT - adding colour



Adding colour is fairly straightforward. If you want to have different colours in each cell then you can produce:



enter image description here



using the code:



documentclass{article}
usepackage{xcolor}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline=(current bounding box.south)]{
foreach x/col [count=c] in {#1} {
node[array, fill=col!20, label=above:{tiny c}]at (c/2,0){$x$};
}
}
}

begin{document}

$A = Array{1/red,3/blue,5/white,7/green,8/white}$

end{document}


If you want the same colour in each cell then, assuming that the cell entries are always non-negative you can use an easier input syntax by using negative numbers for colour to produce



enter image description here



using the marginally more complicated code:



documentclass{article}
usepackage{xcolor}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline=(current bounding box.south)]{
foreach x [count=c] in {#1} {
ifnumx<0relax
node[array, fill=blue!20, label=above:{tiny c}]at (c/2,0){$thenumexpr-xrelax$};
else
node[array, label=above:{tiny c}]at (c/2,0){$x$};
fi
}
}
}

begin{document}

$A = Array{1,-3,5,-7,8}$

end{document}





share|improve this answer























  • It's usepackage{xinttools}...
    – Werner
    2 days ago










  • Thank you for your suggestion, but this implementation doesn't allow change of cell color by the user of the macro... Your solution is very elegant and I like it, but my version is more appropriate for my needs, except for the fact that it doesn't compile :-(
    – Gemma Martini
    yesterday










  • @GemmaMartini Colour is not mentioned in the OP but it is easy enough to incorporate. How do you want the cell colours to change?
    – Andrew
    yesterday










  • I would like to change the colour of some cells, when I pass them to the macro... Using my code I could have used $B = $myarray{11}{cellcolor{mycolor}$0$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & $0$ & $1$ & $0$ & $1$ & $0$}
    – Gemma Martini
    yesterday












  • @GemmaMartini See my edit
    – Andrew
    yesterday















up vote
1
down vote













I don't know what packages you need to load to get your code to compile with xint - I tried usepackage{xint} but this was not sufficient.



Would you consider a tikz solution that produces



enter image description here



using the code



documentclass{article}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline]{foreach x [count=c] in {#1} {
node[array, label=above:{tiny c}]at (c/2,0){$x$};
}
}
}

begin{document}

$A = Array{1,3,5,7,8}$

end{document}


EDIT - adding colour



Adding colour is fairly straightforward. If you want to have different colours in each cell then you can produce:



enter image description here



using the code:



documentclass{article}
usepackage{xcolor}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline=(current bounding box.south)]{
foreach x/col [count=c] in {#1} {
node[array, fill=col!20, label=above:{tiny c}]at (c/2,0){$x$};
}
}
}

begin{document}

$A = Array{1/red,3/blue,5/white,7/green,8/white}$

end{document}


If you want the same colour in each cell then, assuming that the cell entries are always non-negative you can use an easier input syntax by using negative numbers for colour to produce



enter image description here



using the marginally more complicated code:



documentclass{article}
usepackage{xcolor}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline=(current bounding box.south)]{
foreach x [count=c] in {#1} {
ifnumx<0relax
node[array, fill=blue!20, label=above:{tiny c}]at (c/2,0){$thenumexpr-xrelax$};
else
node[array, label=above:{tiny c}]at (c/2,0){$x$};
fi
}
}
}

begin{document}

$A = Array{1,-3,5,-7,8}$

end{document}





share|improve this answer























  • It's usepackage{xinttools}...
    – Werner
    2 days ago










  • Thank you for your suggestion, but this implementation doesn't allow change of cell color by the user of the macro... Your solution is very elegant and I like it, but my version is more appropriate for my needs, except for the fact that it doesn't compile :-(
    – Gemma Martini
    yesterday










  • @GemmaMartini Colour is not mentioned in the OP but it is easy enough to incorporate. How do you want the cell colours to change?
    – Andrew
    yesterday










  • I would like to change the colour of some cells, when I pass them to the macro... Using my code I could have used $B = $myarray{11}{cellcolor{mycolor}$0$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & $0$ & $1$ & $0$ & $1$ & $0$}
    – Gemma Martini
    yesterday












  • @GemmaMartini See my edit
    – Andrew
    yesterday













up vote
1
down vote










up vote
1
down vote









I don't know what packages you need to load to get your code to compile with xint - I tried usepackage{xint} but this was not sufficient.



Would you consider a tikz solution that produces



enter image description here



using the code



documentclass{article}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline]{foreach x [count=c] in {#1} {
node[array, label=above:{tiny c}]at (c/2,0){$x$};
}
}
}

begin{document}

$A = Array{1,3,5,7,8}$

end{document}


EDIT - adding colour



Adding colour is fairly straightforward. If you want to have different colours in each cell then you can produce:



enter image description here



using the code:



documentclass{article}
usepackage{xcolor}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline=(current bounding box.south)]{
foreach x/col [count=c] in {#1} {
node[array, fill=col!20, label=above:{tiny c}]at (c/2,0){$x$};
}
}
}

begin{document}

$A = Array{1/red,3/blue,5/white,7/green,8/white}$

end{document}


If you want the same colour in each cell then, assuming that the cell entries are always non-negative you can use an easier input syntax by using negative numbers for colour to produce



enter image description here



using the marginally more complicated code:



documentclass{article}
usepackage{xcolor}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline=(current bounding box.south)]{
foreach x [count=c] in {#1} {
ifnumx<0relax
node[array, fill=blue!20, label=above:{tiny c}]at (c/2,0){$thenumexpr-xrelax$};
else
node[array, label=above:{tiny c}]at (c/2,0){$x$};
fi
}
}
}

begin{document}

$A = Array{1,-3,5,-7,8}$

end{document}





share|improve this answer














I don't know what packages you need to load to get your code to compile with xint - I tried usepackage{xint} but this was not sufficient.



Would you consider a tikz solution that produces



enter image description here



using the code



documentclass{article}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline]{foreach x [count=c] in {#1} {
node[array, label=above:{tiny c}]at (c/2,0){$x$};
}
}
}

begin{document}

$A = Array{1,3,5,7,8}$

end{document}


EDIT - adding colour



Adding colour is fairly straightforward. If you want to have different colours in each cell then you can produce:



enter image description here



using the code:



documentclass{article}
usepackage{xcolor}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline=(current bounding box.south)]{
foreach x/col [count=c] in {#1} {
node[array, fill=col!20, label=above:{tiny c}]at (c/2,0){$x$};
}
}
}

begin{document}

$A = Array{1/red,3/blue,5/white,7/green,8/white}$

end{document}


If you want the same colour in each cell then, assuming that the cell entries are always non-negative you can use an easier input syntax by using negative numbers for colour to produce



enter image description here



using the marginally more complicated code:



documentclass{article}
usepackage{xcolor}
usepackage{tikz}
tikzset{array/.style={rectangle, draw, minimum width=5mm}}
newcommandArray[1]{%
tikz[baseline=(current bounding box.south)]{
foreach x [count=c] in {#1} {
ifnumx<0relax
node[array, fill=blue!20, label=above:{tiny c}]at (c/2,0){$thenumexpr-xrelax$};
else
node[array, label=above:{tiny c}]at (c/2,0){$x$};
fi
}
}
}

begin{document}

$A = Array{1,-3,5,-7,8}$

end{document}






share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered 2 days ago









Andrew

29.3k34178




29.3k34178












  • It's usepackage{xinttools}...
    – Werner
    2 days ago










  • Thank you for your suggestion, but this implementation doesn't allow change of cell color by the user of the macro... Your solution is very elegant and I like it, but my version is more appropriate for my needs, except for the fact that it doesn't compile :-(
    – Gemma Martini
    yesterday










  • @GemmaMartini Colour is not mentioned in the OP but it is easy enough to incorporate. How do you want the cell colours to change?
    – Andrew
    yesterday










  • I would like to change the colour of some cells, when I pass them to the macro... Using my code I could have used $B = $myarray{11}{cellcolor{mycolor}$0$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & $0$ & $1$ & $0$ & $1$ & $0$}
    – Gemma Martini
    yesterday












  • @GemmaMartini See my edit
    – Andrew
    yesterday


















  • It's usepackage{xinttools}...
    – Werner
    2 days ago










  • Thank you for your suggestion, but this implementation doesn't allow change of cell color by the user of the macro... Your solution is very elegant and I like it, but my version is more appropriate for my needs, except for the fact that it doesn't compile :-(
    – Gemma Martini
    yesterday










  • @GemmaMartini Colour is not mentioned in the OP but it is easy enough to incorporate. How do you want the cell colours to change?
    – Andrew
    yesterday










  • I would like to change the colour of some cells, when I pass them to the macro... Using my code I could have used $B = $myarray{11}{cellcolor{mycolor}$0$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & $0$ & $1$ & $0$ & $1$ & $0$}
    – Gemma Martini
    yesterday












  • @GemmaMartini See my edit
    – Andrew
    yesterday
















It's usepackage{xinttools}...
– Werner
2 days ago




It's usepackage{xinttools}...
– Werner
2 days ago












Thank you for your suggestion, but this implementation doesn't allow change of cell color by the user of the macro... Your solution is very elegant and I like it, but my version is more appropriate for my needs, except for the fact that it doesn't compile :-(
– Gemma Martini
yesterday




Thank you for your suggestion, but this implementation doesn't allow change of cell color by the user of the macro... Your solution is very elegant and I like it, but my version is more appropriate for my needs, except for the fact that it doesn't compile :-(
– Gemma Martini
yesterday












@GemmaMartini Colour is not mentioned in the OP but it is easy enough to incorporate. How do you want the cell colours to change?
– Andrew
yesterday




@GemmaMartini Colour is not mentioned in the OP but it is easy enough to incorporate. How do you want the cell colours to change?
– Andrew
yesterday












I would like to change the colour of some cells, when I pass them to the macro... Using my code I could have used $B = $myarray{11}{cellcolor{mycolor}$0$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & $0$ & $1$ & $0$ & $1$ & $0$}
– Gemma Martini
yesterday






I would like to change the colour of some cells, when I pass them to the macro... Using my code I could have used $B = $myarray{11}{cellcolor{mycolor}$0$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & cellcolor{mycolor}$mathbf{1}$ & cellcolor{mycolor}$0$ & $0$ & $1$ & $0$ & $1$ & $0$}
– Gemma Martini
yesterday














@GemmaMartini See my edit
– Andrew
yesterday




@GemmaMartini See my edit
– Andrew
yesterday










Gemma Martini is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Gemma Martini is a new contributor. Be nice, and check out our Code of Conduct.













Gemma Martini is a new contributor. Be nice, and check out our Code of Conduct.












Gemma Martini is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460834%2fmulticolumn-and-xintfor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Entries order in /etc/network/interfaces

新発田市

Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)