8

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

5

Why reinvent the wheel. Use modiagram.

\documentclass{article}
\usepackage{modiagram}
\begin{document}

\begin{MOdiagram}[style=square]
  \AO{s}[label={2s}]{0}
  \AO(30pt){p}[label[y]={2p}]{0;up,up,up}
\end{MOdiagram}

\end{document}

enter image description here

or without style=square

enter image description here

  • is possible obtain p-boxes and d-boxes glued together? – Edson Marcon Jun 1 '17 at 14:53
  • @EdsonMarcon Actually no, which is quite surprising. The distance between the boxes is hardcoded in modiagram.sty. – Henri Menke Jun 15 '17 at 7:32
2

Here's an adaptation of my answer to accommodate both styles (box or underline):

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

\ExplSyntaxOn
\NewDocumentCommand{\electron}{smm}
 { % #2 = level, #3 = electron schemes
  \IfBooleanTF{#1}
   { \jm_electron:Nnn \underline { #2 } { #3 } }
   { \jm_electron:Nnn \fbox { #2 } { #3 } }
 }

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

\cs_new_protected:Nn \jm_electron:Nnn
 {
  \cs_set_eq:NN \__jm_electron_highlight:n #1
  \seq_clear:N \l__jm_electron_schemes_print_seq
  \seq_set_split:Nnn \l_jm_electron_schemes_seq { | } { #3 }
  \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 } { #2 }
  \end{tabular}
  \group_end:
 }

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

\begin{document}

\electron{2s}{1,-1}\quad\electron{2p}{1,0 | 1,0 | 1,0}

\electron*{2s}{1,-1}\quad\electron*{2p}{1,0 | 1,0 | 1,0}

\end{document}

enter image description here

  • I made changes in your original code to obtain p-boxes and d-boxes glued together, but the corners isn't goods. \begin{tabular}{ * { \seq_count:N \l_jm_electron_schemes_seq } { |c }| } \hline \seq_use:Nn \l__jm_electron_schemes_print_seq { & } \\ \hline \multicolumn { \seq_count:N \l_jm_electron_schemes_seq } { c } { #1 } \end{tabular} – Edson Marcon Jun 1 '17 at 14:47
2

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

  • is possible obtain p-boxes and d-boxes glued together? – Edson Marcon Jun 1 '17 at 14:52
  • You mean like \electron{2s}{\updwn}\electron{2p}{\up\ \dwn\ \emp} or \electron{2s}{\updwn}\quad \electron{2p}{\up\dwn\emp}? – Troy Jun 1 '17 at 14:55
  • More like the second option, but with lines of the same thickness – Edson Marcon Jun 1 '17 at 15:33
  • @EdsonMarcon see update. – Troy Jun 1 '17 at 16:14
  • @EdsonMarcon If it answers your question, please consider accepting my answer by clicking the green tick next to the answer. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. – Troy Jun 2 '17 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.