8

I would like to have several single arrow nodes all with the same dimensions (independent of the node text). I tried to achieve this by setting minimum width, minimum height, inner sep, and single arrow head extend.

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{shapes.arrows}
\tikzset{MyArrow/.style={single arrow, draw, minimum width=6ex, minimum height=10ex, 
                         inner sep=0ex, single arrow head extend=1ex}
}

\begin{document}

    \begin{tikzpicture}

        \draw[step=1ex,gray,ultra thin] (-1ex,-4ex) grid (45ex,4ex);
        \path (0,0) node[anchor=west,MyArrow] (a1) {};
        \path (a1.east) ++(1ex,0) node[anchor=west,MyArrow] (a2) {a};
        \path (a2.east) ++(1ex,0) node[anchor=west,MyArrow] (a3) {b};
        \path (a3.east) ++(1ex,0) node[anchor=west,MyArrow] (a4) {bg};

    \end{tikzpicture}

\end{document}

Here, the arrow dimensions depend on the text. enter image description here

One can indirectly make the arrow dimensions independent of the node text by using \rule as the node text and adding the text with a subsequent command:

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{shapes.arrows}
\tikzset{MyArrow/.style={single arrow, draw, minimum width=6ex, minimum height=10ex, 
                         inner sep=0ex, single arrow head extend=1ex}
}

\begin{document}
   \begin{tikzpicture}

        \draw[step=1ex,gray,ultra thin] (-1ex,-4ex) grid (45ex,4ex);
        \path (0,0) node[anchor=west,MyArrow] (a1) {\rule{0ex}{4ex}};
        \path (a1.east) ++(1ex,0) node[anchor=west,MyArrow] (a2) {\rule{0ex}{4ex}};
        \path (a2) node {a};
        \path (a2.east) ++(1ex,0) node[anchor=west,MyArrow] (a3) {\rule{0ex}{4ex}};
        \path (a3) node {b};
        \path (a3.east) ++(1ex,0) node[anchor=west,MyArrow] (a4) {\rule{0ex}{4ex}};
        \path (a4) node {bg};

    \end{tikzpicture}

\end{document}

enter image description here

I was wondering whether there is an easier way to directly determine the dimensions of the single arrow node shape and make it independent of the node text.

Robert
  • 267

3 Answers3

3

If you use dimensions in ex and em then they are subject to change. Use absolute dimensions like mm or cm or in.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes.arrows}
\tikzset{MyArrow/.style={single arrow, draw, minimum width=10mm, minimum height=30mm,
                         inner sep=0mm, single arrow head extend=1mm}
}

\begin{document}

    \begin{tikzpicture}

        \draw[step=1ex,gray,ultra thin] (-1ex,-4ex) grid (45ex,4ex);
        \path (0,0) node[anchor=west,MyArrow] (a1) {\strut};
        \path (a1.south) ++(0,-10mm) node[MyArrow] (a2) {\strut a};
        \path (a2.south) ++(0,-10mm) node[MyArrow] (a3) {\strut b};
        \path (a3.south) ++(0,-10mm) node[MyArrow] (a4) {\strut bg};

    \end{tikzpicture}

\end{document}

enter image description here

I have used \strut to maintain height and depth of the text. You can use text height and text depth instead. Put them in mm too.

3

Your first example fails because you use inner sep=0ex. With this option commented out, the first arrow keeps minimum width and minimum height.

Once you have decided minimum height and width, you can simulate writing some contents inside arrows with the label=center:... option instead of using {...}. In this case, label's text is written on node's center.

\documentclass[tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.arrows}
\tikzset{MyArrow/.style={single arrow, draw, minimum width=6ex, minimum height=10ex, 
                         %inner sep=0ex, 
                         single arrow head extend=1ex}
}

\begin{document}

    \begin{tikzpicture}

        \draw[step=1ex,gray,ultra thin] (-1ex,-4ex) grid (45ex,4ex);
        \path (0,0) node[anchor=west,MyArrow] (a1) {};
        \path (a1.east) ++(1ex,0) node[anchor=west,MyArrow, label=center:a] (a2) {};
        \path (a2.east) ++(1ex,0) node[anchor=west,MyArrow, label=center:b] (a3) {};
        \path (a3.east) ++(1ex,0) node[anchor=west,MyArrow, label=center:bg] (a4) {};

    \end{tikzpicture}

\end{document}

enter image description here

Ignasi
  • 136,588
  • Thanks for your answer. There was another answer (which disappeared in the meantime) mentioning the node parameters text height and text depth. I think setting these could solve my problem... – Robert Nov 03 '14 at 10:46
  • You can change the order of the keys too. – percusse Nov 03 '14 at 12:42
  • I should have mentioned that I wanted to have a an arrow with a fixed single arrow head extend and a fixed width of the arrow tail. For this, setting the parameters text height and text depth do the trick. – Robert Nov 03 '14 at 14:01
0

Inspired by Harish Kumar's hint to to set text height and text depth I came up with the following solution.

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{shapes.arrows}
\tikzset{MyArrow/.style={single arrow, draw, minimum width=5ex, minimum height=10ex, 
                         inner sep=1ex, text height=1ex, text depth=0ex,
                         single arrow head extend=1ex}
}

\begin{document}

    \begin{tikzpicture}

        \draw[step=1ex,gray,ultra thin] (-1ex,-4ex) grid (45ex,4ex);
        \path (0,0) node[anchor=west,MyArrow] (a1) {};
        \path (a1.east) ++(1ex,0) node[anchor=west,MyArrow] (a2) {a};
        \path (a2.east) ++(1ex,0) node[anchor=west,MyArrow] (a3) {b};
        \path (a3.east) ++(1ex,0) node[anchor=west,MyArrow] (a4) {bg};

    \end{tikzpicture}

\end{document}

resulting in the following output.

enter image description here

Robert
  • 267