2

I have 2 nodes of different height. They are positioned relative to the nodes below them, b1 and b2, which are the same height and have the same y value.
I want b1, b2 to have the same horizontal distance as a1, a2 and I want them to be vertically centered.
But because a1, a2 have different lengths I can't just use right=of b1 because the x value will not align with a2. Likewise above=of a2 results in the wrong y-value.
I would like to have both right=of b1 and above=of a2 for my upper right node.

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

\begin{document}
    \begin{tikzpicture}

      \node [draw] (a1) {loooooooooong};
      \node [draw, right=of a1] (a2) {short};

      \node [draw, above=of a1] (b1) {$\begin{bmatrix}1\\2\\3\\4\end{bmatrix}$};
      \node [draw, blue, above=of a2] (b2) {$\dots$};
      \node [draw, green, right=of b1] (b3) {$\dots$};

    \end{tikzpicture}
\end{document}

image

2

like this?

enter image description here

one possibility is:

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

\begin{document}
    \begin{tikzpicture}

      \node [draw] (a1) {loooooooooong};
      \node [draw, right=of a1] (a2) {short};

      \node [draw, above=of a1] (b1) {$\begin{bmatrix}1\\2\\3\\4\end{bmatrix}$};
      \node [draw, blue, above=of a2] (b2) {$\dots$};
      \node [draw, green, at=(b1 -| a2)] (b3) {$\dots$}; % <---

    \end{tikzpicture}
\end{document}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.