%% example4_labels.tex
%% Copyright 2015 J. Schmidt
%% tikz-palattice LaTeX package
% 
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
% 
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is J. Schmidt.
% 
% This work consists of the files tikz-palattice.sty and tikz-palattice_documentation.tex
% and the 5 example files example1_linear.tex, example2_circular.tex,
% example3_coordinates.tex, example4_labels.tex and elsa.tex

\documentclass[]{standalone}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{tikz-palattice}


\begin{document}
\begin{lattice}[0.5]
\drawrule{(-9,-11)}[5][3][0.2]

\northlabels % labels "inside" ring
\setlabeldistance{0.5}
\rotate{-35}
\marker{start}[0.5]

\drift{0.03415}
\quadrupole{QD1}{0.4997}
\drift{0.19515}
\kicker{KV01}{0.1}
\drift{1.79875}
\quadrupole{SQ1}{0.45}[0.2]
\drift{1.01375}
\quadrupole{LQ1}{0.45}[0.2]
\drift{0.2065}
\sextupole{SX1}{0.287}
\drift{0.13665}
\quadrupole{QF2}{0.4997}
\drift{1.05365}
\kicker{KV02}{0.1}
\drift{0.3077}
\dipole{M2}{2.875}{15}
\drift{0.30145}
\quadrupole{QD3}{0.4997}
\drift{0.13665}
\sextupole{SD3}{0.287}
\drift{0.4305}
\kicker{KV03}{0.1}
\drift{1.84183}
\drift{1.84183}

% labels rotated (with manually set anchor)
\rotatelabels{65}[west]
\quadrupole{QF4}{0.4997}
\drift{0.13665}
\sextupole{SF4}{0.287}
\drift{0.214}
\kicker{KV04}{0.1}
\drift{0.7237}
\rotatelabels{0}

\dipole{M4}{2.875}{15}
\drift{0.30145}
\quadrupole{QD5}{0.4997}
\drift{0.09715}

% labels with changed fontsize
\setlabelfont{\tiny}
\kicker{KV05}{0.1}
\setlabelfont{\normalsize}

\drift{1.2642}
\dipole{M5}{2.875}{15}
\drift{0.30145}
\quadrupole{QF6}{0.4997}
\drift{0.94465}
\kicker{KV06}{0.1}
\drift{0.4167}
\dipole{M6}{2.875}{15}
\drift{0.30145}

%labels rotated (with manually set anchor) within scope (forget changes after scope)
\begin{scope}
\rotatelabels{-65}[east]
\quadrupole{QD7}{0.4997}
\drift{0.19415}
\kicker{KV07}{0.1}
\end{scope}


\drift{1.1672}
\dipole{M7}{2.875}{15}
\drift{0.30145}
\quadrupole{QF8}{0.4997}
\drift{1.02365}
\kicker{KV08}{0.1}
\drift{0.3377}
\dipole{M8}{2.875}{15}
\drift{0.30145}
\quadrupole{QD9}{0.4997}
\drift{0.30135}
\dipole{M9}{2.875}{15}
\drift{0.3208}
\kicker{KV09}{0.1}
\drift{1.04065}
\quadrupole{QF10}{0.4997}
\drift{0.30135}
\dipole{M10}{2.875}{15}
\drift{0.7203}
\kicker{KV10}{0.1}
\drift{0.2175}
\sextupole{SD10}{0.287}
\drift{0.13665}
\quadrupole{QD11}{0.4997}
\drift{0.30135}
\dipole{M11}{2.875}{15}
\drift{0.7208}
\kicker{KV11}{0.1}
\drift{0.217}
\sextupole{SF11}{0.287}
\drift{0.13665}
\quadrupole{QF12}{0.4997}
\drift{0.30135}
\dipole{M12}{2.875}{15}
\drift{1.1743}
\kicker{KV12}{0.1}
\drift{0.18715}
\quadrupole{QD13}{0.4997}
\drift{0.30135}
\dipole{M13}{2.875}{15}
\drift{0.7398}
\kicker{KV13}{0.1}
\drift{0.62165}
\quadrupole{QF14}{0.4997}
\savecoordinate{rechts}
\drift{1.86133}
\drift{1.86133}
\kicker{KV14}{0.1}
\drift{0.81515}
\quadrupole{QD15}{0.4997}
\drift{0.30135}
\dipole{M15}{2.875}{15}
\drift{0.9368}
\kicker{KV15}{0.1}
\drift{0.42465}
\quadrupole{QF16}{0.4997}
\drift{0.13665}
\sextupole{SX16}{0.287}
\drift{0.2065}
\quadrupole{LQ16}{0.45}[0.2]
\drift{0.3075}
\cavity{PETRA1}{1.6}
\drift{0.93725}
\quadrupole{TJQD16}{0.5515}[0.2]
\drift{0.1614}

