Tikz:节点组的水平居中
我需要将图表的每一行与中心对齐。我正在尝试用 xshift 来做到这一点。这是代码:
\begin{tikzpicture}[node distance=1.5cm, auto, text centered]
\tikzstyle{every node}=[draw,ball];
\begin{scope}[xshift=1.5cm]
\node (A) {A};
\node [right of=A] (B) {B};
\node [right of=B] (C) {C};
\node [right of=C] (D) {D};
\end{scope}
\begin{scope}[yshift=-1.5cm]
\node (AB) {AB};
\node [right of=AB] (AC) {AC};
\node [right of=AC] (AD) {AD};
\node [right of=AD] (BC) {BC};
\node [right of=BC] (BD) {BD};
\node [right of=BD] (CD) {CD};
\end{scope}
\begin{scope}[yshift=-3cm,node distance=2cm,xshift=1cm]
\node (ABC) {ABC};
\node [right of=ABC] (ABD) {ABD};
\node [right of=ABD] (ACD) {ACD};
\node [right of=ACD] (BCD) {BCD};
\end{scope}
\begin{scope}[xshift=4cm, yshift=-4.5cm, node distance=2cm]
\node (ABCD) {ABCD};
\end{scope}
\end{tikzpicture}
还有其他方法吗?不喜欢每次都改变 xshift 值。
I need to align each row of the graph to the center. I am trying to do it with xshift. Here the code:
\begin{tikzpicture}[node distance=1.5cm, auto, text centered]
\tikzstyle{every node}=[draw,ball];
\begin{scope}[xshift=1.5cm]
\node (A) {A};
\node [right of=A] (B) {B};
\node [right of=B] (C) {C};
\node [right of=C] (D) {D};
\end{scope}
\begin{scope}[yshift=-1.5cm]
\node (AB) {AB};
\node [right of=AB] (AC) {AC};
\node [right of=AC] (AD) {AD};
\node [right of=AD] (BC) {BC};
\node [right of=BC] (BD) {BD};
\node [right of=BD] (CD) {CD};
\end{scope}
\begin{scope}[yshift=-3cm,node distance=2cm,xshift=1cm]
\node (ABC) {ABC};
\node [right of=ABC] (ABD) {ABD};
\node [right of=ABD] (ACD) {ACD};
\node [right of=ACD] (BCD) {BCD};
\end{scope}
\begin{scope}[xshift=4cm, yshift=-4.5cm, node distance=2cm]
\node (ABCD) {ABCD};
\end{scope}
\end{tikzpicture}
Is there any other way to do it? Do not like to change xshift values every time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将每一行设为自己的矩阵,从而使您可以有效地将一组节点分组为一个。
您的示例
注意:请确保
\usetikzlibrary{matrix}
结果为
(我创造了自己的
球
风格。)You can make each row its own matrix, allowing you to effectively group a set of nodes into one.
Your Example
Note: be sure to
\usetikzlibrary{matrix}
Results in
(I made up my own
ball
style.)