3

I have two nodes and would like to position a third node centered above them. In the example below, the vertical position of node Z is good. However, I would like to move node Z further to the right to be centered relative to the two nodes at the bottom. Is there an interpolation command similar to above=of x!0.5!y or another simple way of doing this?

Example:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta,fit,calc,backgrounds,shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[circle, draw=black] (x) {$x$};
\node[circle, draw=black, right=of x] (y) {$y$};
\node[circle, draw=black, above=of x] (z) {$z$};
\path (x) edge[->, sloped, anchor=south] node {left} (z);
\path (z) edge[->, sloped, anchor=south] node {right} (y);
\path (x) edge[->, sloped, anchor=north] node {bottom} (y);
\end{tikzpicture}
\end{document}

Output:

triangle of three nodes

I'm aware of the related question tikz center node below 2 other nodes but the answers seem to suggest right above=x which does not actually center the node between X and Y.

4

Like this:

enter image description here

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                calc,
                positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[
node distance = 13mm,
     C/.style = {%C: as circle
                 circle, draw, minimum size=1.5em, inner sep=2pt},
every edge/.style = {draw, -Straight Barb},
every edge quotes/.style = {auto, font=\footnotesize, inner sep=1pt, sloped}
                        ]
\node[C] (x) {$x$};
\node[C, right=of x] (y) {$y$};
\node[C, above=of $(x.north)!0.5!(y.north)$] (z) {$z$};
\path   (x) edge["left"]    (z)
        (z) edge["right"]   (y)
        (x) edge["bottom"]  (y);
    \end{tikzpicture}
\end{document}
1

Another way with on grid option.

screenshot

\documentclass[border=5mm,tikz]{standalone}

\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\begin{scope}[on grid,node distance=2cm]
\draw[help lines](-1,-1) grid(3,3);%<-- comment this line to hide the grid
\node[circle, draw=black] (x) {$x$};
\node[circle, draw=black, right=of x] (y) {$y$};
\node[circle, draw=black, above right=2cm and 1cm of x] (z) {$z$};
\end{scope}

\path (x) edge[->, sloped, anchor=south] node {left} (z);
\path (z) edge[->, sloped, anchor=south] node {right} (y);
\path (x) edge[->, sloped, anchor=north] node {bottom} (y);

\end{tikzpicture}
\end{document}

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.