Loop counter not interpreted as numberRotate a node but not its content: the case of the ellipse...
How effective would a full set of plate armor be against wild animals found in temperate regions (bears, snakes, wolves)?
The best in flight meal option for those suffering from reflux
Will users know a CardView is clickable
Jam with honey & without pectin has a saucy consistency always
Commencez à vous connecter -- I don't understand the phrasing of this
Realistic, logical way for men with medieval-era weaponry to compete with much larger and physically stronger foes
Does WiFi affect the quality of images downloaded from the internet?
Parsing text written the millitext font
Why is it bad to use your whole foot in rock climbing
typeid("") != typeid(const char*)
Should I move out from my current apartment before the contract ends to save more money?
Was the Lonely Mountain, where Smaug lived, a volcano?
How can I find out about the game world without meta-influencing it?
What publication claimed that Michael Jackson died in a nuclear holocaust?
Is it true that "only photographers care about noise"?
Am I allowed to determine tenets of my contract as a warlock?
Can Dive Down protect a creature against Pacifism?
Why did the AvroCar fail to fly above 3 feet?
Past vs. present tense when referring to a fictional character
Why does there seem to be an extreme lack of public trashcans in Taiwan?
Optimising matrix generation time
What are the advantages of using TLRs to rangefinders?
Fastest way from 10 to 1 with everyone in between
Is it ethical to cite a reviewer's papers even if they are rather irrelevant?
Loop counter not interpreted as number
Rotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?Numerical conditional within tikz keys?TikZ/ERD: node (=Entity) label on the insideWhy do I get an extra white page before my TikZ picture?TikZ: Drawing an arc from an intersection to an intersectionHow to prevent rounded and duplicated tick labels in pgfplots with fixed precision?Drawing rectilinear curves in Tikz, aka an Etch-a-Sketch drawingLine up nested tikz enviroments or how to get rid of themHow to draw a square and its diagonals with arrows?
I'd like to create 32 small boxes next to each other that each contain its current index.
|0|1|2|3|...|31|
This code makes me trouble:
documentclass{article}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i in {0, 31} {
node[box, right=of i] (i + 1) {i+1};
}
end{tikzpicture}
end{document}
I have the impression that {i+1} is not interpreted, but instead i+1 is actually written for a given i. How can I make tikz to compute i+1 and to assign the result as a name or label?
tikz-pgf
add a comment |
I'd like to create 32 small boxes next to each other that each contain its current index.
|0|1|2|3|...|31|
This code makes me trouble:
documentclass{article}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i in {0, 31} {
node[box, right=of i] (i + 1) {i+1};
}
end{tikzpicture}
end{document}
I have the impression that {i+1} is not interpreted, but instead i+1 is actually written for a given i. How can I make tikz to compute i+1 and to assign the result as a name or label?
tikz-pgf
add a comment |
I'd like to create 32 small boxes next to each other that each contain its current index.
|0|1|2|3|...|31|
This code makes me trouble:
documentclass{article}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i in {0, 31} {
node[box, right=of i] (i + 1) {i+1};
}
end{tikzpicture}
end{document}
I have the impression that {i+1} is not interpreted, but instead i+1 is actually written for a given i. How can I make tikz to compute i+1 and to assign the result as a name or label?
tikz-pgf
I'd like to create 32 small boxes next to each other that each contain its current index.
|0|1|2|3|...|31|
This code makes me trouble:
documentclass{article}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i in {0, 31} {
node[box, right=of i] (i + 1) {i+1};
}
end{tikzpicture}
end{document}
I have the impression that {i+1} is not interpreted, but instead i+1 is actually written for a given i. How can I make tikz to compute i+1 and to assign the result as a name or label?
tikz-pgf
tikz-pgf
asked 8 hours ago
nullnull
1325
1325
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Even another solution:
documentclass[tikz, border=2mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i [remember=i as lasti (initially 0), count=ni] in {1, ..., 31} {
node[box, right=of lasti] (ni) {ni};
}
end{tikzpicture}
end{document}
add a comment |
A variation of Ignasi's answer where you can easily change upper and lower bound of the foreach
-range.
documentclass[tikz, border=2mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}
]
foreach i [remember=i as lasti (initially a)] in {0, ..., 31} {
if alasti
node[box](i) {i};
else
node[box, right=of lasti](i) {i};
fi
}
end{tikzpicture}
end{document}
add a comment |
Yes, your impression is right. One way to enforce evaluation is to use numexpr
.
documentclass{article}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i in {0,..., 31} {
node[box, right=of i] (thenumexpri + 1relax)
{thenumexpri+1relax};
}
end{tikzpicture}
end{document}
The less hacky way, though, is to use evaluate.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i [evaluate=i as nexti using {int(i+1)}] in {0,..., 31} {
node[box, right=of i] (nexti)
{nexti};
}
end{tikzpicture}
end{document}
Here is a pic
version thereof.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm},
pics/boxrow/.style 2 args={code={
node[box] (#1){#1};
foreach i [evaluate=i as nexti using {int(i+1)}] in
{#1,thenumexpr#1+1,...,#2} {
node[box, right=of i] (nexti) {nexti};
}
}}]
path (0,0) pic{boxrow={0}{30}}
(0,-1) pic{boxrow={5}{18}};
end{tikzpicture}
end{document}
@UlrichDiez 33 includes 32. One only needs to adjust the upper and lower bounds to achieve whatever one likes.
– marmot
8 hours ago
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
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%2f495477%2floop-counter-not-interpreted-as-number%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Even another solution:
documentclass[tikz, border=2mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i [remember=i as lasti (initially 0), count=ni] in {1, ..., 31} {
node[box, right=of lasti] (ni) {ni};
}
end{tikzpicture}
end{document}
add a comment |
Even another solution:
documentclass[tikz, border=2mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i [remember=i as lasti (initially 0), count=ni] in {1, ..., 31} {
node[box, right=of lasti] (ni) {ni};
}
end{tikzpicture}
end{document}
add a comment |
Even another solution:
documentclass[tikz, border=2mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i [remember=i as lasti (initially 0), count=ni] in {1, ..., 31} {
node[box, right=of lasti] (ni) {ni};
}
end{tikzpicture}
end{document}
Even another solution:
documentclass[tikz, border=2mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i [remember=i as lasti (initially 0), count=ni] in {1, ..., 31} {
node[box, right=of lasti] (ni) {ni};
}
end{tikzpicture}
end{document}
answered 8 hours ago
IgnasiIgnasi
97.8k6179327
97.8k6179327
add a comment |
add a comment |
A variation of Ignasi's answer where you can easily change upper and lower bound of the foreach
-range.
documentclass[tikz, border=2mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}
]
foreach i [remember=i as lasti (initially a)] in {0, ..., 31} {
if alasti
node[box](i) {i};
else
node[box, right=of lasti](i) {i};
fi
}
end{tikzpicture}
end{document}
add a comment |
A variation of Ignasi's answer where you can easily change upper and lower bound of the foreach
-range.
documentclass[tikz, border=2mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}
]
foreach i [remember=i as lasti (initially a)] in {0, ..., 31} {
if alasti
node[box](i) {i};
else
node[box, right=of lasti](i) {i};
fi
}
end{tikzpicture}
end{document}
add a comment |
A variation of Ignasi's answer where you can easily change upper and lower bound of the foreach
-range.
documentclass[tikz, border=2mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}
]
foreach i [remember=i as lasti (initially a)] in {0, ..., 31} {
if alasti
node[box](i) {i};
else
node[box, right=of lasti](i) {i};
fi
}
end{tikzpicture}
end{document}
A variation of Ignasi's answer where you can easily change upper and lower bound of the foreach
-range.
documentclass[tikz, border=2mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}
]
foreach i [remember=i as lasti (initially a)] in {0, ..., 31} {
if alasti
node[box](i) {i};
else
node[box, right=of lasti](i) {i};
fi
}
end{tikzpicture}
end{document}
edited 6 hours ago
answered 6 hours ago
Ulrich DiezUlrich Diez
6,302622
6,302622
add a comment |
add a comment |
Yes, your impression is right. One way to enforce evaluation is to use numexpr
.
documentclass{article}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i in {0,..., 31} {
node[box, right=of i] (thenumexpri + 1relax)
{thenumexpri+1relax};
}
end{tikzpicture}
end{document}
The less hacky way, though, is to use evaluate.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i [evaluate=i as nexti using {int(i+1)}] in {0,..., 31} {
node[box, right=of i] (nexti)
{nexti};
}
end{tikzpicture}
end{document}
Here is a pic
version thereof.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm},
pics/boxrow/.style 2 args={code={
node[box] (#1){#1};
foreach i [evaluate=i as nexti using {int(i+1)}] in
{#1,thenumexpr#1+1,...,#2} {
node[box, right=of i] (nexti) {nexti};
}
}}]
path (0,0) pic{boxrow={0}{30}}
(0,-1) pic{boxrow={5}{18}};
end{tikzpicture}
end{document}
@UlrichDiez 33 includes 32. One only needs to adjust the upper and lower bounds to achieve whatever one likes.
– marmot
8 hours ago
add a comment |
Yes, your impression is right. One way to enforce evaluation is to use numexpr
.
documentclass{article}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i in {0,..., 31} {
node[box, right=of i] (thenumexpri + 1relax)
{thenumexpri+1relax};
}
end{tikzpicture}
end{document}
The less hacky way, though, is to use evaluate.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i [evaluate=i as nexti using {int(i+1)}] in {0,..., 31} {
node[box, right=of i] (nexti)
{nexti};
}
end{tikzpicture}
end{document}
Here is a pic
version thereof.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm},
pics/boxrow/.style 2 args={code={
node[box] (#1){#1};
foreach i [evaluate=i as nexti using {int(i+1)}] in
{#1,thenumexpr#1+1,...,#2} {
node[box, right=of i] (nexti) {nexti};
}
}}]
path (0,0) pic{boxrow={0}{30}}
(0,-1) pic{boxrow={5}{18}};
end{tikzpicture}
end{document}
@UlrichDiez 33 includes 32. One only needs to adjust the upper and lower bounds to achieve whatever one likes.
– marmot
8 hours ago
add a comment |
Yes, your impression is right. One way to enforce evaluation is to use numexpr
.
documentclass{article}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i in {0,..., 31} {
node[box, right=of i] (thenumexpri + 1relax)
{thenumexpri+1relax};
}
end{tikzpicture}
end{document}
The less hacky way, though, is to use evaluate.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i [evaluate=i as nexti using {int(i+1)}] in {0,..., 31} {
node[box, right=of i] (nexti)
{nexti};
}
end{tikzpicture}
end{document}
Here is a pic
version thereof.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm},
pics/boxrow/.style 2 args={code={
node[box] (#1){#1};
foreach i [evaluate=i as nexti using {int(i+1)}] in
{#1,thenumexpr#1+1,...,#2} {
node[box, right=of i] (nexti) {nexti};
}
}}]
path (0,0) pic{boxrow={0}{30}}
(0,-1) pic{boxrow={5}{18}};
end{tikzpicture}
end{document}
Yes, your impression is right. One way to enforce evaluation is to use numexpr
.
documentclass{article}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i in {0,..., 31} {
node[box, right=of i] (thenumexpri + 1relax)
{thenumexpri+1relax};
}
end{tikzpicture}
end{document}
The less hacky way, though, is to use evaluate.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm}]
node[box](0) {0};
foreach i [evaluate=i as nexti using {int(i+1)}] in {0,..., 31} {
node[box, right=of i] (nexti)
{nexti};
}
end{tikzpicture}
end{document}
Here is a pic
version thereof.
documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[
node distance=0pt,
box/.style={outer sep=0pt, draw, thick, minimum height=0.6cm},
pics/boxrow/.style 2 args={code={
node[box] (#1){#1};
foreach i [evaluate=i as nexti using {int(i+1)}] in
{#1,thenumexpr#1+1,...,#2} {
node[box, right=of i] (nexti) {nexti};
}
}}]
path (0,0) pic{boxrow={0}{30}}
(0,-1) pic{boxrow={5}{18}};
end{tikzpicture}
end{document}
edited 22 mins ago
Ulrich Diez
6,302622
6,302622
answered 8 hours ago
marmotmarmot
135k6176324
135k6176324
@UlrichDiez 33 includes 32. One only needs to adjust the upper and lower bounds to achieve whatever one likes.
– marmot
8 hours ago
add a comment |
@UlrichDiez 33 includes 32. One only needs to adjust the upper and lower bounds to achieve whatever one likes.
– marmot
8 hours ago
@UlrichDiez 33 includes 32. One only needs to adjust the upper and lower bounds to achieve whatever one likes.
– marmot
8 hours ago
@UlrichDiez 33 includes 32. One only needs to adjust the upper and lower bounds to achieve whatever one likes.
– marmot
8 hours ago
add a comment |
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.
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%2f495477%2floop-counter-not-interpreted-as-number%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