怎样才能画出这个图案呢?
我试过这个
\begin{tikzpicture}
\pgfmathsetmacro\gratio{(1+sqrt(5))/2}
\def\lenB{2}
\path (0,0) node[coordinate](start){} ++(\gratio*\lenB,0)node[coordinate](a){} -- ++(\lenB,0)node[coordinate](b){};
\draw (start) --node[above] {$a$} (a) --node[above]{$b$} (b);
\foreach \n in {start,a,b}\draw (\n) ++(0,-2pt) -- ++(0,4pt);
\end{tikzpicture}
答案1
有很多方法。下面是使用用户定义样式的方法,tick
其中包括刻度线下方的标签。
\documentclass{article}
\usepackage{tikz}
\tikzset{tick/.style={draw, minimum width=0pt, minimum height=2pt, inner sep=0pt, label=below:$#1$},
tick/.default={}}
\pgfmathsetmacro\gratio{(1+sqrt(5))/2}
\newcommand{\lenB}{2}
\begin{document}
\begin{tikzpicture}
\draw(0,0) node[tick=C_2]{} -- ++(\lenB*\gratio,0) node[tick=C_1]{}
(\lenB,0) node[tick=A]{} -- ++(\lenB*\gratio,0) node[tick=B]{};
\end{tikzpicture}
\end{document}
答案2
这看起来很像你的例子:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def\x{5}
\def\tick{0.05}
\draw (0,0) -- (\x,0);
\draw (0,\tick) -- ++(0,-2*\tick) node[below] {$C_2$};
\draw (0.37*\x,\tick) -- ++(0,-2*\tick) node[below] {$A$};
\draw (0.63*\x,\tick) -- ++(0,-2*\tick) node[below] {$C_1$};
\draw (\x,\tick) -- ++(0,-2*\tick) node[below] {$B$};
\end{tikzpicture}
\end{document}
答案3
@Sandy G 给出了一种node
方法。以下是使用 的替代方法pic
。
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro\gratio{(1+sqrt(5))/2}
\newcommand{\lenB}{2}
\tikzset{mytick/.pic={\draw[thick] (0,.08)--(0,-.08);}}
\draw
(0,0) pic[red]{mytick} node[below=1pt]{$C_2$} --
++(\lenB*\gratio,0) pic[magenta]{mytick} node[below=1pt]{$C_1$}--
(\lenB,0) pic[blue]{mytick} node[below=1pt]{$A$} -- ++(\lenB*\gratio,0) pic[orange]{mytick} node[below=1pt]{$B$};
\end{tikzpicture}
\end{document}