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?
Asked
Active
Viewed 3,376 times
8
-
1Welcome to TeX.SX! Do you mean something like in this picture (click)? – egreg May 31 '17 at 13:48
3 Answers
8
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}
or without style=square
Henri Menke
- 109,596
-
-
@EdsonMarcon Actually no, which is quite surprising. The distance between the boxes is hardcoded in
modiagram.sty. – Henri Menke Jun 15 '17 at 07:32
4
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}
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}
Troy
- 13,741
-
-
You mean like
\electron{2s}{\updwn}\electron{2p}{\up\ \dwn\ \emp}or\electron{2s}{\updwn}\quad \electron{2p}{\up\dwn\emp}? – Troy Jun 01 '17 at 14:55 -
-
-
@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 02 '17 at 06:10
4
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}
egreg
- 1,121,712
-
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} – CrocoDuck Jun 01 '17 at 14:47




