以问号结尾的箭头(tikz)

以问号结尾的箭头(tikz)

我有以下图形,其中包括一个以三角形结尾的箭头:

\documentclass[margin=0.5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}
\node[draw=white] (1) at (4,0) {AA};
\node[draw=white] (2) at (0,4) {BB};
\draw[black, arrows={|-Triangle[angle=45:10pt,black,fill=black]}] (1) -- (2);
\end{tikzpicture}
\end{document}

如何改变它以便箭头以问号而不是三角形结束?

答案1

我的解决方案与 类似ferahfeza。我的思路如下:

借助它,\usetikzlibrary{calc}您可以精确计算给定路线上的某个点。我们利用这一点:

\documentclass[margin=0.5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
\node[draw=white] (1) at (4,0) {AA};
\node[draw=white] (2) at (0,4) {BB};
%\draw[black, arrows={|-Triangle[angle=45:10pt,black,fill=black]}] (1) -- (2);

\draw (1) -- (2);
\node[fill=white,draw,circle,inner sep=1pt] at ($(4,0)!.92!(0,4)$) {?}; % You can remove the node options if you want
\end{tikzpicture}
\end{document}

答案2

我猜你想让问号指向最后的那条线。你可以使用sloped将问号与线垂直对齐,然后将其旋转 90 度使其平行。此外,你还需要重新定位问号,因为它的锚点位于中间。

\documentclass[margin=0.5mm]{standalone}
\usepackage{tikz}
\begin{document}
  % Get height of question mark
  \newbox\qbox
  \setbox\qbox\hbox{?}
  \edef\qmarkHeight{\the\ht\qbox}
  \begin{tikzpicture}
    \node[draw=white] (1) at (4,0) {AA};
    \node[draw=white] (2) at (0,4) {};
    \node[above left] at (2) {BB};
    \draw[black, arrows={|-}] (1) -- (2) node[sloped, at end, rotate=90, yshift=\qmarkHeight/2]{?};
  \end{tikzpicture}
\end{document}

由此产生了这个“提示”:问号箭头提示

此外,你可以使用装饰器使其成为一种风格(\draw[questionmark]...),如下所示回答:

\documentclass[margin=0.5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
  % Get height of question mark
  \newbox\qbox
  \setbox\qbox\hbox{?}
  \edef\qmarkHeight{\the\ht\qbox}
  \begin{tikzpicture}
    \tikzset{questionmark/.style={
          postaction={
              decorate,decoration={
                  markings,mark=at position 1 with {
                      \node[at end, rotate=-90, yshift=\qmarkHeight/2]{?};
                    }
                }
            }
        }
    }
    \node[draw=white] (1) at (4,0) {AA};
    \node[draw=white] (2) at (0,4) {};
    \node[above left] at (2) {BB};
    \draw[black, arrows={|-}, questionmark] (1) -- (2);
  \end{tikzpicture}
\end{document}

这产生了(几乎)相同的结果。

相关内容