% turn labels to other side and back
\turnlabels
\quadrupole{QD17}{0.4997}
\turnlabels

\drift{0.10615}
\kicker{KV17}{0.1}
\drift{0.244}
\cavity{PETRA2}{1.6}
\drift{1.43175}
\drift{0.07575}
\quadrupole{LQ17}{0.45}[0.2]
\drift{0.2065}
\sextupole{SX17}{0.287}
\drift{0.13665}
\quadrupole{QF18}{0.4997}
\drift{0.41665}
\kicker{KV18}{0.1}
\drift{0.9447}
\dipole{M18}{2.875}{15}
\drift{0.30145}

%labels rotated (with manually set anchor) within scope (forget changes after scope)
\begin{scope}
\rotatelabels{65}[east]
\quadrupole{QD19}{0.4997}
\drift{0.13665}
\sextupole{SD19}{0.287}
\drift{0.1965}
\kicker{KV19}{0.1}
\end{scope}

\drift{1.747}
\drift{1.747}
\sextupole{SF19}{0.287}
\drift{0.13665}

% turn labels to other side within scope (no second \turnlabels needed)
\begin{scope}
\turnlabels
\quadrupole{QF20}{0.4997}
\end{scope}

\drift{0.22565}
\kicker{KV20}{0.1}

\drift{1.1357}
\dipole{M20}{2.875}{15}
\drift{0.30145}

%labels in other distance to elements
\begin{labeldistance}{0.8}
  \quadrupole{QD21}{0.4997}
\end{labeldistance} %back to previous label distance (same as \setlabeldistance within scope)

\drift{0.21015}
\kicker{KV21}{0.1}
\drift{1.151}
\dipole{M21}{2.875}{15}
\drift{0.30165}
\quadrupole{QF22}{0.4997}
\drift{0.99865}
\kicker{KV22}{0.1}
\drift{0.363}
\dipole{M22}{2.875}{15}
\drift{0.30115}
\quadrupole{QD23}{0.4997}
\drift{1.46115}
\dipole{M23}{2.875}{15}
\drift{0.30165}
\quadrupole{QF24}{0.4997}
\drift{0.99265}
\kicker{KV24}{0.1}
\drift{0.369}
\dipole{M24}{2.875}{15}
\drift{0.30115}
\quadrupole{QD25}{0.4997}
\drift{0.30115}
\dipole{M25}{2.875}{15}
\drift{0.716}
\kicker{KV25}{0.1}
\drift{0.64565}
\quadrupole{QF26}{0.4997}
\drift{0.30165}
\dipole{M26}{2.875}{15}
\drift{0.723}
\kicker{KV26}{0.1}
\drift{0.214}
\sextupole{SD26}{0.287}
\drift{0.13715}
\quadrupole{QD27}{0.4997}
\drift{0.30115}
\dipole{M27}{2.875}{15}
\drift{0.728}
\kicker{KV27}{0.1}
\drift{0.21}
\sextupole{SF27}{0.287}
\drift{0.13665}
\quadrupole{QF28}{0.4997}
\drift{0.30165}
\dipole{M28}{2.875}{15}
\drift{1.168}
\kicker{KV28}{0.1}
\drift{0.19315}
\quadrupole{QD29}{0.4997}
\drift{0.30115}
\dipole{M29}{2.875}{15}
\savecoordinate{links}
\drift{0.318}
\kicker{KV29}{0.1}
\drift{1.04365}
\quadrupole{QF30}{0.4997}
\drift{1.56882}
\drift{1.56882}
\kicker{KV30}{0.1}
\drift{1.40015}
\quadrupole{QD31}{0.4997}
\drift{0.30115}
\dipole{M31}{2.875}{15}
\drift{0.307}
\kicker{KV31}{0.1}
\drift{1.05465}
\quadrupole{QF32}{0.4997}
\drift{0.13665}
\sextupole{SX32}{0.287}
\drift{0.2069}
\quadrupole{LQ32}{0.45}[0.2]
\drift{0.5031}
\kicker{KV32}{0.1}
\drift{0.41025}
\quadrupole{SQ32}{0.45}
\drift{1.382}
\quadrupole{TJQ32}{0.5515}[0.2]
\drift{0.12625}

% legend shows all element types occuring before this commmand
\legend{(35,38)}[2]

%title - aligned between M29 and QF14 via \savecoordinate
\draw[draw=none] (links) -- (rechts) node[midway, font=\bfseries\Huge,scale=2, align=center]
{ELSA Stretcherring\\{\SIrange[range-units=single,detect-weight=true]{0.5}{3.2}{\GeV}}};
\end{lattice}
\end{document}
