2

I've got two diagrams, and am trying to put text in between them on the same line so as to talk about a transformation between them. I'm also trying to be able to reference the diagram as a whole with a label which I'm referencing elsewhere in the text. The issue I'm having is that the tikzpictures are put into the equation by (what I think is) the south west corner, so that the text and label are both very low compared to my diagrams.

Here's a MWE and its output

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

enter image description here

My hope would be to include the tikzpictures by anchoring them in the middle as opposed to the bottom, but I would also be happy with manually moving the label and text higher (although this seems like it could be more complicated). I'm also calling the tikzpictures in with another command so am not really able to edit them directly.

1
  • 1
    Add baseline=2cm as option to the two tikzpicture environments: \begin{tikzpicture}[baseline=2cm]. Commented Mar 21 at 18:41

1 Answer 1

5

Instead of manually setting the baseline to e.g. 2cm, it is possible to vertical center everything including possible different sized nodes.

Place \tikzset{baseline=(current bounding box)} just before \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}

Two centered vertical lines with circle nodes in the ends

You must log in to answer this question.

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