# How to change the distance between the nodes and club them and bring them to center in TikZ

\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}


Here , How do I reduce the distance between the nodes and group them and bring them in the center of the margin.

-
What do you mean by "group them"? What king of grouping do you have in mind? Can you describe this in detail (or perhaps add an image showing the desired output?) – Gonzalo Medina Feb 10 '14 at 16:50
I meant grouping as the distance between them should be as minimum as possible but they should not touch and they should come at the center of the margin – subham soni Feb 10 '14 at 16:53
The coordinate following the + defines the position of these nodes relative to (current page.north east). So, changing that will adjust where the nodes are placed. Alternatively you can place the nodes relative to each other, but without knowing exactly what you want to achieve it is difficult to help. – Peter Grill Feb 10 '14 at 16:59

You can use positioning library along with the key node distance for this. I have the box technique from Gonzalo as it is easy to put the center of box at page east.

\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}


Changing the node distance will change the separation between nodes.

-

One option using a chain to easily position the nodes and a box to save the initial contents; node distance can be used to control the 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}


-