3

I have two graph side by side in two different tikzpicture. But I'd like to move the left one up a bit. I know an elaborate way to do it but I am sure the is a simple way. The options yshift=-2cm doesnt seem to do it. Here is the code sample:

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

yshift does nothing because it only adds a value to the coordinates in TikZ's coordinate system, which has nothing to do with how the tikzpicture is drawn on the page.

If you want them vertically centered, add baseline=(current bounding box.center) to both tikzpictures. If you want the two triangles vertically aligned, add baseline=(s3.south) as an option to the second tikzpicture.

(I also changed node[xshift=0.23cm] to node[right] and similar, which seems like an easier way of positioning the edge labels.)

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.