\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
[remember picture,overlay,every node/.style={inner sep=2pt}]
\node[anchor=center,circle,fill=magenta,text=white,font=\sffamily,scale=2]
at ($(current page.north east)+(-0.5in,-0.1\paperheight)$) {C};
\node[anchor=center,circle,fill=magenta,text=white,font=\sffamily,scale=2]
at ($(current page.north east)+(-0.5in,-0.2\paperheight)$) {Y};
\node[anchor=center,circle,fill=magenta,text=white,font=\sffamily,scale=2]
at ($(current page.north east)+(-0.5in,-0.3\paperheight)$) {B};
\node[anchor=center,circle,fill=magenta,text=white,font=\sffamily,scale=2]
at ($(current page.north east)+(-0.5in,-0.4\paperheight)$) {Y};
\node[anchor=center,circle,fill=magenta,text=white,font=\sffamily,scale=2]
at ($(current page.north east)+(-0.5in,-0.5\paperheight)$) {R};
\node[anchor=center,circle,fill=magenta,text=white,font=\sffamily,scale=2]
at ($(current page.north east)+(-0.5in,-0.6\paperheight)$) {U};
\node[anchor=center,circle,fill=magenta,text=white,font=\sffamily,scale=2]
at ($(current page.north east)+(-0.5in,-0.7\paperheight)$) {S};
\node[anchor=center,circle,fill=magenta,text=white,font=\sffamily,scale=2]
at ($(current page.north east)+(-0.5in,-0.8\paperheight)$) {1};
\node[anchor=center,circle,fill=magenta,text=white,font=\sffamily,scale=2]
at ($(current page.north east)+(-0.5in,-0.9\paperheight)$) {4};
\end{tikzpicture}
\end{document}
这里,我如何减少节点之间的距离并将它们分组并将它们置于边缘的中心。
答案1
您可以使用positioning
库和密钥node distance
来实现这一点。我有 Gonzalo 的方框技术,因为可以很容易地将方框的中心放在页面东侧。
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\tikzset{mynode/.style={anchor=center,circle,fill=magenta,text=white,font=\sffamily,scale=2,inner
sep=2pt,minimum width=0.6cm}}
\newsavebox\mybox
\savebox\mybox{%
\begin{tikzpicture}[node distance=.1cm]
\node[mynode] (c) {C};
\node[mynode,below=of c] (y1) {Y};
\node[mynode,below=of y1] (b) {B};
\node[mynode,below=of b] (y2) {Y};
\node[mynode,below=of y2] (r) {R};
\node[mynode,below=of r] (u) {U};
\node[mynode,below=of u] (s) {S};
\node[mynode,below=of s] (1) {1};
\node[mynode,below=of 1] (4) {4};
\end{tikzpicture}%
}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\node at ($(current page.east)+(-0.5in,0)$) {\usebox\mybox};
\end{tikzpicture}
\end{document}
改变node distance
将会改变节点之间的分离。
答案2
一个选项是使用链条轻松定位节点,使用盒子保存初始内容;node distance
可以用来控制距离:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc,chains,positioning}
\newsavebox\mybox
\savebox\mybox{%
\begin{tikzpicture}[
start chain=going below,
node distance=1mm,
every node/.style={
anchor=center,
circle,
fill=magenta,
text=white,
font=\sffamily,
scale=2,
inner sep=2pt,
outer sep=0pt,
on chain
},
]
\node {C};
\node {Y};
\node {B};
\node {Y};
\node {R};
\node {U};
\node {S};
\node {1};
\node {4};
\end{tikzpicture}%
}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\node at ($(current page.east)+(-0.5in,0)$) {\usebox\mybox};
\end{tikzpicture}
\end{document}