TikZ graph edges not drawn nicely
I am still new to using Tikz... I am trying to draw a wheel-like graph using TikZ. I have the basic graph done, but it is not turning out how I expected it to. The edges in my graph aren't centered/lined up well.
The edges seem to be following the coordinates rather than drawing a shortest-path straight line between the nodes stopping at their circle representations. Some of the edges are fine (like v1 to v2, v1 to v6, ...) but some others aren't (like v2 to v3).
Here is my code for the TikZ picture, and an image showing what I am getting.
begin{tikzpicture}[auto, scale=0.9]
tikzstyle{vertex}=[draw, circle, inner sep=0.55mm]
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x in {2, 3, 4, 5, 6, 7}{
pgfmathsetmacroy{x - 1}
draw (vy) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}

tikz-pgf graphs
New contributor
Abraham is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I am still new to using Tikz... I am trying to draw a wheel-like graph using TikZ. I have the basic graph done, but it is not turning out how I expected it to. The edges in my graph aren't centered/lined up well.
The edges seem to be following the coordinates rather than drawing a shortest-path straight line between the nodes stopping at their circle representations. Some of the edges are fine (like v1 to v2, v1 to v6, ...) but some others aren't (like v2 to v3).
Here is my code for the TikZ picture, and an image showing what I am getting.
begin{tikzpicture}[auto, scale=0.9]
tikzstyle{vertex}=[draw, circle, inner sep=0.55mm]
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x in {2, 3, 4, 5, 6, 7}{
pgfmathsetmacroy{x - 1}
draw (vy) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}

tikz-pgf graphs
New contributor
Abraham is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The issue is thatpgfmathsetmacrodoes not yield integers, but something like2.0, where.0gets interpreted as node anchor.
– marmot
4 hours ago
add a comment |
I am still new to using Tikz... I am trying to draw a wheel-like graph using TikZ. I have the basic graph done, but it is not turning out how I expected it to. The edges in my graph aren't centered/lined up well.
The edges seem to be following the coordinates rather than drawing a shortest-path straight line between the nodes stopping at their circle representations. Some of the edges are fine (like v1 to v2, v1 to v6, ...) but some others aren't (like v2 to v3).
Here is my code for the TikZ picture, and an image showing what I am getting.
begin{tikzpicture}[auto, scale=0.9]
tikzstyle{vertex}=[draw, circle, inner sep=0.55mm]
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x in {2, 3, 4, 5, 6, 7}{
pgfmathsetmacroy{x - 1}
draw (vy) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}

tikz-pgf graphs
New contributor
Abraham is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am still new to using Tikz... I am trying to draw a wheel-like graph using TikZ. I have the basic graph done, but it is not turning out how I expected it to. The edges in my graph aren't centered/lined up well.
The edges seem to be following the coordinates rather than drawing a shortest-path straight line between the nodes stopping at their circle representations. Some of the edges are fine (like v1 to v2, v1 to v6, ...) but some others aren't (like v2 to v3).
Here is my code for the TikZ picture, and an image showing what I am getting.
begin{tikzpicture}[auto, scale=0.9]
tikzstyle{vertex}=[draw, circle, inner sep=0.55mm]
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x in {2, 3, 4, 5, 6, 7}{
pgfmathsetmacroy{x - 1}
draw (vy) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}

tikz-pgf graphs
tikz-pgf graphs
New contributor
Abraham is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Abraham is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Abraham is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 4 hours ago
AbrahamAbraham
283
283
New contributor
Abraham is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Abraham is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Abraham is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The issue is thatpgfmathsetmacrodoes not yield integers, but something like2.0, where.0gets interpreted as node anchor.
– marmot
4 hours ago
add a comment |
The issue is thatpgfmathsetmacrodoes not yield integers, but something like2.0, where.0gets interpreted as node anchor.
– marmot
4 hours ago
The issue is that
pgfmathsetmacro does not yield integers, but something like 2.0, where .0 gets interpreted as node anchor.– marmot
4 hours ago
The issue is that
pgfmathsetmacro does not yield integers, but something like 2.0, where .0 gets interpreted as node anchor.– marmot
4 hours ago
add a comment |
4 Answers
4
active
oldest
votes
That's because the calculation of y doesn't give an integer. There are two possibilities:
- the first is to use the macro
pgfmathtruncatemacroinstead ofpgfmathsetmacro
- the second is to evaluate
ywithin the foreach loop itself
documentclass[tikz,border=5mm]{standalone}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[auto, scale=0.9]
tikzstyle{vertex}=[draw, circle, inner sep=0.55mm]
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x[evaluate=x as y using int(x-1)] in {2, 3, 4, 5, 6, 7}{
%pgfmathtruncatemacroy{x - 1}
draw (vy) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}
end{document}

