我正在嘗試繪製一個相當簡單的 tikz 圖片,其中包含一些非常準確的定義等級。我的程式碼是
\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}
正如你所看到的,我設定了一個名為 的長度offset
。問題是目前的情況相當大。我想要的只是將其縮放到y axis
.如果我更改\begin{tikzpicture}[y=1cm]
為,\begin{tikzpicture}[y=.6cm]
我會得到理想的y
尺寸,但等級設定output channel
不正確。
有沒有辦法定義一個長度來tikz
適應 tikz 的長度?我的意思是預設情況下 tikz 的長度是1cm
.使用\draw (0,0) -- (0,1);
one 時,沒有指定他正在談論 cm。如果更改全域長度(即“[y=0.6]”),則前一行的長度將為 0.6 公分。這樣的事情可能嗎?
答案1
評論
使用巨集來儲存純值,以便tikz
可以使用它自己的單位對其進行縮放。
執行
\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}