1

I have a question on how to decorate a path with more than three arrows in TikZ, I was using the code

\documentclass{article}

\usepackage{float}

\usepackage{graphicx}

\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{positioning}
\usepackage{tkz-euclide}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[decoration = {markings, mark = at position 1 cm with {\arrow[red]{Stealth[round, scale = 1.5]}}, mark = at position .14 with {\arrow[green]{Stealth[round, scale = 1.5]}}, mark = at position 0.65 with {\arrow[blue]{Stealth[round, scale = 1.5]}}}, mark = at position .86 with {\arrow[green]{Stealth[round, scale = 1.5]}}]
\draw [{Stealth[round, scale = 1.5]}-] (4,0) node[anchor = north] {$x$} -- (-4,0);
\draw [{Stealth[round, scale = 1.5]}-] (0,4) node[anchor = west] {$\mathrm{i} y$} -- (0,-4);
\draw (-3,0.3) node[blue, anchor = east] {$C_R$};
\draw (-1,0.3) node[red, anchor = east] {$C_r$};
\draw (2,0.3) node[green, anchor = south] {$L_1$};
\draw (2,-0.3) node[green, anchor = north] {$L_2$};
\draw [postaction = {decorate}] (-10 mm,0) arc(180 : 5 : 10 mm) -- (29.981724810572872 mm, 1.046984901075029 mm) arc(2 : 358 : 30 mm) -- (9.961946980917455 mm, -0.871557427476582 mm) arc(355 : 180 : 10 mm);
\end{tikzpicture}
\end{figure}

\end{document}

The last arrow never shows up, please see following

tikzarrowdecoration

The part of the code that describes the last arrow decoration is mark=at position .86 with {\arrow[green]{Stealth[round,scale=1.5]}} in the \begin{tikzpicture}[decoration = ] part.

Thank you in advance.

  • @Zarko beat me to the answer. Some notes on style: Green is almost always too light coloured. Use something like green!70!black instead (adjust the 70 to taste). Also, using polar coordinates, you can replace (29.981724810572872mm,1.046984901075029mm) by (2:30mm) and (9.961946980917455mm,-0.871557427476582mm) by (-5:10mm). – Harald Hanche-Olsen Jan 3 '18 at 13:35
  • @HaraldHanche-Olsen Great advice, thanks! – zyy Jan 3 '18 at 15:35
3

you have mismatches in in curly braces in definition of decorated path. correct code is:

decoration={markings, 
        mark=at position 1cm with {\arrow[red]{Stealth[round,scale=1.5]}}, 
        mark=at position .14 with {\arrow[green]{Stealth[round,scale=1.5]}}, 
        mark=at position 0.65 with {\arrow[blue]{Stealth[round,scale=1.5]}}, % <--
        mark=at position .86 with {\arrow[green]{Stealth[round,scale=1.5]}}} % <--

enter image description here

edit:

a mwe which generate above image (reconstructed from your code and simplified to reasonable coordinate values):

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

\begin{document}
\begin{tikzpicture}[
decoration={markings,
        mark=at position  1cm with {\arrow[red]{Stealth[round,scale=1.5]}},
        mark=at position 0.14 with {\arrow[green]{Stealth[round,scale=1.5]}},
        mark=at position 0.65 with {\arrow[blue]{Stealth[round,scale=1.5]}}, % <--
        mark=at position 0.86 with {\arrow[green]{Stealth[round,scale=1.5]}}}% <--
                    ]
% axis
\draw [-{Stealth[round,scale=1.5]}] (-4,0) -- (4,0) node[ left] {$x$};
\draw [-{Stealth[round,scale=1.5]}] (0,-4) -- (0,4) node[below] {$i y$};
% curve
\draw (-3,0.3) node[blue,left=0.02cm]   {$C_R$};
\draw (-1,0.3) node[red,left=0.02cm]    {$C_r$};
\draw ( 2,0.3) node[green,above=0.02cm] {$L_1$};
\draw (2,-0.3) node[green,below=0.02cm] {$L_2$};
\draw [postaction={decorate}]
    (-1, 0.0) arc(180:5:10mm) --
    ( 3, 0.1) arc(2:358:30mm) --
    ( 1,-0.1) arc(355:180:10mm);
\end{tikzpicture}
\end{document}

note: it is not fun to write missing, many times essential part of code, that your code snippet can be tested. so, please, in future always provide complete small document beginning with \documentclass{...} and ending with \end{documentclass} and in preamble load only to your problem related packages as i did in above mwe (minimal working example).

  • Additional comment: If you use an editor such as emacs that will indent your code automatically, such mistakes are much easier to uncover, as they lead to unexpected indentation. – Harald Hanche-Olsen Jan 3 '18 at 13:38
  • @HaraldHanche-Olsen ...if you can manage to make some mistakes rather than randomly typing stuff and accidentally formatting your computer with it. – percusse Jan 3 '18 at 13:42
  • @percusse I don't usually type at random, but I never heard of anybody damaging their computer in any way with emacs. (Unless it is by becoming superuser and editing system files, but then emacs is hardly to blame.) Anyway, this is not the place for an editor rwar. – Harald Hanche-Olsen Jan 3 '18 at 13:47
  • @HaraldHanche-Olsen it was meant as a joke but didn't work apparently :) – percusse Jan 3 '18 at 13:49
  • Ah. Well, then. Maybe my humour detector needs a tune-up. At least I am pretty good at making mistakes, editor or no. That's why I enjoy having an editor catch at least some of them. – Harald Hanche-Olsen Jan 3 '18 at 13:55

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.