# Add text to spin chain with TikZ

I would like to add the text to a spin chain.

This is what I did:

\begin{tikzpicture}
\draw[-] (5,0) -- (0,0) node[left]{$a)$};
% \draw[-stealth] (0,-.25) -- (0,.25);
\draw[](.5, 0) circle(.08);
\draw[-stealth, blue, line width= 0.5mm] (.5,-.25) -- (.5,.25);
\draw[](1, 0) circle(.08);
\draw[-stealth, red, line width= 0.5mm] (1,.25) -- (1,-.25);
\draw[](1.5, 0) circle(.08);
\draw[-stealth, blue, line width= 0.5mm] (1.5,-.25) -- (1.5,.25);
\draw[](2, 0) circle(.08);
\draw[-stealth, red, line width= 0.5mm] (2,.25) -- (2,-.25);
\draw[](2.5, 0) circle(.08);
\draw[-stealth, blue, line width= 0.5mm] (2.5,-.25) -- (2.5,.25);
\draw[](3, 0) circle(.08);
% \draw[-stealth, red, line width= 0.5mm] (3,.25) -- (3,-.25);
\draw[](3.5, 0) circle(.08);
\draw[-stealth, blue, line width= 0.5mm] (3.5,-.25) -- (3.5,.25);
\draw[](4, 0) circle(.08);
\draw[-stealth, red, line width= 0.5mm] (4,.25) -- (4,-.25);
\draw[](4.5, 0) circle(.08);
\draw[-stealth, blue, line width= 0.5mm] (4.5,-.25) -- (4.5,.25);

\begin{scope}[yshift = -1cm]
\draw[-] (5,0) -- (0,0) node[left]{$b)$};

\draw[](.5, 0) circle(.08);
\draw[-stealth, blue, line width= 0.5mm] (.5,-.25) -- (.5,.25);

\draw[](1, 0) circle(.08);
\draw[-stealth, blue, line width= 0.5mm] (1,-.25) -- (1,.25);

\draw[](1.5, 0) circle(.08);
\draw[-stealth, red, line width= 0.5mm] (1.5,.25) -- (1.5,-.25);

\draw[](2, 0) circle(.08);
\draw[-stealth, blue, line width= 0.5mm] (2,-.25) -- (2,.25);

\draw[](2.5, 0) circle(.08);
\draw[-stealth, red, line width= 0.5mm] (2.5,.25) -- (2.5,-.25);

\draw[](3, 0) circle(.08);
\draw[-stealth, blue, line width= 0.5mm] (3,-.25) -- (3,.25);

\draw[](3.5, 0) circle(.08);
\draw[-stealth, red, line width= 0.5mm] (3.5,.25) -- (3.5,-.25);

\draw[](4, 0) circle(.08);
\draw[-stealth, blue, line width= 0.5mm] (4,-.25) -- (4,.25);

\draw[](4.5, 0) circle(.08);
% \draw[-stealth, blue, line width= 0.5mm] (4.5,-.25) -- (4.5,.25);
\end{scope}

\end{tikzpicture}

and this is how I would like to add the text:

How can I do it? Thanks!

## 2 Answers

Why suffer? I suggest you use the LaTeX main ability to use macros. I defined three macros, for the arrow up, down, and the green circle. The macros are thought to draw an element incrementally, going right, in the same path.

Then I mark "interesting" points on the line naming them with coordinates, and add the relevant text. I heavily commented the code to explain it.

\documentclass[border=3.14]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\newcommand{\arrUP}{%
% continue the line moving 0.5 right.
-- ++(0.5,0) circle[radius=0.05]
% using an edge here, because you can't change color or arrow
% only in parts of a path. The edges are drawn  last, so they
% will overwrite the circles
++(0,-0.5) edge[red, -Stealth, line width=0.5mm] ++(0,1)
% edges do not move to the final point, so go back to the main line
++(0,0.5)
}
\newcommand{\arrDN}{%
-- ++(0.5,0) circle[radius=0.05]
++(0,-0.5) edge[blue, Stealth-, line width=0.5mm] ++(0,1)
++(0,0.5)
}
\newcommand{\holo}{%
% nodes are drawn after the path, but before edges. So this will
% overwrite the main line (try removing the fill!)
-- ++(0.5,0) node[circle, draw=green, thick, inner sep=1mm, fill=white]{}
}
\begin{document}
\begin{tikzpicture}[]
\draw (0,0) \arrUP \arrDN \arrUP \holo coordinate(holo1)
\arrUP \arrDN \arrUP \arrDN \arrUP \arrDN \arrUP \arrDN
\arrUP coordinate(sp1) \arrUP coordinate(sp2)
;
\draw [thin] (holo1) ++(0,-0.4) to[bend right] ++(0.5,-0.3)
node[right]{electron removed};
\draw [thin] ([yshift=-0.6cm]sp1) to[bend right]
node[midway, below]{spinon} ([yshift=-0.6cm]sp2);
\end{tikzpicture}
\end{document}

• How I did it is more intuitive for me, because I'm a noob at these things... But I see that these two codes you guys did, are more elegant and efficient. Jun 12, 2021 at 7:37
• ps. thanks for the comments in the code, I'll use in the future now that is clear who is what :) Jun 12, 2021 at 7:38
• I like yours too!! :-P Jun 12, 2021 at 7:40

As Rmano suggests it's better to do it with macros. This is another way to do it, with a macro which draws the chain.

\documentclass[border=2mm]{standalone}
\usepackage    {tikz}
\usetikzlibrary{calc}

\newcommand{\spinchain}[3]% position, label, electrons
{%
\begin{scope}[shift={#1},scale=0.5]
\node at (0,0) {#2)};
\foreach[count=\j]\i in {#3}
{% counting the number of electrons
\global\let\jj=\j % remember the last \j
}
\draw (0.5,0) -- (\jj+0.5,0);
\foreach[count=\j]\i in {#3}
{%
\coordinate (#2\j) at (\j,-1);
\ifnum\i = 1
\fill (\j,0) circle (0.12);
\draw[-stealth,red,line width= 0.5mm] (\j,-0.5) --++ (0,1);
\else\ifnum\i = -1
\fill (\j,0) circle (0.12);
\draw[-stealth,blue,line width= 0.5mm] (\j,0.5) --++ (0,-1);
\else
\draw[thick,green,fill=white] (\j,0) circle (0.16);
\fi\fi
}
\end{scope}
}

\begin{document}
\begin{tikzpicture}
\spinchain{(0,2)}{a}{1,-1,1,0,1,-1,1,-1,1,-1,1,-1,1,-1}
\spinchain{(0,0)}{b}{1,-1,1,1,-1,1,-1,1,-1,0,1,-1,1,-1}
\draw (a4) to [bend right] ($(a6)-(0,0.5)$) node [right] {\strut electron removed};
\draw (b3) to [bend right] node [midway,below] {\strut spinon} (b4);
\draw ($(b9)!0.5!(b10)$) to [bend right] node [midway,below] {\strut holon} ($(b10)!0.5!(b11)$) ;
\end{tikzpicture}
\end{document}

• Nice, I like it! Jun 11, 2021 at 21:52
• thanks Juan !!;) Jun 12, 2021 at 7:45
• It is difficult not to see the smiley faces in the second line :-) Jun 12, 2021 at 21:42