将 tikzpicture 集中锚定以包含在文本中

将 tikzpicture 集中锚定以包含在文本中

我有两张图,想在它们之间同一行插入文本,以便讨论它们之间的转换。我还想用我在文本其他地方引用的标签来引用整个图。我遇到的问题是,tikzpictures 被放入方程式中的西南角(我认为是西南角),因此文本和标签与我的图相比都非常低。

这是 MWE 及其输出

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\begin{document}
    \begin{equation}\label{equation}
        \begin{tikzpicture}
            \node[circle,draw] (0) at (0,0) {0};
            \node[circle,draw] (1) at (0,4) {1};
            \draw (0) -- (1);
        \end{tikzpicture}
        \quad \text{adding 1 gives} \quad
        \begin{tikzpicture}
            \node[circle,draw] (0) at (0,0) {1};
            \node[circle,draw] (1) at (0,4) {2};
            \draw (0) -- (1);
        \end{tikzpicture}
    \end{equation}
\end{document}

在此处输入图片描述

我希望通过将 tikzpictures 锚定在中间而不是底部来包含它们,但我也乐意手动将标签和文本移到更高的位置(尽管这似乎可能更复杂)。我还使用另一个命令调用 tikzpictures,因此无法直接编辑它们。

答案1

无需手动将设置baseline为例如2cm,可以将所有内容(包括可能不同大小的节点)垂直居中。

放置\tikzset{baseline=(current bounding box)}在 之前\end{tikzpicture}

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\begin{equation}\label{equation}
\begin{tikzpicture}
\node[circle,draw] (0) at (0,0) {0};
\node[circle,draw] (1) at (0,4) {1};
\draw (0) -- (1);
\tikzset{baseline=(current bounding box)}
\end{tikzpicture}
\quad \text{adding 1 gives} \quad
\begin{tikzpicture}
\node[circle,draw] (0) at (0,0) {1};
\node[circle,draw] (1) at (0,4) {2};
\draw (0) -- (1);
\tikzset{baseline=(current bounding box)}
\end{tikzpicture}
\end{equation}
\end{document}

两条居中的垂直线,两端有圆形节点

相关内容