我希望有多个单箭头节点,它们都具有相同的尺寸(与节点文本无关)。我尝试通过设置minimum width
、minimum height
、inner sep
和来实现这一点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}
这里,箭头的尺寸取决于文本。
可以通过使用\rule
节点文本并使用后续命令添加文本来间接使箭头尺寸独立于节点文本:
\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}
我想知道是否有更简单的方法可以直接确定单箭头节点形状的尺寸并使其独立于节点文本。
答案1
如果您使用ex
和中的尺寸,em
则它们可能会发生变化。请使用绝对尺寸,如mm
或cm
或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}
我习惯于\strut
保持文本的高度和深度。你可以改用text height
和text depth
。把它们也放进去mm
。
答案2
您的第一个示例失败了,因为您使用了inner sep=0ex
。注释掉此选项后,第一个箭头将保留minimum width
和minimum height
。
一旦你决定了最小高度和宽度,你可以用选项来模拟在箭头内写一些内容,label=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}
答案3
受到 Harish Kumar 的提示的启发text height
,text depth
我想出了以下解决方案。
\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}
产生以下输出。