他の2つのノードの中央にノードを配置するにはどうすればよいですか?
Aug 20 2020
2つのノードがあり、それらの中央に3番目のノードを配置したいと思います。以下の例では、ノードZの垂直位置が適切です。ただし、ノードZをさらに右に移動して、下部の2つのノードに対して中央に配置したいと思います。above=of x!0.5!y
これを行うのと同様の、または別の簡単な方法の補間コマンドはありますか?
例:
\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}
出力:

私は他の2つのノードの下にある関連する質問tikzcenter nodeを知っていますが、答えは、right above=x
実際にはXとYの間のノードを中央に配置していないことを示唆しているようです。
回答
4 Zarko Aug 20 2020 at 01:26
このような:

\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
on grid
オプション付きの別の方法。

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