我使用 tikz 制作了下图。它几乎满足了我的要求,但我想知道是否有办法将文本对齐到边缘。具体来说,我希望文本
- 边缘之上
- 与中间边缘的文本中心对齐
遵循的 MWE 将文本放在边缘上方,但不对齐文本。
\documentclass[multi=tikzpicture, border=1mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node (x1) at (5,0) {$x_1$};
\node (y1) at (4,2.5) {$Y_1$};
\node (y2) at (5,2.5) {$ \cdots$};
\node (y3) at (6,2.5) {$Y_k$};
\node (mu1) at (5,5) {$ \mu_1$};
\draw (x1) edge (y1);
\draw (x1) edge (y2);
\draw (x1) edge (y3);
\draw (y1) edge (mu1);
\draw (y2) edge (mu1);
\draw (y3) edge (mu1);
\path (x1) edge node[above] (one) {this is $x$} (11,0);
\path (y3) edge node[above] (one) {this is $Y$} (11,2.5);
\path (mu1) edge node[above] (one) {this is $mu$} (11,5);
\end{tikzpicture}
\end{document}
非常感谢您的帮助!提前致谢!
答案1
一种可能的方法是绘制线条后添加两个节点,例如使用
\node[above] at (one |- y3) {this is $Y$};
这里(one |- y3)
表示 x 坐标为one
, y 坐标为 的点y3
(读|-
作从第一个坐标垂直方向,从第二个坐标水平方向)。
\documentclass[multi=tikzpicture, border=1mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node (x1) at (5,0) {$x_1$};
\node (y1) at (4,2.5) {$Y_1$};
\node (y2) at (5,2.5) {$ \cdots$};
\node (y3) at (6,2.5) {$Y_k$};
\node (mu1) at (5,5) {$ \mu_1$};
\draw (x1) edge (y1);
\draw (x1) edge (y2);
\draw (x1) edge (y3);
\draw (y1) edge (mu1);
\draw (y2) edge (mu1);
\draw (y3) edge (mu1);
\path (x1) edge node[above] (one) {this is $x$} (11,0);
\path (y3) edge (11,2.5);
\path (mu1) edge (11,5);
\node[above] at (one |- y3) {this is $Y$};
\node[above] at (one |- mu1) {this is $mu$};
\end{tikzpicture}
\end{document}