0

I am drawing two graphs next to each other as follows:

\documentclass[standalone]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, shadows}
\begin{document}
\begin{frame}
    \begin{center}
    \begin{tikzpicture}[scale=0.6]
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (2.5,-1.5) {1};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (1,-3) {2};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (3) at (4,0) {3};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (4) at (5.5,-1.5) {4};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (5) at (5.5, 1.5) {5};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (6) at (7, 0) {6};
    \path (1) edge [->] node {} (3);
    \path (2) edge [->] node {} (1);
    \path (3) edge [->] node {} (5);
    \path (4) edge [->] node {} (3);
    \path (5) edge [loop above] node {} (5);
    \path (6) edge [->] node {} (5);
    \end{tikzpicture}
    \hspace{1cm}
    \vspace{-1cm}
    \begin{tikzpicture}[scale=0.6]
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (2,1) {1};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (0.5, -0.5) {2};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (3) at (3.8,2.5) {3};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (4) at (3.8, 0.5) {4};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (5) at (5.5, 1) {5};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (6) at (7, -0.5) {6};
    \path (1) edge [->] node {} (3);
    \path (2) edge [->] node {} (1);
    \path (3) edge [loop above] node {} (3);
    \path (4) edge [->] node {} (3);
    \path (5) edge [->] node {} (3);
    \path (6) edge [->] node {} (5);
    \end{tikzpicture}
\end{center}
\end{frame}
\end{document}

I can't work out how to get the root nodes aligned vertically. It seems that however I adjust the absolute locations the two graphs are always aligned to the bottom and as they have different heights this means the roots are not aligned vertically.

1
  • @daleif I am not sure where it came from and it isn't needed.
    – Simd
    Jul 29, 2020 at 12:43

3 Answers 3

4

I would argue that the easiest solution is to set the baseline to whatever node you want to align to using [baseline=(anchor)].

\documentclass[standalone]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, shadows}
\begin{document}
\begin{frame}
    \begin{center}
    \begin{tikzpicture}[scale=0.6, baseline=(5)]
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (2.5,-1.5) {1};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (1,-3) {2};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (3) at (4,0) {3};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (4) at (5.5,-1.5) {4};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (5) at (5.5, 1.5) {5};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (6) at (7, 0) {6};
    \path (1) edge [->] node {} (3);
    \path (2) edge [->] node {} (1);
    \path (3) edge [->] node {} (5);
    \path (4) edge [->] node {} (3);
    \path (5) edge [loop above] node {} (5);
    \path (6) edge [->] node {} (5);
    \end{tikzpicture}
    \hspace{1cm}
    \vspace{-1cm}
    \begin{tikzpicture}[scale=0.6, baseline=(3)]
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (2,1) {1};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (0.5, -0.5) {2};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (3) at (3.8,2.5) {3};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (4) at (3.8, 0.5) {4};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (5) at (5.5, 1) {5};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (6) at (7, -0.5) {6};
    \path (1) edge [->] node {} (3);
    \path (2) edge [->] node {} (1);
    \path (3) edge [loop above] node {} (3);
    \path (4) edge [->] node {} (3);
    \path (5) edge [->] node {} (3);
    \path (6) edge [->] node {} (5);
    \end{tikzpicture}
\end{center}
\end{frame}
\end{document}
1
  • This is a very nice solution, thank you.
    – Simd
    Jul 29, 2020 at 15:09
2

It is much easier to shift the second picture inside the same TikZ environment using a scope like \begin{scope} [shift = {(10cm,-1cm)}], then insert a single picture into beamer.

\documentclass[standalone]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, shadows}
\usepackage{array}
\begin{document}
\begin{frame}
    \begin{center}
    \begin{tikzpicture}[scale=0.6]
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (2.5,-1.5) {1};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (1,-3) {2};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (3) at (4,0) {3};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (4) at (5.5,-1.5) {4};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (5) at (5.5, 1.5) {5};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (6) at (7, 0) {6};
    \path (1) edge [->] node {} (3);
    \path (2) edge [->] node {} (1);
    \path (3) edge [->] node {} (5);
    \path (4) edge [->] node {} (3);
    \path (5) edge [loop above] node {} (5);
    \path (6) edge [->] node {} (5);
    %
    \begin{scope}[shift={(10cm,-1cm)}]
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (2,1) {1};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (0.5, -0.5) {2};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (3) at (3.8,2.5) {3};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (4) at (3.8, 0.5) {4};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (5) at (5.5, 1) {5};
    \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (6) at (7, -0.5) {6};
    \path (1) edge [->] node {} (3);
    \path (2) edge [->] node {} (1);
    \path (3) edge [loop above] node {} (3);
    \path (4) edge [->] node {} (3);
    \path (5) edge [->] node {} (3);
    \path (6) edge [->] node {} (5);
    \end{scope}
    \end{tikzpicture}
\end{center}
\end{frame}
\end{document}

enter image description here

2
  • I also like this answer better than mine. Also goes well with your second question, where one acan just add the vertical line between both scopes.
    – ttnick
    Jul 29, 2020 at 13:07
  • can we use the intersection tikzlibrary to align the second picture with the first since the second picture may not be symmetrical to the first
    – js bibra
    Jul 29, 2020 at 13:12
1

A quick solution would be to use a column for each tikzpicture and align them vertically to the top:

\documentclass[standalone]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, shadows}
\usepackage{default}
\begin{document}
\begin{frame}
    \begin{columns}[T]
        \begin{column}{.49\linewidth}
            \begin{tikzpicture}[scale=0.6]
                \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (2.5,-1.5) {1};
                \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (1,-3) {2};
                \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (3) at (4,0) {3};
                \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (4) at (5.5,-1.5) {4};
                \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (5) at (5.5, 1.5) {5};
                \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (6) at (7, 0) {6};
                \path (1) edge [->] node {} (3);
                \path (2) edge [->] node {} (1);
                \path (3) edge [->] node {} (5);
                \path (4) edge [->] node {} (3);
                \path (5) edge [loop above] node {} (5);
                \path (6) edge [->] node {} (5);
            \end{tikzpicture}
        \end{column}
        \begin{column}{.49\linewidth}
            \begin{tikzpicture}[scale=0.6]
                \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (2,1) {1};
                \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (0.5, -0.5) {2};
                \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (3) at (3.8,2.5) {3};
                \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (4) at (3.8, 0.5) {4};
                \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (5) at (5.5, 1) {5};
                \node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (6) at (7, -0.5) {6};
                \path (1) edge [->] node {} (3);
                \path (2) edge [->] node {} (1);
                \path (3) edge [loop above] node {} (3);
                \path (4) edge [->] node {} (3);
                \path (5) edge [->] node {} (3);
                \path (6) edge [->] node {} (5);
            \end{tikzpicture}
        \end{column}
    \end{columns}
\end{frame}
\end{document}

preview

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .