我在用 tikz 绘制简单图表时遇到了麻烦。我想要的是一个在左对齐节点之间绘制线条的图表。但垂直对齐会使线条倾斜/倾斜,看起来很丑陋(见下面的示例)。我该如何避免这种情况?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[every node/.style={anchor=base west}]
\matrix [matrix of math nodes, row sep=5mm] {
\node (X) {X_{i}}; \\
\node (Y) {Y_{ij}}; \\
\node (Z) {Z_{ijk}}; \\
};
\draw (X) -- (Y);
\draw (Y) -- (Z);
\end{tikzpicture}
\end{document}
答案1
像这样吗?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[every node/.style={anchor=base west}]
\matrix [matrix of math nodes, row sep=5mm] {
\node (X) {X_{i}}; \\
\node (Y) {Y_{ij}}; \\
\node (Z) {Z_{ijk}}; \\
};
\draw (X) -- (Y.north -| X); % <--- added -| X for determining coordinate
% cross vertical line through middle of X
% and horizontal through north of Y
\draw (Y) -- (Z.north -| X);
\end{tikzpicture}
\end{document}