Grid using TikZ
up vote
9
down vote
favorite
I'm using the code below to generate the grid, however it's not connecting all points in the grid.
Could anyone help with this? Thank you!
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{pgfmathtruncatemacro {label}{x y}
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};}
foreach x in {1,2,3}
foreach y [count=yi] in {1,2}
draw (xy)--(xyi) (yx) --(yix) ;
end{tikzpicture}
tikz-pgf
New contributor
add a comment |
up vote
9
down vote
favorite
I'm using the code below to generate the grid, however it's not connecting all points in the grid.
Could anyone help with this? Thank you!
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{pgfmathtruncatemacro {label}{x y}
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};}
foreach x in {1,2,3}
foreach y [count=yi] in {1,2}
draw (xy)--(xyi) (yx) --(yix) ;
end{tikzpicture}
tikz-pgf
New contributor
1
Welcome to Tex.SE. Are you looking for something like this ? tex.stackexchange.com/q/460231/28557
– nidhin
2 days ago
There is no need to dopgfmathtruncatemacro {label}{x y}
, you could usenode [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{xy}$};}
without any detour.
– marmot
2 days ago
add a comment |
up vote
9
down vote
favorite
up vote
9
down vote
favorite
I'm using the code below to generate the grid, however it's not connecting all points in the grid.
Could anyone help with this? Thank you!
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{pgfmathtruncatemacro {label}{x y}
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};}
foreach x in {1,2,3}
foreach y [count=yi] in {1,2}
draw (xy)--(xyi) (yx) --(yix) ;
end{tikzpicture}
tikz-pgf
New contributor
I'm using the code below to generate the grid, however it's not connecting all points in the grid.
Could anyone help with this? Thank you!
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{pgfmathtruncatemacro {label}{x y}
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};}
foreach x in {1,2,3}
foreach y [count=yi] in {1,2}
draw (xy)--(xyi) (yx) --(yix) ;
end{tikzpicture}
tikz-pgf
tikz-pgf
New contributor
New contributor
edited 2 days ago
AndréC
5,7921937
5,7921937
New contributor
asked 2 days ago
ioana
462
462
New contributor
New contributor
1
Welcome to Tex.SE. Are you looking for something like this ? tex.stackexchange.com/q/460231/28557
– nidhin
2 days ago
There is no need to dopgfmathtruncatemacro {label}{x y}
, you could usenode [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{xy}$};}
without any detour.
– marmot
2 days ago
add a comment |
1
Welcome to Tex.SE. Are you looking for something like this ? tex.stackexchange.com/q/460231/28557
– nidhin
2 days ago
There is no need to dopgfmathtruncatemacro {label}{x y}
, you could usenode [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{xy}$};}
without any detour.
– marmot
2 days ago
1
1
Welcome to Tex.SE. Are you looking for something like this ? tex.stackexchange.com/q/460231/28557
– nidhin
2 days ago
Welcome to Tex.SE. Are you looking for something like this ? tex.stackexchange.com/q/460231/28557
– nidhin
2 days ago
There is no need to do
pgfmathtruncatemacro {label}{x y}
, you could use node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{xy}$};}
without any detour.– marmot
2 days ago
There is no need to do
pgfmathtruncatemacro {label}{x y}
, you could use node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{xy}$};}
without any detour.– marmot
2 days ago
add a comment |
3 Answers
3
active
oldest
votes
up vote
8
down vote
Unsurprisingly, a grid can be drawn with grid
... (and there is no need to do pgfmathtruncatemacro {label}{x y}
).
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9,fill=white}]
draw (1.5,1.5) grid[step=1.5] (4.5,4.5);
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{x y}$};}
end{tikzpicture}
end{document}
add a comment |
up vote
5
down vote
Do you mean this?
documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
foreach x in {1, 2, 3}
foreach y in {1, 2}
draw (1.5*x,1.5*y) -- (1.5*x,2.5*y);
foreach x in {1, 2}
foreach y in {1, 2, 3}
draw (1.5*x,1.5*y) -- (2.5*x,1.5*y);
foreach x in {1, 2, 3}
foreach y in {1, 2, 3} {
pgfmathtruncatemacro {label}{xy}
fill[color=white] (1.5*x,1.5*y) circle (0.5cm);
draw (1.5*x,1.5*y) circle (0.5cm);
node (xy) at (1.5*x,1.5*y) {$U_{label}$};
}
end{tikzpicture}
end{document}
Hope this will help!
Yes, this is what I wanted. Thank you!!
– ioana
2 days ago
add a comment |
up vote
5
down vote
The problem is that you draw a line from the node to itself, so it doesn't draw anything at all:
draw (xy)--(xyi)
Indeed, your loop generates a counter [count=yi] in {1,2}
which starts at 1
and therefore during the first iteration with x=1
and y =1
, you generate this x=1
yi=1
, etc.
Assuming you want the same result as @DũngVũ, here is another way to do it:
documentclass[crop,tikz,border=5mm]{standalone}
begin{document}
usetikzlibrary{positioning,calc}
tikzstyle{block} = [draw, rectangle, minimum height=1cm, minimum width=1cm, outer sep=0pt]
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{pgfmathtruncatemacro {label}{xy}
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};
}
foreach x in {1,2,3}
foreach y [count=yi from 2] in {1,2}
path (xy)edge(xyi)(yx)edge(yix);
end{tikzpicture}
end{document}
Thank you! It is what I was looking for!
– ioana
2 days ago
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
Unsurprisingly, a grid can be drawn with grid
... (and there is no need to do pgfmathtruncatemacro {label}{x y}
).
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9,fill=white}]
draw (1.5,1.5) grid[step=1.5] (4.5,4.5);
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{x y}$};}
end{tikzpicture}
end{document}
add a comment |
up vote
8
down vote
Unsurprisingly, a grid can be drawn with grid
... (and there is no need to do pgfmathtruncatemacro {label}{x y}
).
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9,fill=white}]
draw (1.5,1.5) grid[step=1.5] (4.5,4.5);
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{x y}$};}
end{tikzpicture}
end{document}
add a comment |
up vote
8
down vote
up vote
8
down vote
Unsurprisingly, a grid can be drawn with grid
... (and there is no need to do pgfmathtruncatemacro {label}{x y}
).
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9,fill=white}]
draw (1.5,1.5) grid[step=1.5] (4.5,4.5);
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{x y}$};}
end{tikzpicture}
end{document}
Unsurprisingly, a grid can be drawn with grid
... (and there is no need to do pgfmathtruncatemacro {label}{x y}
).
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9,fill=white}]
draw (1.5,1.5) grid[step=1.5] (4.5,4.5);
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{x y}$};}
end{tikzpicture}
end{document}
answered 2 days ago
marmot
76.1k486160
76.1k486160
add a comment |
add a comment |
up vote
5
down vote
Do you mean this?
documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
foreach x in {1, 2, 3}
foreach y in {1, 2}
draw (1.5*x,1.5*y) -- (1.5*x,2.5*y);
foreach x in {1, 2}
foreach y in {1, 2, 3}
draw (1.5*x,1.5*y) -- (2.5*x,1.5*y);
foreach x in {1, 2, 3}
foreach y in {1, 2, 3} {
pgfmathtruncatemacro {label}{xy}
fill[color=white] (1.5*x,1.5*y) circle (0.5cm);
draw (1.5*x,1.5*y) circle (0.5cm);
node (xy) at (1.5*x,1.5*y) {$U_{label}$};
}
end{tikzpicture}
end{document}
Hope this will help!
Yes, this is what I wanted. Thank you!!
– ioana
2 days ago
add a comment |
up vote
5
down vote
Do you mean this?
documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
foreach x in {1, 2, 3}
foreach y in {1, 2}
draw (1.5*x,1.5*y) -- (1.5*x,2.5*y);
foreach x in {1, 2}
foreach y in {1, 2, 3}
draw (1.5*x,1.5*y) -- (2.5*x,1.5*y);
foreach x in {1, 2, 3}
foreach y in {1, 2, 3} {
pgfmathtruncatemacro {label}{xy}
fill[color=white] (1.5*x,1.5*y) circle (0.5cm);
draw (1.5*x,1.5*y) circle (0.5cm);
node (xy) at (1.5*x,1.5*y) {$U_{label}$};
}
end{tikzpicture}
end{document}
Hope this will help!
Yes, this is what I wanted. Thank you!!
– ioana
2 days ago
add a comment |
up vote
5
down vote
up vote
5
down vote
Do you mean this?
documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
foreach x in {1, 2, 3}
foreach y in {1, 2}
draw (1.5*x,1.5*y) -- (1.5*x,2.5*y);
foreach x in {1, 2}
foreach y in {1, 2, 3}
draw (1.5*x,1.5*y) -- (2.5*x,1.5*y);
foreach x in {1, 2, 3}
foreach y in {1, 2, 3} {
pgfmathtruncatemacro {label}{xy}
fill[color=white] (1.5*x,1.5*y) circle (0.5cm);
draw (1.5*x,1.5*y) circle (0.5cm);
node (xy) at (1.5*x,1.5*y) {$U_{label}$};
}
end{tikzpicture}
end{document}
Hope this will help!
Do you mean this?
documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
foreach x in {1, 2, 3}
foreach y in {1, 2}
draw (1.5*x,1.5*y) -- (1.5*x,2.5*y);
foreach x in {1, 2}
foreach y in {1, 2, 3}
draw (1.5*x,1.5*y) -- (2.5*x,1.5*y);
foreach x in {1, 2, 3}
foreach y in {1, 2, 3} {
pgfmathtruncatemacro {label}{xy}
fill[color=white] (1.5*x,1.5*y) circle (0.5cm);
draw (1.5*x,1.5*y) circle (0.5cm);
node (xy) at (1.5*x,1.5*y) {$U_{label}$};
}
end{tikzpicture}
end{document}
Hope this will help!
answered 2 days ago
Dũng Vũ
1,04918
1,04918
Yes, this is what I wanted. Thank you!!
– ioana
2 days ago
add a comment |
Yes, this is what I wanted. Thank you!!
– ioana
2 days ago
Yes, this is what I wanted. Thank you!!
– ioana
2 days ago
Yes, this is what I wanted. Thank you!!
– ioana
2 days ago
add a comment |
up vote
5
down vote
The problem is that you draw a line from the node to itself, so it doesn't draw anything at all:
draw (xy)--(xyi)
Indeed, your loop generates a counter [count=yi] in {1,2}
which starts at 1
and therefore during the first iteration with x=1
and y =1
, you generate this x=1
yi=1
, etc.
Assuming you want the same result as @DũngVũ, here is another way to do it:
documentclass[crop,tikz,border=5mm]{standalone}
begin{document}
usetikzlibrary{positioning,calc}
tikzstyle{block} = [draw, rectangle, minimum height=1cm, minimum width=1cm, outer sep=0pt]
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{pgfmathtruncatemacro {label}{xy}
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};
}
foreach x in {1,2,3}
foreach y [count=yi from 2] in {1,2}
path (xy)edge(xyi)(yx)edge(yix);
end{tikzpicture}
end{document}
Thank you! It is what I was looking for!
– ioana
2 days ago
add a comment |
up vote
5
down vote
The problem is that you draw a line from the node to itself, so it doesn't draw anything at all:
draw (xy)--(xyi)
Indeed, your loop generates a counter [count=yi] in {1,2}
which starts at 1
and therefore during the first iteration with x=1
and y =1
, you generate this x=1
yi=1
, etc.
Assuming you want the same result as @DũngVũ, here is another way to do it:
documentclass[crop,tikz,border=5mm]{standalone}
begin{document}
usetikzlibrary{positioning,calc}
tikzstyle{block} = [draw, rectangle, minimum height=1cm, minimum width=1cm, outer sep=0pt]
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{pgfmathtruncatemacro {label}{xy}
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};
}
foreach x in {1,2,3}
foreach y [count=yi from 2] in {1,2}
path (xy)edge(xyi)(yx)edge(yix);
end{tikzpicture}
end{document}
Thank you! It is what I was looking for!
– ioana
2 days ago
add a comment |
up vote
5
down vote
up vote
5
down vote
The problem is that you draw a line from the node to itself, so it doesn't draw anything at all:
draw (xy)--(xyi)
Indeed, your loop generates a counter [count=yi] in {1,2}
which starts at 1
and therefore during the first iteration with x=1
and y =1
, you generate this x=1
yi=1
, etc.
Assuming you want the same result as @DũngVũ, here is another way to do it:
documentclass[crop,tikz,border=5mm]{standalone}
begin{document}
usetikzlibrary{positioning,calc}
tikzstyle{block} = [draw, rectangle, minimum height=1cm, minimum width=1cm, outer sep=0pt]
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{pgfmathtruncatemacro {label}{xy}
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};
}
foreach x in {1,2,3}
foreach y [count=yi from 2] in {1,2}
path (xy)edge(xyi)(yx)edge(yix);
end{tikzpicture}
end{document}
The problem is that you draw a line from the node to itself, so it doesn't draw anything at all:
draw (xy)--(xyi)
Indeed, your loop generates a counter [count=yi] in {1,2}
which starts at 1
and therefore during the first iteration with x=1
and y =1
, you generate this x=1
yi=1
, etc.
Assuming you want the same result as @DũngVũ, here is another way to do it:
documentclass[crop,tikz,border=5mm]{standalone}
begin{document}
usetikzlibrary{positioning,calc}
tikzstyle{block} = [draw, rectangle, minimum height=1cm, minimum width=1cm, outer sep=0pt]
begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=9}]
foreach x in {1, 2, 3}
foreach y in {1, 2, 3}
{pgfmathtruncatemacro {label}{xy}
node [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{label}$};
}
foreach x in {1,2,3}
foreach y [count=yi from 2] in {1,2}
path (xy)edge(xyi)(yx)edge(yix);
end{tikzpicture}
end{document}
edited 2 days ago
answered 2 days ago
AndréC
5,7921937
5,7921937
Thank you! It is what I was looking for!
– ioana
2 days ago
add a comment |
Thank you! It is what I was looking for!
– ioana
2 days ago
Thank you! It is what I was looking for!
– ioana
2 days ago
Thank you! It is what I was looking for!
– ioana
2 days ago
add a comment |
ioana is a new contributor. Be nice, and check out our Code of Conduct.
ioana is a new contributor. Be nice, and check out our Code of Conduct.
ioana is a new contributor. Be nice, and check out our Code of Conduct.
ioana 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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460284%2fgrid-using-tikz%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
1
Welcome to Tex.SE. Are you looking for something like this ? tex.stackexchange.com/q/460231/28557
– nidhin
2 days ago
There is no need to do
pgfmathtruncatemacro {label}{x y}
, you could usenode [darkstyle] (xy) at (1.5*x,1.5*y) {$U_{xy}$};}
without any detour.– marmot
2 days ago