箭头定位不均匀

箭头定位不均匀

我试图将箭头放置在我的线段中间

draw[decoration={markings,mark=at position .5 with {\arrow{>}}},postaction={decorate}] (A)--(B);

在我看来,0.5 指的是“>”的尖端,但如果我改用“<”,则指的是“<”的尾部。因此,箭头的位置看起来不均匀,见下文。

我可以手动调整到 .5,但我正在寻找一个干净的解决方案,因为我正在绘制许多具有不同长度边缘的图表,所以有时我需要使用 .4 和 .6,有时需要使用 .45 和 .55 等等。

编辑:一种可能的解决方法是修改 \arrow{<} 和 \arrow{>},以便“位置”控制它们的重心,而不是尾部的尖端或末端。我该怎么做?

下面是我所讨论内容的一个例子: 在此处输入图片描述

\documentclass{standalone}
\usepackage{tikz,ifthen} %expl3}
\usetikzlibrary{positioning, math, decorations.markings,arrows.meta,calc,shapes.misc}
\usepgfmodule{decorations}

\tikzset{edge/.style={line width=1.5}}

\begin{document}
\raisebox{-0.4\height}{\begin{tikzpicture}
    \tikzmath{\x=0.3; \y=0.6;}
    \fill[gray!20!white] (0,0)circle(.8);
    \clip (0,0)circle(.8);
    \coordinate (A) at (\x,\x);
    \coordinate (B) at (\x,-\x);
    \coordinate (C) at (-\x,-\x);
    \coordinate (D) at (-\x,\x);
    \draw[edge, decoration={markings,mark=at position .5 with {\arrow{<}}},postaction={decorate}] (A)--(B);
    \draw[edge, decoration={markings,mark=at position .5 with {\arrow{>}}},postaction={decorate}] (B)--(C);
    \draw[edge, decoration={markings,mark=at position .5 with {\arrow{<}}},postaction={decorate}] (C)--(D);
    \draw[edge, decoration={markings,mark=at position .5 with {\arrow{>}}},postaction={decorate}] (D)--(A);
    \draw[edge, decoration={markings,mark=at position .5 with {\arrow{<}}},postaction={decorate}](A)--(\y,\y);
    \draw[edge,  decoration={markings,mark=at position .5 with {\arrow{>}}},postaction={decorate}](B)--(\y,-\y);
    \draw[edge,  decoration={markings,mark=at position .5 with {\arrow{<}}},postaction={decorate}] (C)--(-\y,-\y);
    \draw[edge, decoration={markings,mark=at position .5 with {\arrow{>}}},postaction={decorate}] (D)--(-\y,\y);
\end{tikzpicture}}
\end{document}

答案1

事实上,您可以通过移动箭头来定义新的箭头,然后按照之前的定义使用它。一个简单的例子(颜色只是为了让它清晰易读):

装饰为 0.5

\documentclass{standalone}
\usepackage{tikz,ifthen} %expl3}
\usetikzlibrary{positioning, math, decorations.markings,arrows.meta,calc,shapes.misc}
\usepgfmodule{decorations}

\begin{document}

\def\myarr{{\arrow[xshift={1.525pt + 0.9625\pgflinewidth}]{>}}}
\def\myrevarr{{\arrow[xshift={0.525pt + 0.9625\pgflinewidth}]{<}}}

\tikzset{edge/.style={line width=1.5},
        arr/.style={decoration={markings,mark=at position .5 with {\color{red}{\myarr}}},postaction={decorate}},
        arr'/.style={decoration={markings,mark=at position .5 with {\color{blue}{\myrevarr}}},postaction={decorate}}
        }
        
