2

Does somebody know how to align text, letters or signs exactly above the middle of an arrowhead of an line, independent of the length of the line?

It should look similar to the following figure but the position of the node should not depend on the length of the line.

\begin{tikzpicture}
\draw [-triangle 60] (0,0) -- (2,0) node[pos=.9,above] {$+$};
\draw [-triangle 60] (0,-1) -- (3,-1) node[pos=.9,above] {$+$};

\draw [-triangle 60] (0,-2) -- (2,-2) node[pos=.9,above] {$-$};
\draw [-triangle 60] (0,-3) -- (3,-3) node[pos=.9,above] {$-$};
\end{tikzpicture}

Arrows

3

Something like this:

enter image description here

It's quite simple:

\documentclass[border=3mm, tikz]{standalone}
    \usetikzlibrary{arrows}

\begin{document}
\begin{tikzpicture}[
    sgn/.style = {above left, inner xsep=0pt}
                    ]
\draw [-triangle 60] (0,0)  -- (2, 0) node[sgn] {$+$};
\draw [-triangle 60] (0,-1) -- (3,-1) node[sgn] {$+$};

\draw [-triangle 60] (0,-2) -- (2,-2) node[sgn] {$-$};
\draw [-triangle 60] (0,-3) -- (3,-3) node[sgn] {$-$};
\end{tikzpicture}
\end{document}
1

If you use the current, recommended syntax rather than the legacy version for arrow specifications, you can automatise this rather nicely. This means using the arrows.meta library rather than arrows.

For example:

\tikzset{
  tlabel/.style={
    inner sep=0pt, anchor=center,above,at end, xshift=-.5*\tarrowlength,yshift=.5*\tarrowlength
  },
  tarrow/.code={
    \tikzset{
      tarrow length=#1,
      -{Triangle[length=#1,width=#1]},
    },
  },
  tarrow length/.store in=\tarrowlength,
  tarrow length=10pt,
}

This code allows you to say

  \draw [tarrow=20pt] (0,-2) -- (2,-2) node[tlabel] {$-$};

and it will ensure that the arrow tip is 20pt by 20pt and that the label at the end is centred 10pt above and 10pt to the left of the end of the line, which is where you want it if you want it centred above the arrow, I think.

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{arrows.meta}
\tikzset{
  tlabel/.style={
    inner sep=0pt, anchor=center,above,at end, xshift=-.5*\tarrowlength,yshift=.5*\tarrowlength
  },
  tarrow/.code={
    \tikzset{
      tarrow length=#1,
      -{Triangle[length=#1,width=#1]},
    },
  },
  tarrow length/.store in=\tarrowlength,
  tarrow length=10pt,
}
\begin{document}
\begin{tikzpicture}
  \draw [tarrow=10pt] (0,0) -- (2,0) node [tlabel] {$+$};
  \draw [tarrow=20pt] (0,-1) -- (3,-1) node[tlabel] {$+$};

  \draw [tarrow=20pt] (0,-2) -- (2,-2) node[tlabel] {$-$};
  \draw [tarrow=10pt] (0,-3) -- (3,-3) node[tlabel] {$-$};
\end{tikzpicture}
\end{document}

tarrows

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.