Placing a node at a specific distance from the end of a path

If you don't mind the decorations library dependency, then

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning, decorations}
\makeatletter
\tikzset{
  distance from start/.code={%
    \pgfgetpath\currentpath\pgfprocessround{\currentpath}{\currentpath}%
    \pgf@decorate@parsesoftpath{\currentpath}{\currentpath}%
    \pgfmathparse{#1/\pgf@decorate@totalpathlength}\tikzset{pos=\pgfmathresult}},
  distance from end/.code={%
    \pgfgetpath\currentpath\pgfprocessround{\currentpath}{\currentpath}%
    \pgf@decorate@parsesoftpath{\currentpath}{\currentpath}%
    \pgfmathparse{1-(#1/\pgf@decorate@totalpathlength)}\tikzset{pos=\pgfmathresult}}
}
\makeatother
\begin{document}
\begin{tikzpicture}

\node (A) {$A$};
\node [right=of A] (B) {$B$};
\draw(A) -- node[distance from start=10pt, above] {$+$}
            node[distance from end=5pt, below] {$\times$} (B);
\draw[->, red] (A.east) -- ++(10pt,0); % Test distances
\draw[->, blue] (B.west) -- ++(-5pt,0);
% test curve
\draw[green](A) to[in=45,out=225] 
            node[distance from start=10mm, inner sep=1pt,circle,fill] {}
            node[distance from end=10mm, inner sep=1pt,circle,fill] {} (B);

\end{tikzpicture}
\end{document}

enter image description here


\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node (A) {$A$};
\node [right=of A] (B) {$B$};
\draw [->] (A) -- (B) node[left=10pt, above]  {$+$};
\end{tikzpicture}
\end{document}

enter image description here


With the calc library:

\path ($(B)!10pt!(A)$) node [below, red]{$*$};

should work (10pt along the (B)-(A) line).

Tags:

Tikz Pgf