\begin{tikzpicture}
    \draw[orange!50] (0,0) grid (4,4);
    \draw[arr,edge] (0,0) -- (4,0);
    \draw[arr',edge] (0,1) -- (4,1);
    \draw[arr,edge,line width=4pt] (0,2) -- (4,2);
    \draw[arr',edge,line width=10pt] (0,3) -- (4,3);
\end{tikzpicture}
\end{document}

所用的测量值来自pgflibraryarrows.meta.code.tex。如果您需要对其他箭头执行此操作,则必须相应地调整代码。

答案2

提示的Computer Modern Rightarrow 行为正如您预期的那样。

添加了红色尖端以显示它们在该线段的中心相遇AB。(无需手动调整)。

使用\arrowreversed而不是\arrow 来反转箭头的方向。

C

\documentclass{standalone}
\usepackage{tikz,ifthen} %expl3}
\usetikzlibrary{positioning, math, decorations.markings,arrows.meta,calc,shapes.misc}
%\usepgfmodule{decorations}

\tikzset{edge/.style={line width=1.0}} % changed <<<<

\begin{document}
    \raisebox{-0.4\height}
    {\begin{tikzpicture}
            \tikzmath{\x=0.3; \y=0.6;}
            \fill[gray!20!white] (0,0)circle(.8);
            \clip (0,0)circle(.8);
            \coordinate (A) at (\x,\x);
            \coordinate (B) at (\x,-\x);
            \coordinate (C) at (-\x,-\x);
            \coordinate (D) at (-\x,\x);
            \draw[edge, decoration={markings,mark=at position 0.5 with {\arrowreversed{Computer Modern Rightarrow[red]}}},postaction={decorate}] (A)--(B);  % added <<<<<
            \draw[edge, decoration={markings,mark=at position 0.5 with {\arrow{Computer Modern Rightarrow}}},postaction={decorate}] (A)--(B);                   
            \draw[edge, decoration={markings,mark=at position .5 with {\arrow{Computer Modern Rightarrow}}},postaction={decorate}] (B)--(C);
            \draw[edge, decoration={markings,mark=at position .5 with {\arrowreversed{Computer Modern Rightarrow}}},postaction={decorate}] (C)--(D);
            \draw[edge, decoration={markings,mark=at position .5 with {\arrow{Computer Modern Rightarrow}}},postaction={decorate}] (D)--(A);
            \draw[edge, decoration={markings,mark=at position .5 with {\arrowreversed{Computer Modern Rightarrow}}},postaction={decorate}](A)--(\y,\y);
            \draw[edge, decoration={markings,mark=at position .5 with {\arrow{Computer Modern Rightarrow}}},postaction={decorate}](B)--(\y,-\y);
            \draw[edge, decoration={markings,mark=at position .5 with {\arrowreversed{Computer Modern Rightarrow}}},postaction={decorate}] (C)--(-\y,-\y);
            \draw[edge, decoration={markings,mark=at position .5 with {\arrow{Computer Modern Rightarrow}}},postaction={decorate}] (D)--(-\y,\y);
    \end{tikzpicture}}
\end{document}

答案3

也许通过创建两种样式,您可以将所需的值作为参数传递?

\documentclass{standalone}
\usepackage{tikz,ifthen} %expl3}
\usetikzlibrary{positioning, math, decorations.markings,arrows.meta,calc,shapes.misc}
\usepgfmodule{decorations}

\tikzset{edge/.style={line width=1.5},
        arr/.style={decoration={markings,mark=at position #1 with {\arrow{>}}},postaction={decorate}},
        arr'/.style={decoration={markings,mark=at position #1 with {\arrow{<}}},postaction={decorate}}
        }

\begin{document}
\raisebox{-0.4\height}{\begin{tikzpicture}
    \tikzmath{\x=0.3; \y=0.6;}
    \fill[gray!20!white] (0,0)circle(.8);
    \clip (0,0)circle(.8);
    \coordinate (A) at (\x,\x);
    \coordinate (B) at (\x,-\x);
    \coordinate (C) at (-\x,-\x);
    \coordinate (D) at (-\x,\x);
    \draw[edge, arr=.65] (A)--(B);
    \draw[edge, arr=.6] (B)--(C);
    \draw[edge, arr'=.65] (C)--(D);
    \draw[edge, arr=.6] (D)--(A);
    \draw[edge, arr'=.6](A)--(\y,\y);
    \draw[edge,  arr=.5](B)--(\y,-\y);
    \draw[edge,  arr'=.65] (C)--(-\y,-\y);
    \draw[edge, arr=.6] (D)--(-\y,\y);
\end{tikzpicture}}
\end{document}

用 arg 进行装饰

相关内容