![如何给轴添加“点”?](https://linux22.com/image/284435/%E5%A6%82%E4%BD%95%E7%BB%99%E8%BD%B4%E6%B7%BB%E5%8A%A0%E2%80%9C%E7%82%B9%E2%80%9D%EF%BC%9F.png)
我想给轴添加任意长度,但我不知道如何做。
\documentclass[10pt,a4paper,french]{article}
\usepackage{tikz}
\pgfkeys{/tikz/.cd,
NbGrad/.store in=\NbGrad,
Noze/.store in=\Noze,
Noze=.5cm,
}
\begin{document}
\begin{tikzpicture}[%
>=stealth,x=6cm,font=\footnotesize,NbGrad=6]
\draw [->] (0,0)--(1+\Noze,0) ;
\foreach \x in {0,1,...,\NbGrad} {%
\coordinate (\x) at (\x/\NbGrad,0) ;
\draw [very thin] (\x/\NbGrad,+2pt)--(\x/\NbGrad,-2pt) ;
\pgfmathsetmacro\result{2 + \x / 10}
\node[above=1pt,text depth=1.5pt] at (\x)%
{\pgfmathprintnumber[precision=1,fixed,use comma]{\result}};
} ;
\end{tikzpicture}
\end{document}
答案1
您可以使用calc
库:
\documentclass[10pt,a4paper,french]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\pgfkeys{/tikz/.cd,
NbGrad/.store in=\NbGrad,
Noze/.store in=\Noze,
Noze=2.5cm,
}
\begin{document}
\begin{tikzpicture}[%
>=stealth,x=6cm,font=\footnotesize,NbGrad=6]
\draw [->] (0,0)--($(1,0) +(\Noze,0)$) ;
\foreach \x in {0,1,...,\NbGrad} {%
\coordinate (\x) at (\x/\NbGrad,0) ;
\draw [very thin] (\x/\NbGrad,+2pt)--(\x/\NbGrad,-2pt) ;
\pgfmathsetmacro\result{2 + \x / 10}
\node[above=1pt,text depth=1.5pt] at (\x)%
{\pgfmathprintnumber[precision=1,fixed,use comma]{\result}};
} ;
\end{tikzpicture}
\end{document}