Even-length cycle laid out as a star
For demonstration purposes, I want to obtain a graph of C10 shaped as a star. I have been working on this for much longer than I should have. I currently have this:
begin{figure}
centering
begin{tikzpicture}[nodes={circle, draw}]
foreach i in {1,...,10}
{
pgfmathisodd{i};
node (Ni) at (360/10*i:pgfmathresult?18mm:9mm) {i};
}
foreach i in {1,...,10}
{
pgfmathmod{i}{10}
pgfmathadd{pgfmathresult}{1};
path (Ni) edge (Npgfmathresult);
}
end{tikzpicture}
end{figure}
Which outputs the following abomination:

I don't know if the same ugliness would happen had I typed out the nodes myself.
tikz-pgf tikz-node tikz-path
add a comment |
For demonstration purposes, I want to obtain a graph of C10 shaped as a star. I have been working on this for much longer than I should have. I currently have this:
begin{figure}
centering
begin{tikzpicture}[nodes={circle, draw}]
foreach i in {1,...,10}
{
pgfmathisodd{i};
node (Ni) at (360/10*i:pgfmathresult?18mm:9mm) {i};
}
foreach i in {1,...,10}
{
pgfmathmod{i}{10}
pgfmathadd{pgfmathresult}{1};
path (Ni) edge (Npgfmathresult);
}
end{tikzpicture}
end{figure}
Which outputs the following abomination:

I don't know if the same ugliness would happen had I typed out the nodes myself.
tikz-pgf tikz-node tikz-path
The "abomination" is simply all numbers aligned the same way. Try instead of defining the points recursively like you did and then in a second step add the lines and then the numbers. This should make it better :)
– Superuser27
Mar 7 at 14:36
What I mean is: if you just look at how the numbers are positioned, they look fine. It's just the lines starting from weird places.
– Superuser27
Mar 7 at 14:37
I have given up and written every node one by one. It works! The question is even more curious to me now.
– ThoAppelsin
Mar 7 at 15:00
add a comment |
For demonstration purposes, I want to obtain a graph of C10 shaped as a star. I have been working on this for much longer than I should have. I currently have this:
begin{figure}
centering
begin{tikzpicture}[nodes={circle, draw}]
foreach i in {1,...,10}
{
pgfmathisodd{i};
node (Ni) at (360/10*i:pgfmathresult?18mm:9mm) {i};
}
foreach i in {1,...,10}
{
pgfmathmod{i}{10}
pgfmathadd{pgfmathresult}{1};
path (Ni) edge (Npgfmathresult);
}
end{tikzpicture}
end{figure}
Which outputs the following abomination:

I don't know if the same ugliness would happen had I typed out the nodes myself.
tikz-pgf tikz-node tikz-path
For demonstration purposes, I want to obtain a graph of C10 shaped as a star. I have been working on this for much longer than I should have. I currently have this:
begin{figure}
centering
begin{tikzpicture}[nodes={circle, draw}]
foreach i in {1,...,10}
{
pgfmathisodd{i};
node (Ni) at (360/10*i:pgfmathresult?18mm:9mm) {i};
}
foreach i in {1,...,10}
{
pgfmathmod{i}{10}
pgfmathadd{pgfmathresult}{1};
path (Ni) edge (Npgfmathresult);
}
end{tikzpicture}
end{figure}
Which outputs the following abomination:

I don't know if the same ugliness would happen had I typed out the nodes myself.
tikz-pgf tikz-node tikz-path
tikz-pgf tikz-node tikz-path
asked Mar 7 at 14:34
ThoAppelsinThoAppelsin
330111
330111
The "abomination" is simply all numbers aligned the same way. Try instead of defining the points recursively like you did and then in a second step add the lines and then the numbers. This should make it better :)
– Superuser27
Mar 7 at 14:36
What I mean is: if you just look at how the numbers are positioned, they look fine. It's just the lines starting from weird places.
– Superuser27
Mar 7 at 14:37
I have given up and written every node one by one. It works! The question is even more curious to me now.
– ThoAppelsin
Mar 7 at 15:00
add a comment |
The "abomination" is simply all numbers aligned the same way. Try instead of defining the points recursively like you did and then in a second step add the lines and then the numbers. This should make it better :)
– Superuser27
Mar 7 at 14:36
What I mean is: if you just look at how the numbers are positioned, they look fine. It's just the lines starting from weird places.
– Superuser27
Mar 7 at 14:37
I have given up and written every node one by one. It works! The question is even more curious to me now.
– ThoAppelsin
Mar 7 at 15:00
The "abomination" is simply all numbers aligned the same way. Try instead of defining the points recursively like you did and then in a second step add the lines and then the numbers. This should make it better :)
– Superuser27
Mar 7 at 14:36
The "abomination" is simply all numbers aligned the same way. Try instead of defining the points recursively like you did and then in a second step add the lines and then the numbers. This should make it better :)
– Superuser27
Mar 7 at 14:36
What I mean is: if you just look at how the numbers are positioned, they look fine. It's just the lines starting from weird places.
– Superuser27
Mar 7 at 14:37
What I mean is: if you just look at how the numbers are positioned, they look fine. It's just the lines starting from weird places.
– Superuser27
Mar 7 at 14:37
I have given up and written every node one by one. It works! The question is even more curious to me now.
– ThoAppelsin
Mar 7 at 15:00
I have given up and written every node one by one. It works! The question is even more curious to me now.
– ThoAppelsin
Mar 7 at 15:00
add a comment |
2 Answers
2
active
oldest
votes
After the manipulations, the result won't be an integer any more. Rather, you'll get numbers like 1.0, where .0 is interpreted as an anchor. Therefore I suggest
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[nodes={circle, draw}]
foreach i in {1,...,10}
{
pgfmathisodd{i};
node (Ni) at (360/10*i:pgfmathresult?18mm:9mm) {i};
}
foreach i in {1,...,10}
{
pgfmathtruncatemacro{j}{mod(i,10)+1}
path (Ni) edge (Nj);
}
end{tikzpicture}
end{document}

3
I am aware of the fact that one can shorten the code. This answer is to explain what happens and to provide a way that works which is very close to the code of the question.
– marmot
Mar 7 at 16:12
Probably a good idea to fix the circle size so the 10 node isn't bigger than the others.
– Sandy G
Mar 7 at 16:29
Great answer, thank you for being to the point. And to @SandyG, I already have fixed the size inconsistency via putting all nodes in boxes with zero width, and giving any size I like to the nodes.
– ThoAppelsin
Mar 7 at 19:10
add a comment |
PGF's foreach has quite powerfull tools that you can use here:
begin{tikzpicture}[nodes={circle, draw}]
foreach[evaluate=i as j using isodd(i)] i in {1,...,10}
{
node (Ni) at (360/10*i:j?18mm:9mm) {i};
}
foreach[remember=i as j (initially 10)] i in {1,...,10}
{
draw (Ni) -- (Nj);
}
end{tikzpicture}
The optional [evaluate=i as j using isodd(i)] in the first loop computes isodd(i) and stores the result in macro j.
The optional [remember=i as j (initially 10)] in the second loop stores i's content in macro j at the end of the iteration, allowing for this content to be available for the next iteration.
Thank you for your extended recommendations, but I think marmot's answer is more relevant to the issue/question, since it also explains the cause of the erroneous outcome in the question.
– ThoAppelsin
Mar 7 at 19:11
@ThoAppelsin I agree, this answer is also aimed at those who will find your question later and offer them a simple and robust solution.
– Christoph Frings
Mar 7 at 19:31
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%2f478207%2feven-length-cycle-laid-out-as-a-star%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
After the manipulations, the result won't be an integer any more. Rather, you'll get numbers like 1.0, where .0 is interpreted as an anchor. Therefore I suggest
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[nodes={circle, draw}]
foreach i in {1,...,10}
{
pgfmathisodd{i};
node (Ni) at (360/10*i:pgfmathresult?18mm:9mm) {i};
}
foreach i in {1,...,10}
{
pgfmathtruncatemacro{j}{mod(i,10)+1}
path (Ni) edge (Nj);
}
end{tikzpicture}
end{document}

3
I am aware of the fact that one can shorten the code. This answer is to explain what happens and to provide a way that works which is very close to the code of the question.
– marmot
Mar 7 at 16:12
Probably a good idea to fix the circle size so the 10 node isn't bigger than the others.
– Sandy G
Mar 7 at 16:29
Great answer, thank you for being to the point. And to @SandyG, I already have fixed the size inconsistency via putting all nodes in boxes with zero width, and giving any size I like to the nodes.
– ThoAppelsin
Mar 7 at 19:10
add a comment |
After the manipulations, the result won't be an integer any more. Rather, you'll get numbers like 1.0, where .0 is interpreted as an anchor. Therefore I suggest
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[nodes={circle, draw}]
foreach i in {1,...,10}
{
pgfmathisodd{i};
node (Ni) at (360/10*i:pgfmathresult?18mm:9mm) {i};
}
foreach i in {1,...,10}
{
pgfmathtruncatemacro{j}{mod(i,10)+1}
path (Ni) edge (Nj);
}
end{tikzpicture}
end{document}

