User Tools

Site Tools


latex:tikz

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
latex:tikz [2022/07/20 11:54] – [How to draw diagrams in LaTeX with TikZ] iwnlatex:tikz [2022/12/02 15:42] (current) – [For-loops: Pseudorapidity 𝜂 and polar angle 𝜃] iwn
Line 389: Line 389:
 </WRAP></WRAP> </WRAP></WRAP>
  
 +Using a for-loop over two variables:
 +<WRAP group><WRAP half column lo 65%>
 +<code latex>
 +\begin{tikzpicture}[scale=3]
 +  
 +  % limits
 +  \def\R{1.2} % radius/length of lines
 +  
 +  % axis labels
 +  \node[scale=1,below left=1] at (0,\R) {$y$}; % y axis
 +  \node[scale=1,below left=1] at (\R,0) {$z$}; % z axis
 +  
 +  % lines
 +  \foreach \t/\e in {90/0,60/0.55,45/0.88,30/1.32,10/2.43,0/+\infty}{ % loop over theta/eta
 +    \pgfkeys{/pgf/number format/precision=2}
 +    \draw[->,black!60!red,thick,line cap=round] % eta lines
 +      (0,0) -- (\t:\R) node[anchor=180+\t,black] {$\eta=\e$}
 +      node[black,pos=0.7,fill=white,scale=0.8,inner sep=1.5pt] {$\theta=\t^\circ$};
 +  }
 +  
 +\end{tikzpicture}
 +</code>
 +</WRAP><WRAP half column 30%>
 +\\
 +{{ latex:tikz:axis2d_pseudorapidity.png ? 2000 }}
 +\\
 +</WRAP></WRAP>
  
 +Using for-loop and calculation + rounding:
 <WRAP group><WRAP half column lo 65%> <WRAP group><WRAP half column lo 65%>
 <code latex> <code latex>
Line 395: Line 423:
      
   % limits   % limits
-  \def\R{1.2}+  \def\R{1.2} % radius/length of lines
      
   % axis labels   % axis labels
-  \node[scale=0.9,below=5pt,left=2pt] at (0,\R) {$y$}; +  \node[scale=1,below left=1] at (0,\R) {$y$}; % y axis 
-  \node[scale=0.9,left=5pt,below=2pt] at (\R,0) {$z$};+  \node[scale=1,below left=1] at (\R,0) {$z$}; % z axis
      
   % lines   % lines
-  \foreach \t/\e in {90/0,60/0.55,45/0.88,30/1.32,10/2.44,0/\infty}{ +  \pgfkeys{/pgf/number format/precision=2} % two decimals 
-    \draw[->,black!60!red,thick] +  \foreach \t in {90,60,45,30,10,0}{ % loop over theta 
-      (0,0) -- ({\R*cos(\t)},{\R*sin(\t)}) +    \ifnum \t = 0 
-      node[anchor=180+\t,black] {$\eta=\e$}; +      \def\e{+\infty} % infinity symbol 
-    \node[fill=white,scale=0.8] at ({0.8*cos(\t)},{0.8*sin(\t)}) {$\theta=\t^\circ$};+    \else 
 +      \pgfmathparse{-ln(tan(\t/2))} % pseudorapidity 
 +      %\pgfmathroundto{\pgfmathresult} % round without traling zeroes 
 +      \pgfmathroundtozerofill{\pgfmathresult} % round with trailing zeroes 
 +      \pgfmathsetmacro\e{\t==90?0:\pgfmathresult} % no trailing zeroes for theta = 0 
 +    \fi 
 +    \draw[->,black!60!red,thick,line cap=round% eta lines 
 +      (0,0) -- (\t:\R) node[anchor=180+\t,black] {$\eta=\e$} 
 +      node[black,pos=0.7,fill=white,scale=0.8,inner sep=1.5pt] {$\theta=\t^\circ$};
   }   }
-    +  
 \end{tikzpicture} \end{tikzpicture}
 </code> </code>
 </WRAP><WRAP half column 30%> </WRAP><WRAP half column 30%>
 \\ \\
-{{ latex:theta-eta.png ? 2000 }}+{{ latex:tikz:axis2d_pseudorapidity.png ? 2000 }}
 \\ \\
 </WRAP></WRAP> </WRAP></WRAP>
latex/tikz.1658310872.txt.gz · Last modified: 2022/07/20 11:54 by iwn