并排对齐多个图表

并排对齐多个图表

我想将这些图表全部对齐,使它们并排。该怎么做?我也搞不清楚为什么它们会歪斜。

\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}

在此处输入图片描述

答案1

正如@SalimBou 在评论中所说,你应该删除图片之间的空行。空行表示新段落。

关于图片的弯曲或倾斜,这来自于你放置节点的方式。首先有一个节点 1,然后在它下面画第二个 (2),在右边画第四个 (4)。这意味着节点的边界到边界有 0.5 厘米。第三个 (3) 画的是 (0.5cm,-0.5cm),也就是0.5*sqrt(2)=0.7071在 -45 度的方向上。因为它是从节点的边界到边界画的,这与以前不一样。参见

\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}
 

在此处输入图片描述

我要做的是画出两个左边的节点,然后画出两个右边的节点,

\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}
 

在此处输入图片描述

相关内容