On my computer the lineforeach x[evaluate=x as y using int(x-1)]☺ in {2, 3, 4, 5, 6, 7}{looks like it has an smiley face in it...
– Abraham
4 hours ago
ok, fixed now !
– AndréC
4 hours ago
This works, seems thatpgfmathsetmacrowas the problem, as @marmot explained. Thank you!
– Abraham
4 hours ago
I have given two possibilities to correct this problem.
– AndréC
4 hours ago
This was the first answer, and now that an explanation was added, I am marking this as the accepted answer. The other answers were helpful as well!
– Abraham
36 mins ago
add a comment |
tikzstyle is deprecated and the issue is that pgfmathsetmacro does not yield integers, but something like 2.0, where .0 gets interpreted as node anchor.
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[auto, scale=0.9]
tikzset{vertex/.style={draw, circle, inner sep=0.55mm}}
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x [remember =x as lastx (initially 1)] in {2, 3, 4, 5, 6, 7}{
draw (vlastx) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}
end{document}

add a comment |
To get it more wheel like you can use polar coordinates, like (1,45) to draw a node at distance 1 and 45 degrees from origin. Here is an alternative version with a variable number of nodes. Change the number in numNodes{6} to change the number of nodes n the circle.
documentclass[border=5mm]{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[
auto,
scale=0.9,
vert/.style={draw, circle, inner sep=0.55mm,fill=white}
]
newcommandnumNodes{6}
node[vert,fill=blue] (vC) at (0,0){};
draw (0:1) node[vert](v0) {}
foreach n [evaluate = n as deg using {n*360/numNodes}] in {1,2,...,numNodes}{
-- (deg:1) node[vert](vn) {}
};
foreach n in {0,3,4,5}{
draw (vC) -- (vn);
}
end{tikzpicture}
end {document}

you have a typo(1,45)is not a polar coordinate
– AndréC
3 hours ago
add a comment |
maybe you will like:
documentclass[tikz,border=5mm]{standalone}
usetikzlibrary{shapes.geometric}
begin{document}
begin{tikzpicture}[
vertex/.style = {circle, draw, fill=#1, inner sep=0.5mm}
]
%
node (s) [regular polygon,regular polygon sides=6,
draw, minimum size=20mm, above] at (0.5,-2) {};
draw (s.corner 3) -- (s.corner 6);
node (c) [vertex=blue] at (s.center) {};
%
foreach i in {1,...,6}{node (si) [vertex=white] at (s.corner i) {}; }
draw (c) -- (s4)
(c) -- (s5);
end{tikzpicture}
end{document}

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
});
}
});
Abraham 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%2f476800%2ftikz-graph-edges-not-drawn-nicely%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
That's because the calculation of y doesn't give an integer. There are two possibilities:
- the first is to use the macro
pgfmathtruncatemacroinstead ofpgfmathsetmacro
- the second is to evaluate
ywithin the foreach loop itself
documentclass[tikz,border=5mm]{standalone}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[auto, scale=0.9]
tikzstyle{vertex}=[draw, circle, inner sep=0.55mm]
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x[evaluate=x as y using int(x-1)] in {2, 3, 4, 5, 6, 7}{
%pgfmathtruncatemacroy{x - 1}
draw (vy) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}
end{document}

On my computer the lineforeach x[evaluate=x as y using int(x-1)]☺ in {2, 3, 4, 5, 6, 7}{looks like it has an smiley face in it...
– Abraham
4 hours ago
ok, fixed now !
– AndréC
4 hours ago
This works, seems thatpgfmathsetmacrowas the problem, as @marmot explained. Thank you!
– Abraham
4 hours ago
I have given two possibilities to correct this problem.
– AndréC
4 hours ago
This was the first answer, and now that an explanation was added, I am marking this as the accepted answer. The other answers were helpful as well!
– Abraham
36 mins ago
add a comment |
That's because the calculation of y doesn't give an integer. There are two possibilities:
- the first is to use the macro
pgfmathtruncatemacroinstead ofpgfmathsetmacro
- the second is to evaluate
ywithin the foreach loop itself
documentclass[tikz,border=5mm]{standalone}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[auto, scale=0.9]
tikzstyle{vertex}=[draw, circle, inner sep=0.55mm]
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x[evaluate=x as y using int(x-1)] in {2, 3, 4, 5, 6, 7}{
%pgfmathtruncatemacroy{x - 1}
draw (vy) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}
end{document}

On my computer the lineforeach x[evaluate=x as y using int(x-1)]☺ in {2, 3, 4, 5, 6, 7}{looks like it has an smiley face in it...
– Abraham
4 hours ago
ok, fixed now !
– AndréC
4 hours ago
This works, seems thatpgfmathsetmacrowas the problem, as @marmot explained. Thank you!
– Abraham
4 hours ago
I have given two possibilities to correct this problem.
– AndréC
4 hours ago
This was the first answer, and now that an explanation was added, I am marking this as the accepted answer. The other answers were helpful as well!
– Abraham
36 mins ago
add a comment |
That's because the calculation of y doesn't give an integer. There are two possibilities:
- the first is to use the macro
pgfmathtruncatemacroinstead ofpgfmathsetmacro
- the second is to evaluate
ywithin the foreach loop itself
documentclass[tikz,border=5mm]{standalone}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[auto, scale=0.9]
tikzstyle{vertex}=[draw, circle, inner sep=0.55mm]
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x[evaluate=x as y using int(x-1)] in {2, 3, 4, 5, 6, 7}{
%pgfmathtruncatemacroy{x - 1}
draw (vy) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}
end{document}

That's because the calculation of y doesn't give an integer. There are two possibilities:
- the first is to use the macro
pgfmathtruncatemacroinstead ofpgfmathsetmacro
- the second is to evaluate
ywithin the foreach loop itself
documentclass[tikz,border=5mm]{standalone}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[auto, scale=0.9]
tikzstyle{vertex}=[draw, circle, inner sep=0.55mm]
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x[evaluate=x as y using int(x-1)] in {2, 3, 4, 5, 6, 7}{
%pgfmathtruncatemacroy{x - 1}
draw (vy) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}
end{document}

edited 4 hours ago
answered 4 hours ago
AndréCAndréC
9,37611447
9,37611447
On my computer the lineforeach x[evaluate=x as y using int(x-1)]☺ in {2, 3, 4, 5, 6, 7}{looks like it has an smiley face in it...
– Abraham
4 hours ago
ok, fixed now !
– AndréC
4 hours ago
This works, seems thatpgfmathsetmacrowas the problem, as @marmot explained. Thank you!
– Abraham
4 hours ago
I have given two possibilities to correct this problem.
– AndréC
4 hours ago
This was the first answer, and now that an explanation was added, I am marking this as the accepted answer. The other answers were helpful as well!
– Abraham
36 mins ago
add a comment |
On my computer the lineforeach x[evaluate=x as y using int(x-1)]☺ in {2, 3, 4, 5, 6, 7}{looks like it has an smiley face in it...
– Abraham
4 hours ago
ok, fixed now !
– AndréC
4 hours ago
This works, seems thatpgfmathsetmacrowas the problem, as @marmot explained. Thank you!
– Abraham
4 hours ago
I have given two possibilities to correct this problem.
– AndréC
4 hours ago
This was the first answer, and now that an explanation was added, I am marking this as the accepted answer. The other answers were helpful as well!
– Abraham
36 mins ago
On my computer the line
foreach x[evaluate=x as y using int(x-1)]☺ in {2, 3, 4, 5, 6, 7}{ looks like it has an smiley face in it...– Abraham
4 hours ago
On my computer the line
foreach x[evaluate=x as y using int(x-1)]☺ in {2, 3, 4, 5, 6, 7}{ looks like it has an smiley face in it...– Abraham
4 hours ago
ok, fixed now !
– AndréC
4 hours ago
ok, fixed now !
– AndréC
4 hours ago
This works, seems that
pgfmathsetmacro was the problem, as @marmot explained. Thank you!– Abraham
4 hours ago
This works, seems that
pgfmathsetmacro was the problem, as @marmot explained. Thank you!– Abraham
4 hours ago
I have given two possibilities to correct this problem.
– AndréC
4 hours ago
I have given two possibilities to correct this problem.
– AndréC
4 hours ago
This was the first answer, and now that an explanation was added, I am marking this as the accepted answer. The other answers were helpful as well!
– Abraham
36 mins ago
This was the first answer, and now that an explanation was added, I am marking this as the accepted answer. The other answers were helpful as well!
– Abraham
36 mins ago
add a comment |
tikzstyle is deprecated and the issue is that pgfmathsetmacro does not yield integers, but something like 2.0, where .0 gets interpreted as node anchor.
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[auto, scale=0.9]
tikzset{vertex/.style={draw, circle, inner sep=0.55mm}}
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x [remember =x as lastx (initially 1)] in {2, 3, 4, 5, 6, 7}{
draw (vlastx) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}
end{document}

add a comment |
tikzstyle is deprecated and the issue is that pgfmathsetmacro does not yield integers, but something like 2.0, where .0 gets interpreted as node anchor.
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[auto, scale=0.9]
tikzset{vertex/.style={draw, circle, inner sep=0.55mm}}
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x [remember =x as lastx (initially 1)] in {2, 3, 4, 5, 6, 7}{
draw (vlastx) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}
end{document}

add a comment |
tikzstyle is deprecated and the issue is that pgfmathsetmacro does not yield integers, but something like 2.0, where .0 gets interpreted as node anchor.
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[auto, scale=0.9]
tikzset{vertex/.style={draw, circle, inner sep=0.55mm}}
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x [remember =x as lastx (initially 1)] in {2, 3, 4, 5, 6, 7}{
draw (vlastx) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}
end{document}

tikzstyle is deprecated and the issue is that pgfmathsetmacro does not yield integers, but something like 2.0, where .0 gets interpreted as node anchor.
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[auto, scale=0.9]
tikzset{vertex/.style={draw, circle, inner sep=0.55mm}}
node (v1) at (0,0) [vertex] {};
node (v2) at (1,0) [vertex] {};
node (v3) at (1.5,-1) [vertex] {};
node (v4) at (1,-2) [vertex] {};
node (v5) at (0,-2) [vertex] {};
node (v6) at (-.5,-1) [vertex] {};
node (v7) at (.5,-1) [vertex, fill=blue] {};
foreach x [remember =x as lastx (initially 1)] in {2, 3, 4, 5, 6, 7}{
draw (vlastx) to (vx);
}
draw (v6) to (v1);
draw (v5) to (v7);
draw (v4) to (v7);
draw (v3) to (v7);
end{tikzpicture}
end{document}

answered 4 hours ago
marmotmarmot
104k4123234
104k4123234
add a comment |
add a comment |
To get it more wheel like you can use polar coordinates, like (1,45) to draw a node at distance 1 and 45 degrees from origin. Here is an alternative version with a variable number of nodes. Change the number in numNodes{6} to change the number of nodes n the circle.
documentclass[border=5mm]{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[
auto,
scale=0.9,
vert/.style={draw, circle, inner sep=0.55mm,fill=white}
]
newcommandnumNodes{6}
node[vert,fill=blue] (vC) at (0,0){};
draw (0:1) node[vert](v0) {}
foreach n [evaluate = n as deg using {n*360/numNodes}] in {1,2,...,numNodes}{
-- (deg:1) node[vert](vn) {}
};
foreach n in {0,3,4,5}{
draw (vC) -- (vn);
}
end{tikzpicture}
end {document}

you have a typo(1,45)is not a polar coordinate
– AndréC
3 hours ago
add a comment |
To get it more wheel like you can use polar coordinates, like (1,45) to draw a node at distance 1 and 45 degrees from origin. Here is an alternative version with a variable number of nodes. Change the number in numNodes{6} to change the number of nodes n the circle.
documentclass[border=5mm]{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[
auto,
scale=0.9,
vert/.style={draw, circle, inner sep=0.55mm,fill=white}
]
newcommandnumNodes{6}
node[vert,fill=blue] (vC) at (0,0){};
draw (0:1) node[vert](v0) {}
foreach n [evaluate = n as deg using {n*360/numNodes}] in {1,2,...,numNodes}{
-- (deg:1) node[vert](vn) {}
};
foreach n in {0,3,4,5}{
draw (vC) -- (vn);
}
end{tikzpicture}
end {document}

you have a typo(1,45)is not a polar coordinate
– AndréC
3 hours ago
add a comment |
To get it more wheel like you can use polar coordinates, like (1,45) to draw a node at distance 1 and 45 degrees from origin. Here is an alternative version with a variable number of nodes. Change the number in numNodes{6} to change the number of nodes n the circle.
documentclass[border=5mm]{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[
auto,
scale=0.9,
vert/.style={draw, circle, inner sep=0.55mm,fill=white}
]
newcommandnumNodes{6}
node[vert,fill=blue] (vC) at (0,0){};
draw (0:1) node[vert](v0) {}
foreach n [evaluate = n as deg using {n*360/numNodes}] in {1,2,...,numNodes}{
-- (deg:1) node[vert](vn) {}
};
foreach n in {0,3,4,5}{
draw (vC) -- (vn);
}
end{tikzpicture}
end {document}

To get it more wheel like you can use polar coordinates, like (1,45) to draw a node at distance 1 and 45 degrees from origin. Here is an alternative version with a variable number of nodes. Change the number in numNodes{6} to change the number of nodes n the circle.
documentclass[border=5mm]{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[
auto,
scale=0.9,
vert/.style={draw, circle, inner sep=0.55mm,fill=white}
]
newcommandnumNodes{6}
node[vert,fill=blue] (vC) at (0,0){};
draw (0:1) node[vert](v0) {}
foreach n [evaluate = n as deg using {n*360/numNodes}] in {1,2,...,numNodes}{
-- (deg:1) node[vert](vn) {}
};
foreach n in {0,3,4,5}{
draw (vC) -- (vn);
}
end{tikzpicture}
end {document}

answered 3 hours ago
StefanHStefanH
10.7k1820
10.7k1820
you have a typo(1,45)is not a polar coordinate
– AndréC
3 hours ago
add a comment |
you have a typo(1,45)is not a polar coordinate
– AndréC
3 hours ago
you have a typo
(1,45) is not a polar coordinate– AndréC
3 hours ago
you have a typo
(1,45) is not a polar coordinate– AndréC
3 hours ago
add a comment |
maybe you will like:
documentclass[tikz,border=5mm]{standalone}
usetikzlibrary{shapes.geometric}
begin{document}
begin{tikzpicture}[
vertex/.style = {circle, draw, fill=#1, inner sep=0.5mm}
]
%
node (s) [regular polygon,regular polygon sides=6,
draw, minimum size=20mm, above] at (0.5,-2) {};
draw (s.corner 3) -- (s.corner 6);
node (c) [vertex=blue] at (s.center) {};
%
foreach i in {1,...,6}{node (si) [vertex=white] at (s.corner i) {}; }
draw (c) -- (s4)
(c) -- (s5);
end{tikzpicture}
end{document}

add a comment |
maybe you will like:
documentclass[tikz,border=5mm]{standalone}
usetikzlibrary{shapes.geometric}
begin{document}
begin{tikzpicture}[
vertex/.style = {circle, draw, fill=#1, inner sep=0.5mm}
]
%
node (s) [regular polygon,regular polygon sides=6,
draw, minimum size=20mm, above] at (0.5,-2) {};
draw (s.corner 3) -- (s.corner 6);
node (c) [vertex=blue] at (s.center) {};
%
foreach i in {1,...,6}{node (si) [vertex=white] at (s.corner i) {}; }
draw (c) -- (s4)
(c) -- (s5);
end{tikzpicture}
end{document}

add a comment |
maybe you will like:
documentclass[tikz,border=5mm]{standalone}
usetikzlibrary{shapes.geometric}
begin{document}
begin{tikzpicture}[
vertex/.style = {circle, draw, fill=#1, inner sep=0.5mm}
]
%
node (s) [regular polygon,regular polygon sides=6,
draw, minimum size=20mm, above] at (0.5,-2) {};
draw (s.corner 3) -- (s.corner 6);
node (c) [vertex=blue] at (s.center) {};
%
foreach i in {1,...,6}{node (si) [vertex=white] at (s.corner i) {}; }
draw (c) -- (s4)
(c) -- (s5);
end{tikzpicture}
end{document}

maybe you will like:
documentclass[tikz,border=5mm]{standalone}
usetikzlibrary{shapes.geometric}
begin{document}
begin{tikzpicture}[
vertex/.style = {circle, draw, fill=#1, inner sep=0.5mm}
]
%
node (s) [regular polygon,regular polygon sides=6,
draw, minimum size=20mm, above] at (0.5,-2) {};
draw (s.corner 3) -- (s.corner 6);
node (c) [vertex=blue] at (s.center) {};
%
foreach i in {1,...,6}{node (si) [vertex=white] at (s.corner i) {}; }
draw (c) -- (s4)
(c) -- (s5);
end{tikzpicture}
end{document}

answered 3 hours ago
ZarkoZarko
125k867164
125k867164
add a comment |
add a comment |
Abraham is a new contributor. Be nice, and check out our Code of Conduct.
Abraham is a new contributor. Be nice, and check out our Code of Conduct.
Abraham is a new contributor. Be nice, and check out our Code of Conduct.
Abraham 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.
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%2f476800%2ftikz-graph-edges-not-drawn-nicely%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
The issue is that
pgfmathsetmacrodoes not yield integers, but something like2.0, where.0gets interpreted as node anchor.– marmot
4 hours ago