![Tikz:考虑像节点矩阵这样的坐标](https://linux22.com/image/440275/Tikz%EF%BC%9A%E8%80%83%E8%99%91%E5%83%8F%E8%8A%82%E7%82%B9%E7%9F%A9%E9%98%B5%E8%BF%99%E6%A0%B7%E7%9A%84%E5%9D%90%E6%A0%87.png)
总结:是否可以使用坐标符号,但matrix of nodes
类似行为让列适应内容的宽度?
说明
我正在使用 tikzit 绘制一些带有节点的图:
但是,如您所见,一些节点相距很远(第一个节点),而另一些节点重叠。 Tikzit 使用以下方式自动定位节点:
\node[style=Z] (3) at (2,1) {$-\delta+a\pi$};
当然,我可以在 tikzit 中改变节点的位置,但我不喜欢这样,因为当我改变样式时,我需要改变所有图片以获得正确的对齐(这实际上就是我现在正在做的......),而且有时我想自动生成这些图片。
所以我希望像这样的坐标(2,1)
(它们都是整数)的行为有点像matrix if nodes
,即“列”2 应该与其最宽的内容一样宽,再加上列之间的一些固定空间......但当然保持 tikzit 语法以与 tikz 兼容。
有什么诀窍可以做到这一点吗?
梅威瑟:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds,positioning}
\usetikzlibrary{shapes,shapes.geometric,shapes.misc}
\pgfdeclarelayer{edgelayer}
\pgfdeclarelayer{nodelayer}
\pgfsetlayers{background,edgelayer,nodelayer,main}
\begin{document}
\tikzstyle{Z}=[minimum size=3mm, font={\footnotesize\boldmath}, shape=rectangle, rounded corners=1.3mm, inner sep=1mm, outer sep=-1.8mm, scale=0.8, draw=black, fill={rgb,255: red,204; green,255; blue,204},shape=ellipse,inner sep=0pt,]
%% picture generated by tikzit
\begin{tikzpicture}[scale=.9]
\begin{pgfonlayer}{nodelayer}
\node[style=Z] (0) at (-1,1) {};
\node[style=Z] (1) at (0,1) {$\alpha$};
\node[style=Z] (2) at (1,1) {$-\delta$};
\node[style=Z] (3) at (2,1) {$-\delta+a\pi$};
\node[style=Z] (4) at (4,1) {\thinmuskip=0mu\medmuskip=0mu\thickmuskip=0mu$-\delta+a\pi$};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw (0.center) to (1.center);
\draw (1.center) to (2.center);
\draw (2.center) to (3.center);
\draw (3.center) to (4.center);
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
答案1
postitioning
您可以使用库并相对于其他节点放置节点,而不是绝对位置。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds,positioning}
\usetikzlibrary{shapes,shapes.geometric,shapes.misc}
\pgfdeclarelayer{edgelayer}
\pgfdeclarelayer{nodelayer}
\pgfsetlayers{background,edgelayer,nodelayer,main}
\begin{document}
\tikzstyle{Z}=[minimum size=3mm, font={\footnotesize\boldmath}, shape=rectangle, rounded corners=1.3mm, inner sep=1mm, outer sep=-1.8mm, scale=0.8, draw=black, fill={rgb,255: red,204; green,255; blue,204},shape=ellipse,inner sep=0pt,]
%% picture generated by tikzit
\begin{tikzpicture}[scale=.9]
\begin{pgfonlayer}{nodelayer}
\node[style=Z] (0) {};
\node[style=Z, right=of 0] (1) {$\alpha$};
\node[style=Z, right=of 1] (2) {$-\delta$};
\node[style=Z, right=of 2] (3) {$-\delta+a\pi$};
\node[style=Z, right=of 3] (4) {\thinmuskip=0mu\medmuskip=0mu\thickmuskip=0mu$-\delta+a\pi$};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
\draw (0.center) to (1.center);
\draw (1.center) to (2.center);
\draw (2.center) to (3.center);
\draw (3.center) to (4.center);
\end{pgfonlayer}
\end{tikzpicture}
\end{document}