[Tex/LaTex] Atomic electronic configuration with small boxes

boxeschemistry

I need to create a new command for the electronic distribution of an atom (orbitals S, P, D, F), similar to the one shown in the link below, but with boxes around the electron pairs.
Can someone help me please?

Electron Configuration Diagram

Best Answer

I adapted the solution from the attached link, to draw an \fbox instead of \underline. In addition, I had to add \mathord to make the \fbox-es across the definitions to have equal widths. (not sure if I did this right though)

\documentclass[border=2mm]{standalone}
\usepackage{amssymb} % for harpoons
\newcommand{\electron}[2]{{%
        \newcommand*\up{\fbox{$\mathord\upharpoonleft\phantom{\downharpoonright}$}}%
        \newcommand*\dwn{\fbox{$\mathord\downharpoonleft\phantom{\upharpoonright}$}}%
        \newcommand*\updwn{\fbox{$\upharpoonleft\downharpoonright$}}%
        \newcommand*\emp{\fbox{$\phantom{\downharpoonright}\phantom{\downharpoonright}$}}%
        \setlength\tabcolsep{0pt}% remove extra horizontal space from tabular
        \begin{tabular}{c}#2\\[2pt]#1\end{tabular}%
}}
\begin{document}
    \electron{2s}{\updwn}\quad \electron{2p}{\up\ \dwn\ \emp}
\end{document}

boxed

The commands:

  • \up: up spin electron only
  • \dwn: down spin electron only
  • \updwn: up and down spin electrons (filled)
  • \emp: no electrons (unfilled)

Edit:

Updated code for the boxes to be attached to each other, with equal line widths. Usage is still the same as above. The lines are thicker now because two fbox-es are being drawn. If you want to stick to the old fbox line width, uncomment the \setlength\fboxrule{0.2pt} line.

\documentclass[border=2mm]{standalone}
\usepackage{amssymb} % for harpoons
\newcommand*\up{\fbox{$\mathord\upharpoonleft\phantom{\downharpoonright}$}}%
\newcommand*\dwn{\fbox{$\mathord\downharpoonleft\phantom{\upharpoonright}$}}%
\newcommand*\updwn{\fbox{$\upharpoonleft\downharpoonright$}}%
\newcommand*\emp{\fbox{$\phantom{\downharpoonright}\phantom{\downharpoonright}$}}%
\newcommand{\electron}[2]{{%
        \setlength\tabcolsep{0pt}% remove extra horizontal space from tabular
%       \setlength\fboxrule{0.2pt}% uncomment for original line width
        \begin{tabular}{c}
            \fboxsep=0pt\fbox{\fboxsep=3pt#2}\\[2pt]
            #1
        \end{tabular}%
}}
\begin{document}
    \electron{2s}{\updwn}\quad \electron{2p}{\up\dwn\emp}
\end{document}

update box

Related Question