我需要底部节点从它们各自的顶部节点开始,而不是位于它们下方的中心。
输出:
代码:
\begin{tikzpicture}
\node[align=left,draw=black,rounded corners](colOne_rowOne)
{
this is line 1\\
this is line 2, this is line 2
};
\node[below=of colOne_rowOne,align=left,draw=black,rounded corners](colOne_rowTwo)
{
this is line
};
\node[right=of colOne_rowOne,align=left,draw=black,rounded corners](colTwo_rowOne)
{
this is line 1\\
this is line 2, this is line 2
};
\node[below=of colTwo_rowOne,align=left,draw=black,rounded corners](colTwo_rowTwo)
{
this is line
};
\end{tikzpicture}
答案1
虽然@Zarko 的答案在这种情况下有效,但我认为使用锚点更清晰:
\begin{tikzpicture}[box/.style={align=left,draw=black,rounded corners}]
\node[box](colOne_rowOne)
{
this is line 1\\
this is line 2, this is line 2
};
\node[box, below=of colOne_rowOne.south west, anchor=north west](colOne_rowTwo)
{
this is west-aligned
};
\node[box, right=of colOne_rowOne](colTwo_rowOne)
{
this is line 1\\
this is line 2, this is line 2
};
\node[box, below=of colTwo_rowOne.south east, anchor=north east](colTwo_rowTwo)
{
this is east-aligned
};
\end{tikzpicture}
锚点就是为这个任务而设的:它们告诉当前节点的哪个点应该位于给定的坐标处。然后你可以使用键node distance
来改变节点之间的距离。
答案2
重建缺失的序言并不好玩:它包含了图像绘制的重要信息......
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 3mm and 0mm,
box/.style = {shape=rectangle, draw, rounded corners, align=left}
]
\node[box](colOne_rowOne)
{
this is line 1\\
this is line 2, this is line 2
};
\node[box, below right=of colOne_rowOne.south west](colOne_rowTwo)
{
this is line
};
\node[box, right=6mm of colOne_rowOne](colTwo_rowOne)
{
this is line 1\\
this is line 2, this is line 2
};
\node[box, below right=of colTwo_rowOne.south west] (colTwo_rowTwo)
{
this is line
};
\end{tikzpicture}
\end{document}