Tikz - 移动/重新定位箭头装饰(箭头长度/大小)

Tikz - 移动/重新定位箭头装饰(箭头长度/大小)

我正在尝试为 Tikz 构建“尺寸线”宏:

\documentclass{article}

% note: with \documentclass{minimal}, this example fails with:
% ! Undefined control sequence.
% \pgf@lib@dec@computed@action ...t (0,0.25) {\tiny 
%                                                   {'test'}};}
% l.31 ...ne[($(nA)+(0,1)$)][($(nB)+(0,1)$)]['test']
%                                                    ;
% ? 
% ... but if Enter is pressed at prompt, a PDF is generated anyways by pdflatex.. 


\usepackage{tikz}
\usetikzlibrary{arrows,snakes,backgrounds,patterns,matrix,shapes,fit,calc,shadows,plotmarks,chains,positioning,scopes,decorations.markings}
\usepackage[graphics,tightpage,active]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}

\def\Dimline[#1][#2][#3]{
    %\node at (0,0) {"test: #1 - #2 ..."};
    \begin{scope}[>=latex] % redef arrow for dimension lines
        \draw[|-|,
            decoration={markings, % switch on markings
                mark=at position 0 with {\arrow[scale=0.5]{<}};,
                mark=at position .5 with {\node[gray] at (0,0.25) {\tiny{#3}};},
                mark=at position 1 with {\arrow[scale=0.5]{>}};,
            },
        postaction={decorate},
        %shorten <=1pt,
        ] #1 -- #2 ;
    \end{scope}
}

\begin{tikzpicture}

    \node at (0,0) (nA) {A};
    \node at (3,0) (nB) {B};
    \Dimline[($(nA)+(0,1)$)][($(nB)+(0,1)$)]['test'] ;

\end{tikzpicture}

\end{document}

...几乎所有功能都正常,除了左箭头向左延伸(我猜它的参考点在右端?!)。

示例渲染

显然,我想将箭头向右移动箭头的长度,但我找不到任何地方如何检索箭头的大小/长度?!

除此之外,还有其他方法可以让箭头“适合”尺寸线内吗?

编辑:只需说明:我想保留decoration={markings,因为我认为只有这样我才能缩放箭头,就像\arrow[scale=0.5]?!

谢谢,
干杯!

答案1

对于此应用程序,您只需使用以下命令定义一个新的组合箭头\pgfarrowsdeclarecombine{name left}{name right}{outer element left}{outer element right}{inner element left}{inner element right}

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows,calc,decorations.markings}

\begin{document}
\pgfarrowsdeclarecombine{|<}{>|}{|}{|}{latex}{latex}
\def\Dimline[#1][#2][#3]{
    %\node at (0,0) {"test: #1 - #2 ..."};
    \begin{scope}[>=latex] % redef arrow for dimension lines
        \draw[|<->|,
        decoration={markings, % switch on markings
                mark=at position .5 with {\node[gray] at (0,0.25) {\tiny{#3}};},
        },
        postaction=decorate] #1 -- #2 ;
    \end{scope}
}

\begin{tikzpicture}

    \node at (0,0) (nA) {A};
    \node at (3,0) (nB) {B};
    \Dimline[($(nA)+(0,1)$)][($(nB)+(0,1)$)]['test'] ;

\end{tikzpicture}

\end{document}

使用 tikz 测量线


或者,为了能够随意缩放箭头尖,您可以使用以下装饰方法。将latex尖头与“空箭头”组合在一起,以修复线末端的突出部分:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows,calc,decorations.markings}

\begin{document}
\pgfarrowsdeclarecombine{dimarrow}{dimarrow}{latex}{latex}{}{}
\def\Dimline[#1][#2][#3]{
        \draw[|-|,
        decoration={markings, % switch on markings
                mark=at position 0 with {\arrowreversed[scale=0.5]{dimarrow}};,
                mark=at position .5 with {\node[gray] at (0,0.25) {\tiny{#3}};},
                mark=at position 1 with {\arrow[scale=0.5]{dimarrow}};,
            },
        postaction=decorate] #1 -- #2 ;
}

\begin{tikzpicture}

    \node at (0,0) (nA) {A};
    \node at (3,0) (nB) {B};
    \Dimline[($(nA)+(0,1)$)][($(nB)+(0,1)$)]['test'] ;

\end{tikzpicture}

\end{document}

相关内容