Tikz: Zero-padding node labels?
up vote
5
down vote
favorite
I define an array in the following way:
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
pgfmathtruncatemacro{nodelabel}{x + y*n}
node at (x,y) (x) {cnodelabel};
}
}
end{tikzpicture}
How can can I zero-pad the node labels such that I get c001
, c010
etc.?
tikz-pgf labels
New contributor
add a comment |
up vote
5
down vote
favorite
I define an array in the following way:
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
pgfmathtruncatemacro{nodelabel}{x + y*n}
node at (x,y) (x) {cnodelabel};
}
}
end{tikzpicture}
How can can I zero-pad the node labels such that I get c001
, c010
etc.?
tikz-pgf labels
New contributor
node at (x,y) (x) {c0nodelabel};
?
– marmot
2 days ago
1
Welcome to TeX.se. For your future questions, please don't post code fragments. Instead put them into complete compilable documents as I did in my answer. This makes it a lot easier for people to help you.
– Alan Munn
2 days ago
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I define an array in the following way:
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
pgfmathtruncatemacro{nodelabel}{x + y*n}
node at (x,y) (x) {cnodelabel};
}
}
end{tikzpicture}
How can can I zero-pad the node labels such that I get c001
, c010
etc.?
tikz-pgf labels
New contributor
I define an array in the following way:
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
pgfmathtruncatemacro{nodelabel}{x + y*n}
node at (x,y) (x) {cnodelabel};
}
}
end{tikzpicture}
How can can I zero-pad the node labels such that I get c001
, c010
etc.?
tikz-pgf labels
tikz-pgf labels
New contributor
New contributor
New contributor
asked 2 days ago
loris
262
262
New contributor
New contributor
node at (x,y) (x) {c0nodelabel};
?
– marmot
2 days ago
1
Welcome to TeX.se. For your future questions, please don't post code fragments. Instead put them into complete compilable documents as I did in my answer. This makes it a lot easier for people to help you.
– Alan Munn
2 days ago
add a comment |
node at (x,y) (x) {c0nodelabel};
?
– marmot
2 days ago
1
Welcome to TeX.se. For your future questions, please don't post code fragments. Instead put them into complete compilable documents as I did in my answer. This makes it a lot easier for people to help you.
– Alan Munn
2 days ago
node at (x,y) (x) {c0nodelabel};
?– marmot
2 days ago
node at (x,y) (x) {c0nodelabel};
?– marmot
2 days ago
1
1
Welcome to TeX.se. For your future questions, please don't post code fragments. Instead put them into complete compilable documents as I did in my answer. This makes it a lot easier for people to help you.
– Alan Munn
2 days ago
Welcome to TeX.se. For your future questions, please don't post code fragments. Instead put them into complete compilable documents as I did in my answer. This makes it a lot easier for people to help you.
– Alan Munn
2 days ago
add a comment |
3 Answers
3
active
oldest
votes
up vote
3
down vote
Adapting the PGF answer given here: How to output a counter with leading zeros? we can use the same approach with your example. Instead of using pgfmathtruncatemacro
I've use pgfmathsetcounter
and then used the base conversion to pad the zeros.
documentclass{article}
usepackage{tikz}
newcounter{nodelabel}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathsetbasenumberlength{3}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
pgfmathsetcounter{nodelabel}{x + y*n}
pgfmathbasetodecnodelabel{thevalue{nodelabel}}{10}%
node at (x,y) (x) {cnodelabel};
}
}
end{tikzpicture}
end{document}
add a comment |
up vote
2
down vote
Another solution with siuntix
:
documentclass{article}
usepackage{siunitx}
usepackage{tikz}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y [evaluate=y as ni using {int(x+y*n)}] in {0,...,pgfmathresult} {
node at (x,y) {cnum[minimum-integer-digits=3]{ni}};
}
}
end{tikzpicture}
end{document}
add a comment |
up vote
2
down vote
Update:
I may have misunderstood the question, because labels can be written naturally like this:
documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
node at (x,y) (x) {c0yx};
}
}
end{tikzpicture}
end{document}
Old answer:
You can use the macro opprint
from the xlop
package that prints the numbers as they are written useless zeros included.
For example 00000.000
will be written 00000.000
documentclass{article}
usepackage{tikz}
usepackage{xlop}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
node at (x,y) (x) {copprint{0yx}};
}
}
end{tikzpicture}
end{document}
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Adapting the PGF answer given here: How to output a counter with leading zeros? we can use the same approach with your example. Instead of using pgfmathtruncatemacro
I've use pgfmathsetcounter
and then used the base conversion to pad the zeros.
documentclass{article}
usepackage{tikz}
newcounter{nodelabel}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathsetbasenumberlength{3}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
pgfmathsetcounter{nodelabel}{x + y*n}
pgfmathbasetodecnodelabel{thevalue{nodelabel}}{10}%
node at (x,y) (x) {cnodelabel};
}
}
end{tikzpicture}
end{document}
add a comment |
up vote
3
down vote
Adapting the PGF answer given here: How to output a counter with leading zeros? we can use the same approach with your example. Instead of using pgfmathtruncatemacro
I've use pgfmathsetcounter
and then used the base conversion to pad the zeros.
documentclass{article}
usepackage{tikz}
newcounter{nodelabel}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathsetbasenumberlength{3}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
pgfmathsetcounter{nodelabel}{x + y*n}
pgfmathbasetodecnodelabel{thevalue{nodelabel}}{10}%
node at (x,y) (x) {cnodelabel};
}
}
end{tikzpicture}
end{document}
add a comment |
up vote
3
down vote
up vote
3
down vote
Adapting the PGF answer given here: How to output a counter with leading zeros? we can use the same approach with your example. Instead of using pgfmathtruncatemacro
I've use pgfmathsetcounter
and then used the base conversion to pad the zeros.
documentclass{article}
usepackage{tikz}
newcounter{nodelabel}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathsetbasenumberlength{3}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
pgfmathsetcounter{nodelabel}{x + y*n}
pgfmathbasetodecnodelabel{thevalue{nodelabel}}{10}%
node at (x,y) (x) {cnodelabel};
}
}
end{tikzpicture}
end{document}
Adapting the PGF answer given here: How to output a counter with leading zeros? we can use the same approach with your example. Instead of using pgfmathtruncatemacro
I've use pgfmathsetcounter
and then used the base conversion to pad the zeros.
documentclass{article}
usepackage{tikz}
newcounter{nodelabel}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathsetbasenumberlength{3}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
pgfmathsetcounter{nodelabel}{x + y*n}
pgfmathbasetodecnodelabel{thevalue{nodelabel}}{10}%
node at (x,y) (x) {cnodelabel};
}
}
end{tikzpicture}
end{document}
answered 2 days ago
Alan Munn
158k27422695
158k27422695
add a comment |
add a comment |
up vote
2
down vote
Another solution with siuntix
:
documentclass{article}
usepackage{siunitx}
usepackage{tikz}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y [evaluate=y as ni using {int(x+y*n)}] in {0,...,pgfmathresult} {
node at (x,y) {cnum[minimum-integer-digits=3]{ni}};
}
}
end{tikzpicture}
end{document}
add a comment |
up vote
2
down vote
Another solution with siuntix
:
documentclass{article}
usepackage{siunitx}
usepackage{tikz}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y [evaluate=y as ni using {int(x+y*n)}] in {0,...,pgfmathresult} {
node at (x,y) {cnum[minimum-integer-digits=3]{ni}};
}
}
end{tikzpicture}
end{document}
add a comment |
up vote
2
down vote
up vote
2
down vote
Another solution with siuntix
:
documentclass{article}
usepackage{siunitx}
usepackage{tikz}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y [evaluate=y as ni using {int(x+y*n)}] in {0,...,pgfmathresult} {
node at (x,y) {cnum[minimum-integer-digits=3]{ni}};
}
}
end{tikzpicture}
end{document}
Another solution with siuntix
:
documentclass{article}
usepackage{siunitx}
usepackage{tikz}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y [evaluate=y as ni using {int(x+y*n)}] in {0,...,pgfmathresult} {
node at (x,y) {cnum[minimum-integer-digits=3]{ni}};
}
}
end{tikzpicture}
end{document}
answered 2 days ago
Ignasi
90.5k4164303
90.5k4164303
add a comment |
add a comment |
up vote
2
down vote
Update:
I may have misunderstood the question, because labels can be written naturally like this:
documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
node at (x,y) (x) {c0yx};
}
}
end{tikzpicture}
end{document}
Old answer:
You can use the macro opprint
from the xlop
package that prints the numbers as they are written useless zeros included.
For example 00000.000
will be written 00000.000
documentclass{article}
usepackage{tikz}
usepackage{xlop}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
node at (x,y) (x) {copprint{0yx}};
}
}
end{tikzpicture}
end{document}
add a comment |
up vote
2
down vote
Update:
I may have misunderstood the question, because labels can be written naturally like this:
documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
node at (x,y) (x) {c0yx};
}
}
end{tikzpicture}
end{document}
Old answer:
You can use the macro opprint
from the xlop
package that prints the numbers as they are written useless zeros included.
For example 00000.000
will be written 00000.000
documentclass{article}
usepackage{tikz}
usepackage{xlop}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
node at (x,y) (x) {copprint{0yx}};
}
}
end{tikzpicture}
end{document}
add a comment |
up vote
2
down vote
up vote
2
down vote
Update:
I may have misunderstood the question, because labels can be written naturally like this:
documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
node at (x,y) (x) {c0yx};
}
}
end{tikzpicture}
end{document}
Old answer:
You can use the macro opprint
from the xlop
package that prints the numbers as they are written useless zeros included.
For example 00000.000
will be written 00000.000
documentclass{article}
usepackage{tikz}
usepackage{xlop}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
node at (x,y) (x) {copprint{0yx}};
}
}
end{tikzpicture}
end{document}
Update:
I may have misunderstood the question, because labels can be written naturally like this:
documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
node at (x,y) (x) {c0yx};
}
}
end{tikzpicture}
end{document}
Old answer:
You can use the macro opprint
from the xlop
package that prints the numbers as they are written useless zeros included.
For example 00000.000
will be written 00000.000
documentclass{article}
usepackage{tikz}
usepackage{xlop}
begin{document}
begin{tikzpicture}
defn{10}
pgfmathparse{int(n-1)}
foreach x in {0,...,pgfmathresult} {
foreach y in {0,...,pgfmathresult} {
node at (x,y) (x) {copprint{0yx}};
}
}
end{tikzpicture}
end{document}
edited 2 days ago
answered 2 days ago
AndréC
6,59711140
6,59711140
add a comment |
add a comment |
loris is a new contributor. Be nice, and check out our Code of Conduct.
loris is a new contributor. Be nice, and check out our Code of Conduct.
loris is a new contributor. Be nice, and check out our Code of Conduct.
loris is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f462563%2ftikz-zero-padding-node-labels%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
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
node at (x,y) (x) {c0nodelabel};
?– marmot
2 days ago
1
Welcome to TeX.se. For your future questions, please don't post code fragments. Instead put them into complete compilable documents as I did in my answer. This makes it a lot easier for people to help you.
– Alan Munn
2 days ago