1

How to use loop in this code to define points and labels

\foreach \x in {1.5,3,...,6}

MWE

\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}

enter image description here

1 Answer 1

2

Like this? I changed the delta option to length, since I use A as center for the compass marks.

\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}

Edit

To keep the previous point as center for the compass marks you have to define 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}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.