# Heisenberg Spin exchange figure with Tikz

I want to construct a figure with Tikz similar to this one:

I was looking for example but couldn't find any I tried to make it but it was a mess. so: How can I get the spins on the dots? and how to put them in a table while still being a tikz figure? Thank you for your valuable help

• Welcome to the site! It's a great community :) When asking a question, it's best if you can show what you've tried so far. Asking the community to 'start from something', with specific goals, is generally received more positively than 'start from scratch and make this thing for me'. For your example, you might start with a simple tabular, post what you have, and then point to specific things that are causing problems. Good luck! :) – cmhughes Jan 24 at 11:30

With a tabular environment and a tikz \newcommand you can do the following:

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

\newcommand{\level}[3]% up (1)/down (0), up (1)/down (0), labels (y/n)
{
\begin{tikzpicture}
\useasboundingbox (0,-0.25) rectangle (2,1.25);
\draw[blue,thick,-latex] (0,1-#1) -- (0,#1);
\draw[red ,thick,-latex] (2,1-#2) -- (2,#2);
\draw[dashed] (0,0.5)  -- (2,0.5);
\fill (0,0.5) circle (2pt);
\fill (2,0.5) circle (2pt);
\ifthenelse
{\equal{#3}{y}}
{%
\node at (0,0)   [below] {$S_i$};
\node at (2,0)   [below] {$S_j$};
\node at (1,0.5) [above] {$J_{ij}$};
}
{}
\end{tikzpicture}
}

\renewcommand{\arraystretch}{2}
\begin{document}
\begin{tabular}{|c|c|}\cline{1-2}
\bfseries State 1 & \bfseries State 2 \\\hline
\level{1}{1}{y}   & \level{1}{0}{n}   \\\hline
\bfseries State 3 & \bfseries State 4 \\\hline
\level{0}{1}{n}   & \level{0}{0}{n}   \\\hline
\multicolumn{2}{|c|}{$\displaystyle J_{ij}=\frac{E_1+E_4-E_3-E_2}{4|S_iS_j|}$}\\[2mm]\hline
\end{tabular}
\end{document}
[![enter image description here][1]][1]

[1]: https://i.stack.imgur.com/XGc5e.png

• You might want to replace the deprecated \bf with \bfseries. Also, \cline{1-2} can be replaced with \hline. – leandriis Jan 24 at 16:21
• @leandris, I know, old habits of mine. I'll make an edit – Juan Castaño Jan 24 at 16:24

\documentclass{article}
\usepackage{array}
\usepackage{makecell}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning, arrows.meta}

\tikzset{node distance = 1cm, baseline={(0,0)}}

\newcommand{\spinup}[1][]{
\draw[-Triangle , draw=#1, very thick] (0,0ex) -- (0ex,2em) node (up) {};
\draw[fill=black, draw=#1, draw=black] (0ex,1em) circle (0.5ex);
} % inspired by https://tex.stackexchange.com/a/314648/134144

\newcommand{\spindown}[1][]{
\draw[Triangle-, draw=#1, very thick] (0,0ex) -- (0ex,2em)node (down) {};
\draw[fill=black, draw=#1, draw=black] (0ex,1em) circle (0.5ex);
}

\newcommand{\energylevel}{\draw [dotted] (0,0.9em) -- (1cm, 0.9em);}

\setcellgapes{3pt}
\begin{document}

\makegapedcells
\begin{tabular}{|wc{2cm}|wc{2cm}|}
\hline
State 1 & State 2 \\
\hline
\begin{tikzpicture}
\energylevel;
\node at (0.5cm,2em) {$J_{ij}$};
\spinup[blue];
\node[below of = up]{$S_i$};
\spinup[red, right of= up]
\node[below of = up]{$S_j$};
\end{tikzpicture}
&
\begin{tikzpicture}
\spinup[blue];
\spindown[red, right of= up];
\energylevel
\end{tikzpicture}
\\
\hline
State 3 & State 4 \\
\hline
\begin{tikzpicture}
\energylevel;
\spindown[blue];
\spinup[red, right of= down]
\end{tikzpicture}
&
\begin{tikzpicture}
\spindown[blue];
\spindown[red, right of= down];
\energylevel
\end{tikzpicture}
\\
\hline
\multicolumn{2}{|c|}{$$\displaystyle J_{ij} = \frac{E_1 + E_4 - E_3 - E_2}{4 | S_i S_j |}$$}\\
\hline
\end{tabular}

\end{document}


Maybe you can do this without tikz in a usual table using constructions as this one:

\documentclass{article}
\def\qeq{\mathrel{%
\mathchoice{\QEQ}{\QEQ}{\scriptsize\QEQ}{\tiny\QEQ}%
}}
\def\QEQ{{%
\setbox0\hbox{\textbullet}%
\rlap{\hbox to \wd0{\hss$\uparrow$\hss}}\box0
}}

\begin{document}

$\qeq$ \textbullet \, \textbullet \, \textbullet

\end{document}