0

I have an issue regarding aligning of text: I'd like to have a G=(tikzpicture) section, like for the matrix in my example. I didn't find a helping answer, all I found was aligning stuff inside nodes.

If possible (and everything is possible if you know how I guess) I'd like to have it outside of the tikzpicture, at the same time I'm happy with every answer! Trying to solve it with new nodes just gave me errors sadly. I tried it with a new minipage, but then there is a pretty huge gap between the graph and the text.

Thanks in advance!

Edit: Thanks for all the good and quick responses, they all helped me to a good degree, especially to understand this stuff more!

the wrong alignment

That's a compilable code, focussing on the important part:

\documentclass{beamer}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows, automata}

\begin{document}
\begin{minipage}{.3\textwidth}
\resizebox*{\textwidth}{!}{
    $G=$
    \begin{tikzpicture}[-,>=stealth',shorten >=1pt,auto,node distance=3.5cm,scale = 1,transform shape]
        \node[state] (1)  {$1$};
        \node[state] (2) [right of=1] {$2$};
        \node[state] (3) [below of=2] {$3$};
        \node[state] (4) [left of=3] {$4$};

        \path   (1) edge              node {$$} (2)
                (2) edge              node {$$} (3)
                (3) edge              node {$$} (4)
                (4) edge              node {$$} (1);
    \end{tikzpicture}
}
\end{minipage}
\end{document}

The whole code is the following (but it's not compilable, as there are no usepackages):

\begin{frame}
\frametitle{Orthonormalbasis aus Eigenvektoren: Beispiel}
\centering
\begin{minipage}{.3\textwidth}
    \resizebox*{\textwidth}{!}{
        $G=$
        \begin{tikzpicture}[-,>=stealth',shorten >=1pt,auto,node distance=3.5cm,scale = 1,transform shape]
            \node[state] (1)  {$1$};
            \node[state] (2) [right of=1] {$2$};
            \node[state] (3) [below of=2] {$3$};
            \node[state] (4) [left of=3] {$4$};

            \path   (1) edge              node {$$} (2)
                    (2) edge              node {$$} (3)
                    (3) edge              node {$$} (4)
                    (4) edge              node {$$} (1);
        \end{tikzpicture}
    }
\end{minipage}
\pause
\begin{minipage}{.2\textwidth}
    \resizebox*{\textwidth}{!}{$\leadsto$}
\end{minipage}
\begin{minipage}{.3\textwidth}
    \resizebox*{\textwidth}{!}{
        $A(G)=
        \begin{pmatrix}
        0 & 1 & 1 & 0 \\
        1 & 0 & 0 & 1 \\
        1 & 0 & 0 & 1 \\
        0 & 1 & 1 & 0 \\
        \end{pmatrix}$
    }   \end{minipage}
\end{frame}
\end{document}

4 Answers4

2

Here is a starting point.

enter image description here

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,calc}

\begin{document}
\begin{frame}
\[
G=
\begin{tikzpicture}[-,>=stealth',shorten >=1pt,auto,node distance=3.5cm,scale = 1,baseline={(foo)}]
\node[state] (1)  {$1$};
\node[state] (2) [right of=1] {$2$};
\node[state] (3) [below of=2] {$3$};
\node[state] (4) [left of=3] {$4$};

\coordinate (foo) at ($(4.base)!0.5!(1.base)$);
\coordinate (faa) at ($(2.base)!0.5!(3.base)$);

\path   (1) edge              node {$$} (2)
(2) edge              node {$$} (3)
(3) edge              node {$$} (4)
(4) edge              node {$$} (1);

\node[right=1em] at (faa) {\resizebox{.1\linewidth}{!}{$\rightsquigarrow$}};
\end{tikzpicture}
\
A(G)=
\begin{pmatrix}
0 & 1 & 1 & 0 \\
1 & 0 & 0 & 1 \\
1 & 0 & 0 & 1 \\
0 & 1 & 1 & 0 \\
\end{pmatrix}
\]
\end{frame}
\end{document}
Sigur
  • 37,330
1

Just use an equation. And use positioning. Embed the tikzpicture with an appropriate baseline. Please do not use \resizebox.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}

\begin{document}
\begin{frame}[t]
\frametitle{An equation with an embedded Ti\emph{k}Z picture}
\[G=
  \begin{tikzpicture}[-,shorten >=1pt,auto,node
  distance=1.5cm,baseline={(Gaux.base)}]
      \path node[state] (1)  {$1$}
      node[state] (2) [right=of 1] {$2$}
      node[state] (3) [below=of 2] {$3$}
      node[state] (4) [left=of 3] {$4$}
       foreach \X [remember=\X as \LastX (initially 4)] in {1,...,4}
       {(\LastX) edge (\X)}
       (2)-- node(Gaux) {$\vphantom{G}$}(3);
      \draw[very thick,line cap=round,->] ([xshift=1em]Gaux)
      -- ++ (0.5em,0.5em) -- ++ (1em,-1em) -- ++ (1em,1em)
      -- ++ (0.5em,-0.5em) -- ++ (1em,0);
  \end{tikzpicture}
  ~A(G)=\begin{pmatrix}
        0 & 1 & 1 & 0 \\
        1 & 0 & 0 & 1 \\
        1 & 0 & 0 & 1 \\
        0 & 1 & 1 & 0 \\
        \end{pmatrix}
\]
\end{frame}

\end{document}

enter image description here

1

A solution without additional packages involves two tabularenvironments (see https://tex.stackexchange.com/a/473626/193767)

\documentclass{beamer}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows, automata}
\begin{document}
\begin{minipage}{.3\textwidth}
    $G$
\resizebox*{\textwidth}{!}{%
\begin{tabular}{@{}c@{}c@{}}
$G$=& \begin{tabular}{@{}c}
\begin{tikzpicture}[-,>=stealth',shorten >=1pt,auto,node distance=3.5cm,scale = 1,transform shape]
        \node[state] (1)  {$1$};
        \node[state] (2) [right of=1] {$2$};
        \node[state] (3) [below of=2] {$3$};
        \node[state] (4) [left of=3] {$4$};

        \path   (1) edge              node {$$} (2)
        (2) edge              node {$$} (3)
        (3) edge              node {$$} (4)
        (4) edge              node {$$} (1);
        \end{tikzpicture} \\
\end{tabular}
\end{tabular}
}
\end{minipage}
\end{document}
1

I'd keep it simpler, without those scaling and minipages. The \leadsto is magnified here, but I'd much prefer the standard size.

\documentclass{beamer}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows, automata}

\begin{document}

\begin{frame}
\frametitle{Orthonormalbasis aus Eigenvektoren: Beispiel}

\[
G=
\begin{gathered}
  \begin{tikzpicture}[
    scale=0.5,
    -,
    >=stealth',
    shorten >=1pt,
    auto,
    node distance=3cm,
    transform shape
  ]
  \node[state] (1) {$1$};
  \node[state] (2) [right of=1] {$2$};
  \node[state] (3) [below of=2] {$3$};
  \node[state] (4) [left of=3] {$4$};

  \path (1) edge node {} (2)
        (2) edge node {} (3)
        (3) edge node {} (4)
        (4) edge node {} (1);
    \end{tikzpicture}
\end{gathered}
\pause
\mathrel{\raisebox{-0.25\height}{\scalebox{2}{$\leadsto$}}}
A(G)=
  \begin{pmatrix}
  0 & 1 & 1 & 0 \\
  1 & 0 & 0 & 1 \\
  1 & 0 & 0 & 1 \\
  0 & 1 & 1 & 0 \\
  \end{pmatrix}
\]
\end{frame}

\end{document}

enter image description here

egreg
  • 1,121,712