Box and arrow notation of writing electron configuration

chemistry

image
image source: https://opentextbc.ca/

I write the electron configurations like 1s2 2s2 2p6, but not able to draw the box and arrow notations.

$\mathrm{N} \quad 1 s^{2} 2 \mathrm{~s}^{2} 2 p^{3} \quad$
$\mathrm{O} \quad 1 s^{2} 2 \mathrm{~s}^{2} 2 p^{4} \quad$
$\mathrm{F} \quad 1 s^{2} 2 \mathrm{~s}^{2} 2 p^{5} \quad$
$\mathrm{Ne} \quad 1 s^{2} 2 \mathrm{~s}^{2} 2 p^{6} \quad$

I tried something like this using \fbox{} or \boxed{}

$\mathrm{N} \quad 1 s^{2} 2 \mathrm{~s}^{2} 2 p^{3} \quad$ $\boxed{\uparrow \downarrow} \boxed{\uparrow \downarrow} \boxed{\uparrow|\uparrow|\uparrow}$

$\mathrm{O} \quad 1 s^{2} 2 \mathrm{~s}^{2} 2 p^{4} \quad$ $\boxed{\uparrow \downarrow} \boxed{\uparrow \downarrow} \boxed{\uparrow \downarrow|\uparrow|\uparrow}$

$\mathrm{F} \quad 1 s^{2} 2 \mathrm{~s}^{2} 2 p^{5} \quad$ $\boxed{\uparrow \downarrow} \boxed{\uparrow \downarrow} \boxed{\uparrow \downarrow|\uparrow \downarrow|\uparrow}$

$\mathrm{Ne} \quad 1 s^{2} 2 \mathrm{~s}^{2} 2 p^{6} \quad$ $\boxed{\uparrow \downarrow} \boxed{\uparrow \downarrow} \boxed{\uparrow \downarrow|\uparrow \downarrow|\uparrow \downarrow}$

Best Answer

I have collected a few command definitions in a separate style file electrons.sty, see below. It essentially uses \upharpoonleft, \downharpoonright, \fboxes, and loops to iterate over shell specifications.

Then you can achieve what you want by

\documentclass{article}
\usepackage{array}% only needed for injecting commands at the beginning of columns in the tabular below
\usepackage{electrons}
\begin{document}
\sffamily
\begin{tabular}{l>{\TextShells}l>{\BoxedShells}l}
  N  & \subshells{{1s:2}{2s:2}{2p:111}} & \subshells{{1s:2}{2s:2}{2p:111}} \\
  O  & \subshells{{1s:2}{2s:2}{2p:211}} & \subshells{{1s:2}{2s:2}{2p:211}} \\
  F  & \subshells{{1s:2}{2s:2}{2p:221}} & \subshells{{1s:2}{2s:2}{2p:221}} \\
  Ne & \subshells{{1s:2}{2s:2}{2p:222}} & \subshells{{1s:2}{2s:2}{2p:222}} \\
\end{tabular}
\end{document}

enter image description here

Package electrons: Copy the following code into a file electrons.sty. For the documentation see below.

\RequirePackage{amssymb}

\newcommand\spinup{$\upharpoonleft$}
\newcommand\spindown{$\downharpoonright$}

% Looping over a list of tokens with separator
% \electronLoop{processor}{separator}{list}
\newcommand\electronLoop[3]{%
  \bgroup
  \def\electronLoopProcessor{#1}%
  \def\electronLoopSeparator{\def\electronLoopSeparator{#2}}%
  \electronLoopDo#3\relax
  \egroup
}
\newcommand\electronLoopDo[1]{%
  \ifx\relax#1\else
    \electronLoopSeparator
    \electronLoopProcessor{#1}%
    \expandafter
    \electronLoopDo
  \fi
}

% \orbital{#electrons: 0,1,2}
\newcommand\orbital[1]{%
  \fbox{%
    \ifcase#1
      \phantom\spinup\!\phantom\spindown
    \or
      \spinup\!\phantom\spindown
    \or
      \spinup\!\spindown
    \else
      \bfseries**\strut
    \fi
  }%
}

% \orbitals{list of #electrons}
\newcommand\orbitals[1]{\electronLoop\orbital{\hspace{-\fboxrule}}{#1}}

% \subshell{name:list of #electrons}
\newcommand\subshell[1]{%
  \subshellX#1\endOfShell
}
\newcommand\subshellX{}
\def\subshellX#1:#2\endOfShell{\doSubShell{#1}{#2}}

\newcommand\subshellBox[2]{%
  \begin{tabular}[t]{@{}c@{}}
    \orbitals{#2}\\[-2pt]
    \scriptsize#1%
  \end{tabular}%
}

\newcounter{electrons}
\newcommand\subshellText[2]{%
  \setcounter{electrons}{0}%
  \electronLoop{\addtocounter{electrons}}{}{#2}%
  #1$^\arabic{electrons}$%
}

% \subshells{list of shells}
\newcommand\subshells[1]{\electronLoop\subshell\SubShellSep{#1}}

\newcommand\BoxedShells{%
  \def\SubShellSep{ }%
  \let\doSubShell\subshellBox
}

\newcommand\TextShells{%
  \def\SubShellSep{}%
  \let\doSubShell\subshellText
}

\BoxedShells

enter image description here

\documentclass{article}
\usepackage{electrons}
\parindent0pt
\begin{document}

\title{The package \texttt{electrons}}
\author{gernot}
\date{2021}
\maketitle

\paragraph{Spins:} \verb"\spinup" gives \spinup, \verb"\spindown" gives
\spindown.

\paragraph{Single orbitals:}
\verb"\orbital{0} \orbital{1} \orbital{2}" gives \orbital{0}
\orbital{1} \orbital{2}.

\paragraph{Multiple orbitals:} \verb"\orbitals{012}" gives \orbitals{012}.

\bigskip
\verb"\BoxedShells" (the default) represents shells as boxes.

\paragraph{Subshell:} \verb"\subshell{2p:221}" gives \subshell{2p:221}.

\paragraph{Multiple subshells:}
\verb"\subshells{{1s:2}{2s:2}{2p:221}}" gives \subshells{{1s:2}{2s:2}{2p:221}}.

\bigskip
\verb"\TextShells" represents shells as text.
\TextShells

\paragraph{Subshell:} Now \verb"\subshell{2p:221}" results in \subshell{2p:221}.

\paragraph{Multiple subshells:} Now
\verb"\subshells{{1s:2}{2s:2}{2p:221}}" results in
\subshells{{1s:2}{2s:2}{2p:221}}.

\end{document}
Related Question