14

I tried to draw a path and a curve length marker. This is the desired result:

desired output

This would be easy if the curve was defined as a function, then I'd just set the domain, add some markers, done. But what about more complicated paths, such as bézier curves?

I have a solution, but this is somewhat hacky and hard-coded.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[scale=2]
\coordinate (P) at (2.5,2) {};
\coordinate (Q) at (2.5,3) {};
\draw[ postaction={decorate,decoration={markings, mark=at position 0.245 with {\arrow[scale=1.2, blue]{stealth}}, 
mark=at position 0.17 with {\draw[blue, -, thick] (0,-0.6mm) --    (0,0.6mm) node[below right] {$s=0$};}}}] (0,0) to [in=200, out=70] (P)    to[out=20, in=170] (5,1.5);

\begin{scope}
    \clip(0.5,0) rectangle (0.8, 1.6);
    \draw[thick, blue] 
    (0,0) to [in=200, out=70] (2.5,2) to[out=20, in=230] (5,1.5) ;
\end{scope}

\end{tikzpicture}
\end{document}

(The reason for not putting the markers inside the second curve is that if I did that, at least the left marker would be clipped, too)

As a first step, I'd like to remove the hard coded numbers from scope and decorations.

Any ideas how to improve that (ugly) bit of code?

As a bonus, it would be cool to have a node with "s" in the middle of the blue line.

1
  • 1
    Welcome to TeX.SX! Please help us (and also you) and add a minimal working example (MWE), that illustrates your problem. It will be much easier when we see compilable code, starting with \documentclass and ending with \end{document}.
    – Bobyandbob
    Sep 4, 2017 at 12:10

1 Answer 1

14

edit (2): in the first solution the definition of clip area doesn't work in all circumstances. with some small changes in provided code escape this limitation

see if the following code is close to what you looking for:

\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, calc, decorations.markings, quotes}

\begin{document}
\begin{tikzpicture}[auto=right, scale=2]
\newcommand\clipshape[1]{($(a)!#1!90:(b)$) -- ($(b)!#1!-90:(a)$) --
                         ($(b)!#1!90:(a)$) -- ($(a)!#1!-90:(b)$) -- cycle} % added
\coordinate (P) at (2.5,2) {};
\draw[ postaction={decorate,decoration={markings,
    mark=at position 0.17 with {\coordinate (a); % changed
                                \arrow[blue,thick]{Bar[width=1.2mm]}},
    mark=at position 0.24 with {\coordinate (b); % changed
                                \arrow[blue,thick,xshift=2\pgflinewidth]{Stealth}},
        }}]
    (0,0) to [in=200, out=70] (P)
          to [out=20, in=170] (5,1.5);

    \path (a) to [inner sep=1pt, "$s=0$"] (b); % changed
    \path[clip] \clipshape{2mm}; % changed
    \draw[thick, blue]
    (0,0) to [in=200, out=70] (P) to [out=20, in=170] (5,1.5);
\end{tikzpicture}
\end{document}

enter image description here

edit (1): to see effect of \clipshape, change it content to:

    \draw[thick, red, semitransparent]
    (0,0) to [in=200, out=70] (P) 
          to [out=20, in=170] (5,1.5) ;

enter image description here

now the position of node with s=0 is always adapted to slope of line.

3
  • Saving a coordinate inside a marker, nice!
    – jaytar
    Sep 4, 2017 at 12:52
  • But if you look really closely (especially when the arrow is near horizontal or near vertical), a significant part of the arrow is clipped too.
    – jaytar
    Sep 4, 2017 at 12:54
  • @jaytar, see edit of my answer
    – Zarko
    Sep 4, 2017 at 13:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .