电子配电箱图

电子配电箱图

仅供分享,欢迎改进。

\starttext

Electron distribution box diagram

\startMPcode
picture finalpicture ; finalpicture := nullpicture ;
numeric n ; n := 0 ; bboxmargin := 0pt ;

vardef boxx(expr nu, orbitalname)= 
   draw unitsquare scaled 1cm;
   path p; p:= origin shifted(.333cm,.1cm) -- origin shifted (.333cm, .8cm);
   if nu<>0:
   drawarrow p; fi;
   if nu=2: drawarrow (reverse p ) shifted (.3cm,0); fi;
    label(textext(orbitalname) scaled .7, (.5cm,1.3cm));
   addto finalpicture also currentpicture shifted(n*1.1cm,0) ;
    currentpicture := nullpicture ; n := n+1 ;
    enddef;


 vardef box(expr nu, orbitalname)=  
     numeric N;
     if orbitalname ="2p": 
       if nu<=3:
       N:=nu-1; boxx(1, "2px"); boxx(min(N,1),"2py"); N := max(N-1,0); boxx(N,"2pz"); 
       elseif nu=6:
       boxx(2,"2px"); boxx(2,"2py"); boxx(2,"2pz");
       elseif nu=5:
        boxx(2,"2px"); boxx(2,"2py"); boxx(1,"2pz");      
       else:     
        boxx(2,"2px"); boxx(1,"2py"); boxx(1,"2pz"); 
       fi;  
      elseif orbitalname ="3p": 
       if nu<=3:
       N:=nu-1; boxx(1, "3px"); boxx(min(N,1),"3py"); N := max(N-1,0); boxx(N,"3pz"); 
       elseif nu=6:
       boxx(2,"3px"); boxx(2,"3py"); boxx(2,"3pz");
       elseif nu=5:
        boxx(2,"3px"); boxx(2,"3py"); boxx(1,"3pz");      
       else:     
        boxx(2,"3px"); boxx(1,"3py"); boxx(1,"3pz"); 
       fi;
       else: boxx(nu,orbitalname);
     fi; 
 enddef;
  box(2,"1s");
  box(2,"2s");
  box(6,"2p");    
  box(2,"3s");
  box(5,"3p");

 currentpicture := finalpicture ;

\stopMPcode

\stoptext

答案1

\documentclass{article}
\usepackage{pstricks}
\makeatletter
\def\EBox(#1,#2){%
  \ifx\relax#2\relax\def\UpDown{2}\else\def\UpDown{1}\fi
  \pspicture(0,1.5)%
  \rput(0.5,1.3){#1}%
  \psline{->}(0.3,0.1)(0.3,0.9)%
  \ifnum\UpDown=2\psline{->}(0.7,0.9)(0.7,0.1)\fi
  \psframe(1,1)%
  \endpspicture
  \@ifnextchar({\hspace{1.1cm}\EBox}{}}
\makeatother
\begin{document}

\EBox(1s,)(2s,)(2px,)(2py,)(2pz,)(3s,)(3px,)(3py,)(3pz,1)
\end{document}

在此处输入图片描述

无需加载包也一样:

\documentclass{article}
\makeatletter
\unitlength=1cm
\def\EBox(#1,#2){%
  \ifx\relax#2\relax\def\UpDown{2}\else\def\UpDown{1}\fi
  \picture(0,1.5)%
  \put(0.5,1.3){\makebox[0pt]{#1}}%
  \put(0.3,0.1){\vector(0,1){0.8}}%
  \ifnum\UpDown=2\put(0.7,0.9){\vector(0,-1){0.8}}\fi
  \put(0,0){\framebox(1,1)}%
  \endpicture
  \@ifnextchar({\hspace{1.1cm}\EBox}{}}
\makeatother
\begin{document}

\EBox(1s,)(2s,)(2px,)(2py,)(2pz,)(3s,)(3px,)(3py,)(3pz,1)
\end{document}

相关内容