TeX - LaTeX Asked by stackexchange on January 31, 2021
I would like to align all of these graphs next to each other so they are side by side. How can this be done? I also can’t figure out why the they are crooked.
documentclass{article}
usepackage{tikz}
begin{document}
usetikzlibrary{positioning}
tikzset{main node/.style={circle,fill=black,draw,minimum size=.1cm,inner sep=0pt},}
begin{center}
begin{tikzpicture}
node[main node] (1) {};
node[main node] (2) [below = .5cm of 1] {};
node[main node] (3) [below right = .5cm and .5cm of 1] {};
node[main node] (4) [right = .5cm of 1] {};
end{tikzpicture}
begin{tikzpicture}
node[main node] (1) {};
node[main node] (2) [below = .5cm of 1] {};
node[main node] (3) [below right = .5cm and .5cm of 1] {};
node[main node] (4) [right = .5cm of 1] {};
path[draw,thick]
(1) edge node {} (2);
end{tikzpicture}
begin{tikzpicture}
node[main node] (1) {};
node[main node] (2) [below = .5cm of 1] {};
node[main node] (3) [below right = .5cm and .5cm of 1] {};
node[main node] (4) [right = .5cm of 1] {};
path[draw,thick]
(1) edge node {} (2)
(1) edge node {} (4)
(1) edge node {} (3);
end{tikzpicture}
begin{tikzpicture}
node[main node] (1) {};
node[main node] (2) [below = .5cm of 1] {};
node[main node] (3) [below right = .5cm and .5cm of 1] {};
node[main node] (4) [right = .5cm of 1] {};
path[draw,thick]
(3) edge node {} (4)
(2) edge node {} (3);
end{tikzpicture}
begin{tikzpicture}
node[main node] (1) {};
node[main node] (2) [below = .5cm of 1] {};
node[main node] (3) [below right = .5cm and .5cm of 1] {};
node[main node] (4) [right = .5cm of 1] {};
path[draw,thick]
(1) edge node {} (2)
(2) edge node {} (3)
(3) edge node {} (4)
(4) edge node {} (1);
end{tikzpicture}
begin{tikzpicture}
node[main node] (1) {};
node[main node] (2) [below = .5cm of 1] {};
node[main node] (3) [below right = .5cm and .5cm of 1] {};
node[main node] (4) [right = .5cm of 1] {};
path[draw,thick]
(1) edge node {} (2)
(2) edge node {} (3)
(3) edge node {} (4);
end{tikzpicture}
end{center}
end{document}
As @SalimBou said in the comment, yuo shuld remove the empty lines between the pictures. An empty line means new paragraph.
About the crookedness or skewness of the picture, it comes from the way yuo position the nodes. You have first a node 1, and draw the second (2) beolw it and the fourth (4) to the right. That means yuo have 0.5 cm from border to border of the nodes. The third (3) is drawn (0.5cm,-0.5cm), meaning 0.5*sqrt(2)=0.7071
in direction -45 degrees. Since it draws from border to border of the nodes that is not the same as before. See
begin{tikzpicture}
node[main node] (1) {};
node[main node] (2) [below = .5cm of 1] {};
node[main node] (3) [below right = .5cm and .5cm of 1] {};
node[main node] (4) [right = .5cm of 1] {};
draw[|-|,red] (1.0) -- +(0.5cm,0cm);
draw[|-|,blue] (1.-45) -- +(0.5cm,-0.5cm);
draw[->,green,dashed] (1.-45) -- +(-45:0.7071cm);
end{tikzpicture}
What I would do is to draw the two left nodes and then the two right positioned from them,
begin{tikzpicture}
node[main node] (1) {};
node[main node] (2) [below = .5cm of 1] {};
node[main node] (3) [right =.5cm of 2] {};
node[main node] (4) [right = .5cm of 1] {};
end{tikzpicture}
Answered by StefanH on January 31, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP