为什么箭头装饰没有出现在 tikz 中?

为什么箭头装饰没有出现在 tikz 中?

我有一个关于如何在 TikZ 中用三个以上的箭头装饰路径的问题,我使用的代码

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

最后一个箭头永远不会出现,请参见以下内容

tikzarrow装饰

描述最后一个箭头装饰的代码部分位于部分mark=at position .86 with {\arrow[green]{Stealth[round,scale=1.5]}}\begin{tikzpicture}[decoration = ]

先感谢您。

答案1

装饰路径定义中的花括号不匹配。正确的代码是:

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]}}} % <--

在此处输入图片描述

编辑:

A姆韦生成上述图像(从您的代码重建并简化为合理的坐标值):

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

笔记: 编写缺少代码的、很多时候必不可少的部分代码并不好玩,因为您的代码片段无法进行测试。因此,请在将来始终提供完整的小文档,以开头\documentclass{...}和结尾,\end{documentclass}并在序言中仅加载到与问题相关的包,就像我在上面所做的那样姆韦(最小工作示例)。

相关内容