3
I am aware of the fact that one can shorten the code. This answer is to explain what happens and to provide a way that works which is very close to the code of the question.
– marmot
Mar 7 at 16:12
Probably a good idea to fix the circle size so the 10 node isn't bigger than the others.
– Sandy G
Mar 7 at 16:29
Great answer, thank you for being to the point. And to @SandyG, I already have fixed the size inconsistency via putting all nodes in boxes with zero width, and giving any size I like to the nodes.
– ThoAppelsin
Mar 7 at 19:10
add a comment |
After the manipulations, the result won't be an integer any more. Rather, you'll get numbers like 1.0, where .0 is interpreted as an anchor. Therefore I suggest
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[nodes={circle, draw}]
foreach i in {1,...,10}
{
pgfmathisodd{i};
node (Ni) at (360/10*i:pgfmathresult?18mm:9mm) {i};
}
foreach i in {1,...,10}
{
pgfmathtruncatemacro{j}{mod(i,10)+1}
path (Ni) edge (Nj);
}
end{tikzpicture}
end{document}

After the manipulations, the result won't be an integer any more. Rather, you'll get numbers like 1.0, where .0 is interpreted as an anchor. Therefore I suggest
documentclass[tikz,border=3.14mm]{standalone}
begin{document}
begin{tikzpicture}[nodes={circle, draw}]
foreach i in {1,...,10}
{
pgfmathisodd{i};
node (Ni) at (360/10*i:pgfmathresult?18mm:9mm) {i};
}
foreach i in {1,...,10}
{
pgfmathtruncatemacro{j}{mod(i,10)+1}
path (Ni) edge (Nj);
}
end{tikzpicture}
end{document}

