# How could a resonance energy levels diagram be made using TikZ?

How could an energy levels diagram like the following be made using TikZ?

I have seen some energy level diagram examples (such as this) but I am not sure how to make one that features an axis.

• If only the missing piece is axis, then it's easy. But do you have the rest of the image? Can you include your code? Jul 14, 2014 at 15:38
• This is an existing diagram which I am trying to reproduce using TikZ. I am inclined towards a 'functional' approach, in which resonance masses can be specified and then their corresponding horizontal lines position themselves appropriately with respect to the vertical axis. I could use a typical TikZ nodes coordinate system, but I think it would be inefficient and unintuitive. It would be better to be able to specify the mass and have it position accordingly.
– d3pd
Jul 14, 2014 at 15:53
• The axis and legend would be more easily generated using pgfplots, as would the coordinate calculation. OTOH, it's another manual to have to read. Jul 14, 2014 at 22:22

I did something like that for a personal notes,

The code is the following

\begin{center}
\begin{tikzpicture}[thick,line cap=round,yscale=2,
% Styles
axes/.style=,
important line/.style={very thick},
information text/.style={rounded corners,draw=blue!80!black,fill=blue!10,inner sep=1ex}]
\pgfkeys{/pgf/number format/.cd,fixed,precision=2}

\pgfmathsetmacro{\r}{.7}
\pgfmathsetmacro{\R}{.5}

\draw[help lines, color=blue!20,step=1cm] (-.4,-.4) grid (12.3,8.3);

%\draw (0,0) node[anchor=east] {$m_{\text{eff}} =0$} -- (2,0);
\foreach \n in {0,1,2,3}  {
\foreach \m in {0,1,...,3} {
\draw[important line,xshift=3*\n cm] (0,{sqrt((\m/\r)^2 + (\n/\R)^2)}) node[anchor=east] {$m_{\text{eff}} = \pgfmathparse{sqrt((\m/\r)^2 + (\n/\R)^2) }\pgfmathprintnumber{\pgfmathresult}$} -- (2,{sqrt((\m/\r)^2 + (\n/\R)^2)});
}
\draw [decorate,decoration={brace,amplitude=10pt,mirror},ultra thick,color=blue,yshift=-4pt,xshift=3*\n cm] (0,0) -- (2,0) node [black,midway,yshift=-0.6cm] { $n=\n$};
}

\end{tikzpicture}
\end{center}


For this sort of free-format chart, Metapost is often a good fit, because it's all just labels and lines.

The key thing is to establish sensible horizontal and vertical units. You could consider writing a little function to do the labels and lines, but since there are not many and you might need flexibility about where the labels go, it's probably not worth it.

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);

v = 0.2; % vertical unit 0.2bp = 0.567mm
u = 1cm; % horizontal unit

drawoptions(withcolor .78 red);
xpos := 2u;
draw (left -- right) scaled 1/2u shifted (xpos,+680v); label.top(btex $\Upsilon(4S)$ etex,(xpos,+680v)) withcolor black;
draw (left -- right) scaled 1/2u shifted (xpos,+450v); label.top(btex $\Upsilon(3S)$ etex,(xpos,+450v)) withcolor black;
draw (left -- right) scaled 1/2u shifted (xpos,+120v); label.top(btex $\Upsilon(2S)$ etex,(xpos,+120v)) withcolor black;
draw (left -- right) scaled 1/2u shifted (xpos,-440v); label.top(btex $\Upsilon(1S)$ etex,(xpos,-440v)) withcolor black;
% etc
drawoptions(dashed withdots scaled .5 withcolor .67 blue);
xpos := xpos + 2u;
draw (left -- right) scaled 1/2u shifted (xpos,250v); label.top(btex $\psi(3770)$ etex,(xpos,250v)) withcolor black;
draw (left -- right) scaled 1/2u shifted (xpos,170v); label.top(btex $\psi(2S)$   etex,(xpos,170v)) withcolor black;
draw (left -- right) scaled 1/2u shifted (xpos,105v); label.bot(btex $\eta_k(2S)$ etex,(xpos,105v)) withcolor black;
% etc, etc for the other markers
drawoptions();

draw (1u,-600v) -- (1u,-610v) -- (5u,-610v) -- (5u,-600v) withcolor .62 green;
label.bot(btex $S$ states etex, (3u,-610v));

% axis marker
drawoptions(withcolor .4 white);
draw (0,-580v) -- (0,780v);
for i=-500v step 100v until 700v+epsilon: draw (-1/5u,i)--(0,i); endfor
drawoptions();

label.lft(btex $-500$ etex, (-1/5u,-500v));
label.lft(btex $+500$ etex, (-1/5u,+500v));
label.lft(btex $0$    etex, (-1/5u,0));
label.lft(btex MeV etex, (-1/5u,800v));

endfig;
end.