TikZ Arrow忽略旋转

TikZ Arrow忽略旋转

我想说明几个箭头,每个箭头都指向前一个箭头,但在某个点,两个箭头应该指向前一个箭头,因此它们的角度应该是 +/-45°。现在的问题是,箭头旋转似乎锁定在 90° 的倍数,这对我来说不切实际。

在此处输入图片描述

我定义并使用了rotate border,如 pgfmanual 中所述,但没有shape border uses incircle它会使箭头十分难看(尽管可以看出,旋转是正确的)。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart, shapes.arrows}

\begin{document}
\begin{tikzpicture}[every node/.style={fill=green, minimum width = 30pt, ultra thick},rotate border/.style={shape border rotate=#1}]
    \node[minimum height = 30pt] (last) at (-2,0){0};% top color=vir6, bottom color=vir8,
    \node[minimum height = 40pt,single arrow, rotate border = 180,anchor = tip] (last) at (last.east) {1};
    \node[minimum height = 40pt,single arrow, rotate border = 180,anchor = tip] (last) at (last.east) {2};
    \node[minimum height = 40pt,single arrow, rotate border = 180,anchor = tip] (last) at (last.east) {...};
    \node[minimum height = 40pt,single arrow, rotate border = 180,anchor = tip] (last) at (last.east) {1546000};
    \node[minimum height = 40pt,single arrow, rotate border = 200,anchor = tip] (orig) at (last.before tail) {1546001};
    \node[minimum height = 40pt,single arrow, rotate border = 160,anchor = tip] (fork) at (last.after tail) {1546001};
\end{tikzpicture}
\end{document}

答案1

我发现实现此目的的最佳方法如下:

  • 用来rotate border=180使箭头指向正确的方向
  • rotate = +/-20然后通过使用旋转节点(包括文本)应用额外的旋转。

仅使用旋转会导致节点的文本颠倒。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart, shapes.arrows}

\begin{document}
\begin{tikzpicture}[every node/.style={fill=green, minimum width = 30pt, ultra thick},rotate border/.style={shape border rotate=#1}]
    \node[minimum height = 30pt] (last) at (-2,0){0};% top color=vir6, bottom color=vir8,
    \node[minimum height = 40pt,single arrow, rotate border = 180,anchor = tip] (last) at (last.east) {1};
    \node[minimum height = 40pt,single arrow, rotate border = 180,anchor = tip] (last) at (last.east) {2};
    \node[minimum height = 40pt,single arrow, rotate border = 180,anchor = tip] (last) at (last.east) {...};
    \node[minimum height = 40pt,single arrow, rotate border = 180,anchor = tip] (last) at (last.east) {1546000};
    \node[minimum height = 40pt,single arrow, rotate border = 180, rotate = 20,anchor = tip] (orig) at (last.before tail) {1546001};
    \node[minimum height = 40pt,single arrow, rotate border = 180, rotate = -20,anchor = tip] (fork) at (last.after tail) {1546001};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

通过使用tikzpositioning并定义箭头样式,您可以使代码更短更清晰:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning, shapes.arrows}

\begin{document}
    \begin{tikzpicture}[
    node distance=1pt,% 0pt ?
Arr/.style = {single arrow, fill=green,
                     minimum width = 30pt, outer sep=0pt,
                     anchor = tip, shape border rotate=180},
box/.style = {fill=green, minimum size=30pt}
                        ]
    \node[box] (last) {0};% top color=vir6, bottom color=vir8,
    \node[Arr, right=of last]   (a1) {1};
    \node[Arr, right=of a1]     (a2) {2};
    \node[Arr, right=of a2]     (a3) {\dots};
    \node[Arr, right=of a3]     (a4) {1546000};
    \node[Arr, rotate= 30,right=of a4.before tail]  {1546001};
    \node[Arr, rotate=-30,right=of a4.after tail]   {1546001};
\end{tikzpicture}
\end{document}

给出:

在此处输入图片描述

相关内容