让文本在 tikzpicture 左侧垂直居中

让文本在 tikzpicture 左侧垂直居中

我有一个关于文本对齐的问题:我想有一个 G=(tikzpicture) 部分,就像我示例中的矩阵一样。我没有找到有用的答案,我找到的只是对齐节点内的内容。

如果可能的话(如果你知道我猜的话,一切皆有可能),我希望把它放在 tikzpicture 之外,同时我对每个答案都很满意!尝试用新节点解决它只会给我带来错误,真遗憾。我尝试用一​​个新的小页面,但图表和文本之间存在相当大的差距。

提前致谢!

编辑:感谢大家的快速回复,它们都对我有很大帮助,尤其是让我更好地理解这些内容!

错误的对齐

这是可编译的代码,重点关注重要部分:

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

整个代码如下(但由于没有使用包,所以无法编译):

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

答案1

我会让它更简单,没有那些缩放和小页面。\leadsto这里是放大的,但我更喜欢标准尺寸。

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

在此处输入图片描述

答案2

这是一个起点。

在此处输入图片描述

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

答案3

只需使用一个方程。并使用positioning。用适当的基线嵌入tikzpicture。请不要使用\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}

在此处输入图片描述

答案4

无需额外软件包的解决方案涉及两个tabular环境(参见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}

相关内容