我有以下代码:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{amsmath,amsfonts,physics}
\usetikzlibrary{shapes.multipart,positioning}
\begin{document}
\begin{tikzpicture}[stack/.style={rectangle split, rectangle split parts=#1, draw, anchor=south},auto]
\node (LMA) [stack=1,label=below:{\texttt{LM(A)}}] {
\nodepart{one}\(\vb*{A}\)
};
\node (PUM1) [stack=2,label=below:{\texttt{PuM()}},right=of LMA] {
\nodepart{one}\(\vb*{A}\)
\nodepart{two}\(\vb*{A}\)
};
\node (MMB) [stack=2,label=below:{\texttt{MM(B)}},right=of PUM1] {
\nodepart{one}\(\vb*{AB}\)
\nodepart{two}\(\vb*{A}\)
};
\node (MMC) [stack=2,label=below:{\texttt{MM(C)}},right=of MMB] {
\nodepart{one}\(\vb*{ABC}\)
\nodepart{two}\(\vb*{A}\)
};
\node (LMD) [stack=2,label=below:{\texttt{LM(D)}},right=of MMC] {
\nodepart{one}\(\vb*{D}\)
\nodepart{two}\(\vb*{A}\)
};
\node (PUM2) [stack=3,label=below:{\texttt{PuM()}},right=of LMD] {
\nodepart{one}\(\vb*{D}\)
\nodepart{two}\(\vb*{D}\)
\nodepart{three}\(\vb*{A}\)
};
\node (MME) [stack=3,label=below:{\texttt{MM(E)}},right=of PUM2] {
\nodepart{one}\(\vb*{DE}\)
\nodepart{two}\(\vb*{D}\)
\nodepart{three}\(\vb*{A}\)
};
\node (MMF) [stack=3,label=below:{\texttt{MM(F)}},right=of MME] {
\nodepart{one}\(\vb*{DEF}\)
\nodepart{two}\(\vb*{D}\)
\nodepart{three}\(\vb*{A}\)
};
\end{tikzpicture}
\end{document}
生成以下内容:
我该如何改变它,使所有的堆栈都沿着它们的底部边缘来显示矩阵堆栈的增长(我已经尝试过这个anchor=south
,但显然不起作用),标签紧挨着下面?
答案1
使用以下选项定位与前一个节点大小不同的两个节点
right=of LMA.south east,anchor=south west
right=of LMD.south east,anchor=south west
分别。
\documentclass{standalone}
\usepackage{tikz}
\usepackage{amsmath,amsfonts,physics}
\usetikzlibrary{shapes.multipart,positioning}
\begin{document}
\begin{tikzpicture}[stack/.style={rectangle split, rectangle split parts=#1, draw, anchor=south},auto]
\node (LMA) [stack=1,label=below:{\texttt{LM(A)}}] {
\nodepart{one}\(\vb*{A}\)
};
\node (PUM1) [stack=2,label=below:{\texttt{PuM()}},right=of LMA.south east,anchor=south west] {
\nodepart{one}\(\vb*{A}\)
\nodepart{two}\(\vb*{A}\)
};
\node (MMB) [stack=2,label=below:{\texttt{MM(B)}},right=of PUM1] {
\nodepart{one}\(\vb*{AB}\)
\nodepart{two}\(\vb*{A}\)
};
\node (MMC) [stack=2,label=below:{\texttt{MM(C)}},right=of MMB] {
\nodepart{one}\(\vb*{ABC}\)
\nodepart{two}\(\vb*{A}\)
};
\node (LMD) [stack=2,label=below:{\texttt{LM(D)}},right=of MMC] {
\nodepart{one}\(\vb*{D}\)
\nodepart{two}\(\vb*{A}\)
};
\node (PUM2) [stack=3,label=below:{\texttt{PuM()}},right=of LMD.south east,anchor=south west] {
\nodepart{one}\(\vb*{D}\)
\nodepart{two}\(\vb*{D}\)
\nodepart{three}\(\vb*{A}\)
};
\node (MME) [stack=3,label=below:{\texttt{MM(E)}},right=of PUM2] {
\nodepart{one}\(\vb*{DE}\)
\nodepart{two}\(\vb*{D}\)
\nodepart{three}\(\vb*{A}\)
};
\node (MMF) [stack=3,label=below:{\texttt{MM(F)}},right=of MME] {
\nodepart{one}\(\vb*{DEF}\)
\nodepart{two}\(\vb*{D}\)
\nodepart{three}\(\vb*{A}\)
};
\end{tikzpicture}
\end{document}
答案2
改编
- (我稍微降低了 MWE)
- 用于
anchor=south west
所有节点(仅当您给出位置时才考虑锚点,例如at (x, y)
或节点的位置(参见gernots 回答),不是节点) - 将位置设置为
south east
最后一个节点加上偏移量,定义在 中dist
。
代码
\documentclass{standalone}
\usepackage{tikz}
\usepackage{amsmath,amsfonts,physics}
\usetikzlibrary{shapes.multipart,positioning}
\begin{document}
\begin{tikzpicture}[
stack/.style={rectangle split, rectangle split parts=#1, draw, anchor=south west},
auto,
dist/.style={xshift=10mm}
]
\node (LMA) [stack=1,label=below:{\texttt{LM(A)}}] {
\nodepart{one}\(\vb*{A}\)
};
\node (PUM1) [stack=2,label=below:{\texttt{PuM()}}] at ([dist] LMA.south east) {
\nodepart{one}\(\vb*{A}\)
\nodepart{two}\(\vb*{A}\)
};
\node (PUM2) [stack=3,label=below:{\texttt{PuM()}}] at ([dist] PUM1.south east) {
\nodepart{one}\(\vb*{D}\)
\nodepart{two}\(\vb*{D}\)
\nodepart{three}\(\vb*{A}\)
};
\end{tikzpicture}
\end{document}