answered Mar 7 at 16:11
marmotmarmot
108k5133251
108k5133251
3
I am aware of the fact that one can shorten the code. This answer is to explain what happens and to provide a way that works which is very close to the code of the question.
– marmot
Mar 7 at 16:12
Probably a good idea to fix the circle size so the 10 node isn't bigger than the others.
– Sandy G
Mar 7 at 16:29
Great answer, thank you for being to the point. And to @SandyG, I already have fixed the size inconsistency via putting all nodes in boxes with zero width, and giving any size I like to the nodes.
– ThoAppelsin
Mar 7 at 19:10
add a comment |
3
I am aware of the fact that one can shorten the code. This answer is to explain what happens and to provide a way that works which is very close to the code of the question.
– marmot
Mar 7 at 16:12
Probably a good idea to fix the circle size so the 10 node isn't bigger than the others.
– Sandy G
Mar 7 at 16:29
Great answer, thank you for being to the point. And to @SandyG, I already have fixed the size inconsistency via putting all nodes in boxes with zero width, and giving any size I like to the nodes.
– ThoAppelsin
Mar 7 at 19:10
3
3
I am aware of the fact that one can shorten the code. This answer is to explain what happens and to provide a way that works which is very close to the code of the question.
– marmot
Mar 7 at 16:12
I am aware of the fact that one can shorten the code. This answer is to explain what happens and to provide a way that works which is very close to the code of the question.
– marmot
Mar 7 at 16:12
Probably a good idea to fix the circle size so the 10 node isn't bigger than the others.
– Sandy G
Mar 7 at 16:29
Probably a good idea to fix the circle size so the 10 node isn't bigger than the others.
– Sandy G
Mar 7 at 16:29
Great answer, thank you for being to the point. And to @SandyG, I already have fixed the size inconsistency via putting all nodes in boxes with zero width, and giving any size I like to the nodes.
– ThoAppelsin
Mar 7 at 19:10
Great answer, thank you for being to the point. And to @SandyG, I already have fixed the size inconsistency via putting all nodes in boxes with zero width, and giving any size I like to the nodes.
– ThoAppelsin
Mar 7 at 19:10
add a comment |
PGF's foreach has quite powerfull tools that you can use here:
begin{tikzpicture}[nodes={circle, draw}]
foreach[evaluate=i as j using isodd(i)] i in {1,...,10}
{
node (Ni) at (360/10*i:j?18mm:9mm) {i};
}
foreach[remember=i as j (initially 10)] i in {1,...,10}
{
draw (Ni) -- (Nj);
}
end{tikzpicture}
The optional [evaluate=i as j using isodd(i)] in the first loop computes isodd(i) and stores the result in macro j.
The optional [remember=i as j (initially 10)] in the second loop stores i's content in macro j at the end of the iteration, allowing for this content to be available for the next iteration.
Thank you for your extended recommendations, but I think marmot's answer is more relevant to the issue/question, since it also explains the cause of the erroneous outcome in the question.
– ThoAppelsin
Mar 7 at 19:11
@ThoAppelsin I agree, this answer is also aimed at those who will find your question later and offer them a simple and robust solution.
– Christoph Frings
Mar 7 at 19:31
add a comment |
PGF's foreach has quite powerfull tools that you can use here:
begin{tikzpicture}[nodes={circle, draw}]
foreach[evaluate=i as j using isodd(i)] i in {1,...,10}
{
node (Ni) at (360/10*i:j?18mm:9mm) {i};
}
foreach[remember=i as j (initially 10)] i in {1,...,10}
{
draw (Ni) -- (Nj);
}
end{tikzpicture}
The optional [evaluate=i as j using isodd(i)] in the first loop computes isodd(i) and stores the result in macro j.
The optional [remember=i as j (initially 10)] in the second loop stores i's content in macro j at the end of the iteration, allowing for this content to be available for the next iteration.
Thank you for your extended recommendations, but I think marmot's answer is more relevant to the issue/question, since it also explains the cause of the erroneous outcome in the question.
– ThoAppelsin
Mar 7 at 19:11
@ThoAppelsin I agree, this answer is also aimed at those who will find your question later and offer them a simple and robust solution.
– Christoph Frings
Mar 7 at 19:31
add a comment |
PGF's foreach has quite powerfull tools that you can use here:
begin{tikzpicture}[nodes={circle, draw}]
foreach[evaluate=i as j using isodd(i)] i in {1,...,10}
{
node (Ni) at (360/10*i:j?18mm:9mm) {i};
}
foreach[remember=i as j (initially 10)] i in {1,...,10}
{
draw (Ni) -- (Nj);
}
end{tikzpicture}
The optional [evaluate=i as j using isodd(i)] in the first loop computes isodd(i) and stores the result in macro j.
The optional [remember=i as j (initially 10)] in the second loop stores i's content in macro j at the end of the iteration, allowing for this content to be available for the next iteration.
PGF's foreach has quite powerfull tools that you can use here:
begin{tikzpicture}[nodes={circle, draw}]
foreach[evaluate=i as j using isodd(i)] i in {1,...,10}
{
node (Ni) at (360/10*i:j?18mm:9mm) {i};
}
foreach[remember=i as j (initially 10)] i in {1,...,10}
{
draw (Ni) -- (Nj);
}
end{tikzpicture}
The optional [evaluate=i as j using isodd(i)] in the first loop computes isodd(i) and stores the result in macro j.
The optional [remember=i as j (initially 10)] in the second loop stores i's content in macro j at the end of the iteration, allowing for this content to be available for the next iteration.
answered Mar 7 at 16:37
Christoph FringsChristoph Frings
923211
923211
Thank you for your extended recommendations, but I think marmot's answer is more relevant to the issue/question, since it also explains the cause of the erroneous outcome in the question.
– ThoAppelsin
Mar 7 at 19:11
@ThoAppelsin I agree, this answer is also aimed at those who will find your question later and offer them a simple and robust solution.
– Christoph Frings
Mar 7 at 19:31
add a comment |
Thank you for your extended recommendations, but I think marmot's answer is more relevant to the issue/question, since it also explains the cause of the erroneous outcome in the question.
– ThoAppelsin
Mar 7 at 19:11
@ThoAppelsin I agree, this answer is also aimed at those who will find your question later and offer them a simple and robust solution.
– Christoph Frings
Mar 7 at 19:31
Thank you for your extended recommendations, but I think marmot's answer is more relevant to the issue/question, since it also explains the cause of the erroneous outcome in the question.
– ThoAppelsin
Mar 7 at 19:11
Thank you for your extended recommendations, but I think marmot's answer is more relevant to the issue/question, since it also explains the cause of the erroneous outcome in the question.
– ThoAppelsin
Mar 7 at 19:11
@ThoAppelsin I agree, this answer is also aimed at those who will find your question later and offer them a simple and robust solution.
– Christoph Frings
Mar 7 at 19:31
@ThoAppelsin I agree, this answer is also aimed at those who will find your question later and offer them a simple and robust solution.
– Christoph Frings
Mar 7 at 19:31
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%2f478207%2feven-length-cycle-laid-out-as-a-star%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 "abomination" is simply all numbers aligned the same way. Try instead of defining the points recursively like you did and then in a second step add the lines and then the numbers. This should make it better :)
– Superuser27
Mar 7 at 14:36
What I mean is: if you just look at how the numbers are positioned, they look fine. It's just the lines starting from weird places.
– Superuser27
Mar 7 at 14:37
I have given up and written every node one by one. It works! The question is even more curious to me now.
– ThoAppelsin
Mar 7 at 15:00