4

I am trying to decorate a curve with some arrowheads, there is a way which you could specify the percentage position with steps

% !TEX TS-program = xelatex
\documentclass[UTF8]{article}

\usepackage{float}

\usepackage{amssymb}

\usepackage{tikz}
\usepackage{tkz-euclide}
\usetikzlibrary{arrows.meta}
\usetkzobj{all}
\usepackage{graphicx}

\begin{document}

\begin{figure}[H]
\begin{center}
\begin{tikzpicture}
\begin{scope}[smooth, decoration = {markings, mark = between positions 0.2 and 0.65 step 0.45 with {\arrow{Stealth[round, scale = 1.5]}}}]
\draw[postaction = {decorate}, dashed] plot coordinates{(0.7, 3) (4, 3) (5, 4)};
\end{scope}
\end{tikzpicture}
\end{center}
\end{figure}

\end{document}

I would like to be able use mark indices also, like below

 \draw plot[mark = x, mark indices = {1, 4, ..., 10, 11, 12, ..., 16, 20}, smooth]

However, it seems like mark indices would not recognize percentage position. Is there any way to let it accept such parameters?

Thanks in advance!

3

I may not understand your question but you can use the /.list key to put some decoration at some positions specified in a list. What I am unsure about is what to make of the numbers you show. I took them to specify the position in units in which the path has length 25, but you can change this, of course.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{arrows.meta,decorations.markings}
\begin{document}
\begin{tikzpicture}
\begin{scope}[smooth, decoration = {markings, mark = between positions 0.2 and 0.65 step 0.45 with {\arrow{Stealth[round, scale = 1.5]}}}]
\draw[postaction = {decorate}, dashed] plot coordinates{(0.7, 3) (4, 3) (5, 4)};
\end{scope}
\begin{scope}[yshift=-2cm,percentage mark/.style={ decoration = {markings, mark =
at position #1/25 with {\draw[solid] (-2pt,-2pt) -- (2pt,2pt)
(-2pt,2pt) -- (2pt,-2pt);}}}]
\draw[postaction = {decorate,percentage mark/.list={1, 4, ..., 10, 11, 12, ..., 16, 20}}, dashed] 
(0.7, 3) to[out=0,in=180] (4, 3) to[out=0,in=-120] (5, 4);
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

Note that I slightly changed the way to construct the path one you use throws dimension to large errors if you try to add some decoration at points at which the curvature is largish.

  • Your solution is fantastic! What I am trying to do is, the between function can only specify periodically appearing points, it would fail if the points were random. It would be nice if it could accept a random list as mark indices does. – zyy Oct 26 '18 at 13:42
  • @zyy Do you have a link to an example that shows how mark indices works? The pgfplots manual is very brief on this. I'd be particularly interested in the random list option. – marmot Oct 26 '18 at 14:25
  • At page 332 of the manual of version 3.0.1a. The example it has also decorated some periodic points, but the rest are randomly assigned. – zyy Oct 26 '18 at 14:40
  • I am wondering how I could use smooth instead of specifying the in and out angles with your solution. – zyy Oct 26 '18 at 14:43
  • 1
    @marmot The mark indice is a function of the sample size. Each point in the sample is indexed. The first point is indexed 1. The latter is indexed by sample size. For example: when the sample is 25 points, the first point of the sample has an indice equal to 1. The last point has an indice equal to 25. – AndréC Oct 27 '18 at 14:01

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.