tikz:对应于下方/上方的距离

tikz:对应于下方/上方的距离

考虑这个例子:

\documentclass[margin=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes, decorations.text}
\begin{document}
\begin{tikzpicture}
  \coordinate (A) at (0.0, 0.0);
  \coordinate (B) at (-5.0, 5.0);
  \draw[] (A) -- (B) node [midway, below, sloped](textnode1){line};
  \draw[red, ->,
  postaction={decorate,decoration={text effects along path,
    text={arc}, text align=center, reverse path,
    text effects/.cd,
      text along path,
      every character/.style={ yshift=0.5ex}}}] (A) arc (0:90:5);
\end{tikzpicture}
\end{document}

在此处输入图片描述

我应该为弧提供什么yshift以确保它与线相同above/below用于线?

答案1

从其他问题可以看出,我猜你想要一个比“arc”更长的文本,并且它需要遵循路径。你可以单独将字母放在路径上方或下方。像这样:

\documentclass[margin=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes, decorations.text}
\begin{document}
\begin{tikzpicture}
  \coordinate (A) at (0.0, 0.0);
  \coordinate (B) at (-5.0, 5.0);
  \draw[] (A) -- (B) node [midway, below, sloped](textnode1){line};
  \draw[red, ->,
  postaction={decorate,decoration={text effects along path,
    text={arc}, text align=center, reverse path,
    text effects/.cd,
      text along path,
      every character/.style={below}}}] (A) arc (0:90:5);
\end{tikzpicture}
\end{document}

带文字的直线和圆弧

below/above不对应于特定的移位,而是更改节点的锚点。节点移动是因为它有一个大小(inner sep最初为 .3333em)。

答案2

您的图像可以绘制得更简单。通过使用 TiZ 库arrows.meta(用于箭头)和quotes(用于边缘标签)。标签与边缘的距离由引号决定inner sep。默认值为 3pt,但every edge quotes/.style = {auto, inner sep=... , sloped}您可以使用样式更改为所需数量:

\documentclass[margin=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, quotes}

\begin{document}
    \begin{tikzpicture}[
every edge quotes/.style = {auto, inner sep=1pt, sloped}
                        ]
\coordinate (A) at (0.0, 0.0);
\coordinate (B) at (-5.0, 5.0);
%
\draw   (A) to ["line" sloped] (B);
\draw[red, -{Straight Barb[angle=60:3pt 4]}] 
        (A) to ["arc" sloped, bend right=45] (B);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容