1

I am trying to draw a rather simple tikz picture that consists of some very acurately defined levels. My code is

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{plotmarks}

\newlength{\offset}
\setlength{\offset}{4.72983cm}

\begin{document}
        \begin{tikzpicture}[y=1cm]
                %axis
                        \draw (-3,0) -- coordinate (y axis mid) (-3,20);
                %ticks
                        \foreach \y in {0,2,...,20}
                            \draw (-3,\y) -- (-3.25,\y) 
                            node[anchor=east] {\y};
                %labels      
                        \node[rotate=90, above=0.8cm] at (y axis mid) {\textbf{Energy[MeV]}};
                %input channel
                        \draw (-2,12.8435) -- (0,12.8435);
                        \node[above=0.2cm] at (-1,12.8435) {$p+{}^{19}F$};
                %compound nucleus
                        \draw[very thick] (2,20) -- (2,0) -- (5,0) -- (5,20);
                        \node[below=0.1cm] at (3.5,0) {${}^{20}Ne$};
                %output channel
                        \draw (7,\offset) -- (9,4.72983);%ground state
                        \draw (7,5.98765+\offset) -- (9,5.98765+4.72983);%1st state
        \end{tikzpicture}
\end{document}

As you can see I have set a length called offset. The problem is that at the present point the picture is rather big. What I want is to scale it only on y axis. If I change \begin{tikzpicture}[y=1cm] to \begin{tikzpicture}[y=.6cm] I get the ideal y dimension but the levels on the output channel are not set correctly.

Is there a way to define a length in tikz that will adapt tikz's lengths? What I mean is that by default tikz's length is 1cm. When using \draw (0,0) -- (0,1); one does not specify that he's talking about cm. If the global length is changed(i.e. `[y=0.6]) the previous line will have 0.6 cm length. Is something like that possible?

3

Remarks

Use a macro to store the pure value, such that tikz can scale it using it's own units.

Implementation

\documentclass[tikz]{standalone}
\usetikzlibrary{plotmarks}
\newcommand{\offset}{4.72983}
\begin{document}
\begin{tikzpicture}[y=0.2cm]
    %axis
    \draw (-3,0) -- coordinate (y axis mid) (-3,20);
    %ticks
    \foreach \y in {0,2,...,20}
    \draw (-3,\y) -- (-3.25,\y) 
    node[anchor=east] {\y};
    %labels      
    \node[rotate=90, above=0.8cm] at (y axis mid) {\textbf{Energy[MeV]}};
    %input channel
    \draw (-2,12.8435) -- (0,12.8435);
    \node[above=0.2cm] at (-1,12.8435) {$p+{}^{19}F$};
    %compound nucleus
    \draw[very thick] (2,20) -- (2,0) -- (5,0) -- (5,20);
    \node[below=0.1cm] at (3.5,0) {${}^{20}Ne$};
    %output channel
    \draw (7,\offset) -- (9,4.72983);%ground state
    \draw (7,5.98765+\offset) -- (9,5.98765+4.72983);%1st state
\end{tikzpicture}
\end{document}

Output

enter image description here

  • Thank you very much for your answer! That was an interesting approach! Very clever! Thank's!!! – Thanos Dec 29 '13 at 13:05

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.