如何在此代码中使用循环来定义点和标签
\foreach \x in {1.5,3,...,6}
平均能量损失
\documentclass[border=2pt]{standalone}
\usepackage[usenames,dvipsnames,svgnames]{xcolor}
\usepackage{tikz-dimline}
\usepackage{tkz-euclide}
\usetkzobj{all}
\definecolor{fondpaille}{cmyk}{0,0,0.1,0}
\pagecolor{fondpaille}
\color{Maroon}
%
\begin{document}
\begin{tikzpicture}[scale=1.0]
\tkzDefPoint(0,0){A}
\tkzDefPoint(8,0){B}
\tkzDefShiftPoint[A](0:1.5){A_1}
\tkzDefShiftPoint[A](0:3){A_2}
\tkzDefShiftPoint[A](0:4.5){A_3}
\tkzDefShiftPoint[A](0:6){A_4}
\tkzCompass[color=red,delta=15](A,A_1)
\tkzCompass[color=red,delta=15](A_1,A_2)
\tkzCompass[color=red,delta=15](A_2,A_3)
\tkzCompass[color=red,delta=15](A_3,A_4)
\tkzDrawSegment[thick,brown](A,B)
\tkzDrawPoints(A,B)
\tkzLabelPoints[below](A,B)
\end{tikzpicture}
\end{document}
答案1
喜欢这个吗?我将delta
选项改为length
,因为我用它A
作为罗盘标记的中心。
\documentclass[border=2pt]{standalone}
\usepackage[usenames,dvipsnames,svgnames]{xcolor}
\usepackage{tikz-dimline}
\usepackage{tkz-euclide}
\usetkzobj{all}
\definecolor{fondpaille}{cmyk}{0,0,0.1,0}
\pagecolor{fondpaille}
\color{Maroon}
%
\begin{document}
\begin{tikzpicture}[scale=1.0]
\tkzDefPoint(0,0){A}
\tkzDefPoint(8,0){B}
\foreach \x in {1,2,...,4}{%
\tkzDefShiftPoint[A](0:\x*1.5){A_\x}
\tkzCompass[color=red,length=.5](A,A_\x)
}
\tkzDrawSegment[thick,brown](A,B)
\tkzDrawPoints(A,B)
\tkzLabelPoints[below](A,B)
\end{tikzpicture}
\end{document}
编辑
要将前一点保留为罗盘标记的中心,您必须定义A_0
。
\begin{document}
\begin{tikzpicture}[scale=1.0]
\tkzDefPoint(0,0){A}
\tkzDefPoint(0,0){A_0}
\tkzDefPoint(8,0){B}
\foreach \i [evaluate=\i as \iMoinsUn using int(\i-1)] in {1,2,...,4}{%
\tkzDefShiftPoint[A](0:\i*1.5){A_\i}
\tkzCompass[color=red,delta=5](A_\iMoinsUn,A_\i)
}
\tkzDrawSegment[thick,brown](A,B)
\tkzDrawPoints(A,B)
\tkzLabelPoints[below](A,B)
\end{tikzpicture}
\end{document}