# Electron Configuration Diagram

I have seen some other postings about related electron configurations, but nothing that matched what I was looking for. I am pretty comfortable with a lot of LaTeX, except when it comes to stuff like using TikZ which I'm sure is what I'm needing here.

I'm wanting to create the following image:

I do not always need to create both the "2s" and "2p" sections at the same time. Ideally wrapping it in a function since I will be needing to create many of these images.

\electron{2s}{1}{{1,-1}}


This would be the {label}{number of lines}{{array of electrons}} - where in the array (which I'm not sure how easy that is to implement), I can provide the arrows needed. 1 is an up arrow, 0 is no arrow, -1 is a down arrow (just as an example).

The 2p would be drawn as:

\electron{2p}{3}{{1,0},{1,0},{1,0}}


Then I could string them together if wanted, defining the space between them:

\electron{}{}{}$\qquad$\electron{}{}{}


Or something like that

Since I don't know the actual TikZ to use, I thought I'd at least provide pseudocode/markup to show what I would think would happen:

\newcommand{\electron}[3]{
\newcounter{lines}
\forloop{lines}{0}{\value{lines} < #2}{
draw line
if array[\value{lines}][0] = -1; draw down line %first entry
if array[\value{lines}][0] = 1; draw up line %first entry
if array[\value{lines}][1] = -1; draw down line %second entry
if array[\value{lines}][1] = 1; draw up line %second entry
}
%place text of #1 cenetered under created lines
}

• Have you looked at the "MOdiagram" package? Nov 22, 2016 at 21:39
• Yes, an MO diagram is different than this
– J M
Nov 23, 2016 at 0:29

I don't think you need TikZ for this. Here is an implementation using just tabulars and underlines:

\documentclass{standalone}
\usepackage{amssymb} % for harpoons
\newcommand{\electron}[2]{{%
\def\+{\underline{\upharpoonleft}}%
\def\-{\underline{\downharpoonright}}%
\def\0{\underline{\phantom{\downharpoonright}}}%
\setlength\tabcolsep{0pt}% remove extra horizontal space from tabular
\begin{tabular}{c}$#2$\\[2pt]#1\end{tabular}%
}}
\begin{document}
\end{document}


If you want the command to work in math mode instead of text mode just remove the dollar signs from the definition of \electron, replace tabular with array, and replace \tabcolsep with \arraycolsep.

You could probably even arrange to use just +, - and 0 in place of \+, \-, and \0, but that's more complicated.

• Your code as it stands will break any discretionary hyphenation declared by \-. You must put an additional grouping in the definition of \electron. Nov 23, 2016 at 16:04
• @campa would I just wrap a \begingroup \endgroup around the definition \-? So \begingroup \def\-......\endgroup?
– J M
Nov 23, 2016 at 20:30
• @campa Thanks for pointing that out! I had assumed the new definition would be local to the command.
– Emma
Nov 24, 2016 at 2:04
• @JM It should suffice to add an extra set of curly braces around the contents of the \newcommand; I have changed the solution above to reflect this.
– Emma
Nov 24, 2016 at 2:05

I realize an answer has been accepted but here is a very simple example using the modiagrampackage, no need for anything new. I posted it as an answer as I couldn't figure out how to put code in a comment! I'll read up on that later.

JM says an MO is different to what is requested in my previous comment but an MO is made from AOs so if we leave out the MO part we have the necessary pieces. The distance between the AOs can be adjusted, see the modiagram user manual section 4.1.2.

\documentclass{standalone}
\usepackage{modiagram}
\begin{document}
\begin{MOdiagram}[names]
\atom[2s]{left}{2s={0;pair}} \atom[2p]{right}{2p={0;up,up,up}}
\end{MOdiagram}
\end{document}


gives the following:

• Ah, thank you for this! I did not dive into the modiagram package, I just saw the examples used in various places on here, and it was always for create an entire MO diagram. This is good to know, however, I'll still go with the other solution as it centers the text, and my students are familiar with the arrows being drawn entirely above the line (it is notoriously easy to throw them off by drawing things different than what they've seen!)
– J M
Nov 23, 2016 at 20:27
• No worries! Always good to have more than one way to do a thing. I learned something too! Nov 23, 2016 at 20:40

The difficult part is splitting the input in a good way:

\documentclass{article}
\usepackage{amssymb}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\electron}{mm}
{ % #1 = level, #2 = electron schemes
\jm_electron:nn { #1 } { #2 }
}

\seq_new:N \l_jm_electron_schemes_seq
\seq_new:N \l__jm_electron_schemes_print_seq

\cs_new_protected:Nn \jm_electron:nn
{
\seq_clear:N \l__jm_electron_schemes_print_seq
\seq_set_split:Nnn \l_jm_electron_schemes_seq { | } { #2 }
\seq_map_function:NN \l_jm_electron_schemes_seq \__jm_electron_do_scheme:n
% print the schemes
\group_begin:
\setlength{\tabcolsep}{.2em}
\begin{tabular}{ * { \seq_count:N \l_jm_electron_schemes_seq } { c } }
\seq_use:Nn \l__jm_electron_schemes_print_seq { & } \\
\multicolumn { \seq_count:N \l_jm_electron_schemes_seq } { c } { #1 }
\end{tabular}
\group_end:
}

\cs_new_protected:Nn \__jm_electron_do_scheme:n
{
\seq_put_right:Nn \l__jm_electron_schemes_print_seq
{
\underline
{
\clist_map_inline:nn { #1 }
{
\int_case:nn { ##1 }
{
{1}{$\scriptstyle\upharpoonleft$}
{0}{\phantom{$\scriptstyle\upharpoonleft$}}
{-1}{$\scriptstyle\downharpoonright$}
}
}
}
}
}
\ExplSyntaxOff

\begin{document}

\end{document}


The second argument is split at |; then each item makes a couple of arrows depending on them being denoted by 1, 0 or -1.

A tabular with the appropriate number of columns is built, where the contents of each cell has been built with the arrows and an underline.

• Your solution throws an error when used as one of the choices in the nmpchoice environment\answer you gave here: tex.stackexchange.com/questions/329085/… The three definitions for 1,0, and -1 with the scriptstyle throw an undefined control sequence error. I don't know how to decide between your answer and the one above as the "correct answer". Both seem to give the desired result
– J M
Nov 23, 2016 at 0:53
• @JM You probably missed \usepackage{amssymb}. Nov 23, 2016 at 7:19
• That was indeed it. Thank you always so much for your helpfulness egreg! It looks like for whatever reason, the other solution makes larger text/arrows than this. The larger look fits better for what I am needing (though I like the 1, -1, 0 better in this one more)
– J M
Nov 23, 2016 at 10:05
• @JM I believe the smaller arrows in this version are just due to the \scriptstyle in the cases.
– Emma
Nov 24, 2016 at 1:57