并排移动 tikzpicture 的简单方法是什么?

并排移动 tikzpicture 的简单方法是什么?

我在两个不同的 tikzpicture 中并排放置了两个图形。但我想将左侧的图形稍微向上移动一点。我知道一种复杂的方法,但我确信这是一种简单的方法。选项 yshift=-2cm 似乎不起作用。以下是代码示例:

\begin{center} 
        \begin{tikzpicture}[sommet/.style={circle, draw},yshift=-2cm]
        \centering
            % Sommets
            \node[sommet] (s1) at (1.5,3) {$s_1$};
            \node[sommet] (s2) at (3,0) {$s_2$};
            \node[sommet] (s3) at (0,0) {$s_3$};        
            % Arêtes
            \path (s1) edge node[xshift=-0.23cm] {$a_1$}(s2);
            \path (s2) edge node[yshift=0.23cm] {$a_2$} (s3);
            \path (s3) edge node[xshift=+0.29cm] {$a_3$}(s1);
        \end{tikzpicture}
        \qquad  
        \begin{tikzpicture}[sommet/.style={circle, draw}]
            % Sommets
            \node[sommet] (s1) at (1.5,3) {$s_1$};
            \node[sommet] (s2) at (3,0) {$s_2$};
            \node[sommet] (s3) at (0,0) {$s_3$};
            \node[sommet] (a1) at (3,2) {$a^{\prime}_1$};
            \node[sommet] (a2) at (1.5,-1) {$a^{\prime}_2$};
            \node[sommet] (a3) at (0,2) {$a^{\prime}_3$};       
            % Arêtes
            \path (a1) edge (s1) edge (s2);
            \path (a2) edge (s2) edge (s3);
            \path (a3) edge (s3) edge (s1);
            \path (s1) edge node[xshift=-0.23cm] {$a_1$}(s2);
            \path (s2) edge node[yshift=0.23cm] {$a_2$} (s3);
            \path (s3) edge node[xshift=+0.29cm] {$a_3$}(s1);
        \end{tikzpicture} 
    \end{center}

答案1

yshifttikzpicture什么都不做,因为它只会在 TikZ 的坐标系中为坐标添加一个值,这与在页面上的绘制方式无关。

如果希望它们垂直居中,请将 添加baseline=(current bounding box.center)到两者中tikzpictures。如果希望两个三角形垂直对齐,请将baseline=(s3.south)选项添加到第二个 中tikzpicture

(我也改为node[xshift=0.23cm]类似node[right]的,这似乎是定位边缘标签的更简单的方法。)

在此处输入图片描述

\documentclass[]{article}
\usepackage{tikz}
\begin{document}
\begin{center} 
        \begin{tikzpicture}[sommet/.style={circle, draw},baseline=(current bounding box.center)]
        \centering
            % Sommets
            \node[sommet] (s1) at (1.5,3) {$s_1$};
            \node[sommet] (s2) at (3,0) {$s_2$};
            \node[sommet] (s3) at (0,0) {$s_3$};        
            % Arêtes
            \path (s1) edge node[left] {$a_1$}(s2);
            \path (s2) edge node[above] {$a_2$} (s3);
            \path (s3) edge node[right] {$a_3$}(s1);
        \end{tikzpicture}
        \qquad  
        \begin{tikzpicture}[sommet/.style={circle, draw},baseline=(current bounding box.center)]
            % Sommets
            \node[sommet] (s1) at (1.5,3) {$s_1$};
            \node[sommet] (s2) at (3,0) {$s_2$};
            \node[sommet] (s3) at (0,0) {$s_3$};
            \node[sommet] (a1) at (3,2) {$a^{\prime}_1$};
            \node[sommet] (a2) at (1.5,-1) {$a^{\prime}_2$};
            \node[sommet] (a3) at (0,2) {$a^{\prime}_3$};       
            % Arêtes
            \path (a1) edge (s1) edge (s2);
            \path (a2) edge (s2) edge (s3);
            \path (a3) edge (s3) edge (s1);
            \path (s1) edge node[left] {$a_1$}(s2);
            \path (s2) edge node[above] {$a_2$} (s3);
            \path (s3) edge node[right] {$a_3$}(s1);
        \end{tikzpicture} 

        \begin{tikzpicture}[sommet/.style={circle, draw}]
        \centering
            % Sommets
            \node[sommet] (s1) at (1.5,3) {$s_1$};
            \node[sommet] (s2) at (3,0) {$s_2$};
            \node[sommet] (s3) at (0,0) {$s_3$};        
            % Arêtes
            \path (s1) edge node[left] {$a_1$}(s2);
            \path (s2) edge node[above] {$a_2$} (s3);
            \path (s3) edge node[right] {$a_3$}(s1);
        \end{tikzpicture}
        \qquad  
        \begin{tikzpicture}[sommet/.style={circle, draw},baseline=(s3.south)]
            % Sommets
            \node[sommet] (s1) at (1.5,3) {$s_1$};
            \node[sommet] (s2) at (3,0) {$s_2$};
            \node[sommet] (s3) at (0,0) {$s_3$};
            \node[sommet] (a1) at (3,2) {$a^{\prime}_1$};
            \node[sommet] (a2) at (1.5,-1) {$a^{\prime}_2$};
            \node[sommet] (a3) at (0,2) {$a^{\prime}_3$};       
            % Arêtes
            \path (a1) edge (s1) edge (s2);
            \path (a2) edge (s2) edge (s3);
            \path (a3) edge (s3) edge (s1);
            \path (s1) edge node[left] {$a_1$}(s2);
            \path (s2) edge node[above] {$a_2$} (s3);
            \path (s3) edge node[right] {$a_3$}(s1);
        \end{tikzpicture} 
    \end{center}
\end{document}

相关内容