¿Cómo colocar un nodo centrado sobre otros dos nodos?

Aug 20 2020

Tengo dos nodos y me gustaría colocar un tercer nodo centrado sobre ellos. En el siguiente ejemplo, la posición vertical del nodo Z es buena. Sin embargo, me gustaría mover el nodo Z más hacia la derecha para centrarlo en relación con los dos nodos de la parte inferior. ¿Existe un comando de interpolación similar above=of x!0.5!yu otra forma sencilla de hacer esto?

Ejemplo:

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

Salida:

Soy consciente de la pregunta relacionada con el nodo central tikz debajo de otros 2 nodos, pero las respuestas parecen sugerir right above=xque en realidad no centra el nodo entre X e Y.

Respuestas

4 Zarko Aug 20 2020 at 01:26

Me gusta esto:

\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 AndréC Aug 20 2020 at 01:40

Otra forma con on gridopción.

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