第一个问题:-to做什么?

第一个问题:-to做什么?

在 TikZ 手册第 61/1318 页上有一个例子,我对其进行了简化和稍微的修改,以创建下面的图片:

在此处输入图片描述

这是我的代码:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary {arrows.meta}
\usetikzlibrary {decorations.pathmorphing}
\begin{document}

\begin{tikzpicture}
%\draw [->,-to, thick, decorate,
\draw [shorten >=1mm,-to, thick, decorate, red,
decoration={snake,amplitude=.4mm,segment length=2mm, pre=moveto, pre length=1mm, post length=2mm}]
(0,0) -- (3,0)
node [above=1mm,align=center,midway, text width=3 cm]
{
replacement of\\
the \textcolor{black}{capacity}\\
by \textcolor{black}{two places}
};
\draw [|-|] (2.8,0) -- (3,0);
\draw [|-|] (0,0) -- (.1,0);
\end{tikzpicture}
\end{document}

我有以下问题:

  1. 做什么-to
  2. 做什么pre=moveto
  3. 尽管post length=2mm根据使用的测量方法\draw [|-|] (2.8,0) -- (3,0);看起来柱子的长度较短。
  4. shorten >=1mm应用于何处以及如何与前后长度配合使用?

答案1

按照惯例,这里每次只提问一个问题。不过,我将只回答前两个问题,我建议您再次提出另一个问题,这个问题本身就值得进一步探讨。

第一个问题:-to做什么?

TikZ 和 pgf 手册(1.18 版)在第322页,我们了解到-to是一支箭。

manual-1.18

从它的形状来看,我们可以看出它是计算机现代右箭头如 3.1.5b 手册第 207 页所示。我引用一下:

除了<arrow tip kind name>,您还可以提供所谓的速记。简写看起来就像普通的箭头类型名称,事实上,你经常会使用简写而没有意识到。这个想法是,而不是,比如说,计算机现代右箭头你可能只想写右箭头或者可能只是或者甚至只是>

第二个问题:pre=moveto做什么?

当你装饰一条路径时,你可以让装饰稍后再开始,先在几毫米上画一条直线,然后再进行适当的装饰。搬去意思是不画也不涂颜色就去某个地方,这是移动。这里pre=moveto, pre length=1mm指定第一毫米什么都不会被绘制,装饰不做任何事,路径的第一毫米什么都不会被绘制。

答案2

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}

\begin{tikzpicture}[nodes={font=\small\ttfamily, black, right}]
  \draw[thick, red] (0, 0) -- (3, 0)
    node {1.1 init with "thick, red"};

  \draw[thick, red, shorten >=1mm, yshift=-.5cm] 
    (0, 0) -- (3, 0)
    node {1.2 add "shorten >=1mm"};
  \draw[|-|, yshift=-.4cm] (2.9, 0) -- node[above, font=\tiny] {1mm} (3, 0);

  \draw[thick, red, shorten >=1mm, -to, yshift=-1cm] 
    (0, 0) -- (3, 0)
    node {1.3 add arrow "-to"};

  \begin{scope}[yshift=-2cm]
    \draw[thick, red] (0, 0) -- (3, 0)
      node {2.1 the same as 1.1};

    \draw[thick, red, decorate,
      decoration={snake},
      yshift=-.5cm,
    ] (0, 0) -- (3, 0)
      node {2.2 add "decorate, decoration=\{snake\}"};

    \draw[thick, red, decorate, 
      decoration={snake, amplitude=.4mm, segment length=2mm},
      yshift=-1cm,
    ] (0, 0) -- (3, 0)
      node {2.3 add "decoration=\{..., amplitude=.4mm, segment length=2mm\}"};

    \draw[thick, red, decorate,
      decoration={
        snake, amplitude=.4mm, segment length=2mm, 
        pre length=1mm, post length=2mm
      },
      yshift=-1.5cm,
    ] (0, 0) -- (3, 0)
      node {2.4 add "decoration=\{..., pre length=1mm, post length=2mm\}"};
    \draw[|-|, yshift=-1.4cm] (0, 0) -- node[above, font=\tiny] {1mm} (.1, 0);
    \draw[|-|, yshift=-1.4cm] (2.8, 0) -- node[above, font=\tiny] {2mm} (3, 0);

    \draw[thick, red, decorate,
      decoration={
        snake, amplitude=.4mm, segment length=2mm, 
        pre length=1mm, post length=2mm, pre=moveto
      },
      yshift=-2.0cm,
    ] (0, 0) -- (3, 0)
      node {2.5 add "decoration=\{..., pre=moveto\}"};
    \draw[|-|, yshift=-1.9cm] (0, 0) -- node[above, font=\tiny] {1mm} (.1, 0);
  \end{scope}

  \begin{scope}[yshift=-5cm]
    \draw[thick, red, shorten >=1mm, -to, decorate,
      decoration={
        snake, amplitude=.4mm, segment length=2mm, 
      }
    ] (0, 0) -- (3, 0)
      node {3.1 combine 1.3 and 2.3, not good};

    \def\x{\ \ \ \ }
    \draw[thick, red, shorten >=5mm, -to, decorate,
      decoration={
        snake, amplitude=.4mm, segment length=2mm, 
      },
      yshift=-.5cm,
    ] (0, 0) -- (3, 0)
      node[yshift=-.6cm, align=left] {
        3.2 combine 1.3 and 2.3 and \\
        \x  use "shorten >=5mm" to show the real problem:\\
        \x decoration is not shortened and a line is drawn \\
        \x from real end (3, 0) to shortened end (2.5, 0).
    };
    \draw[|-|, yshift=-.4cm] (2.5, 0) -- node[above, font=\tiny] {5mm} (3, 0);

    \draw[thick, red, shorten >=5mm, -to, decorate,
      decoration={
        snake, amplitude=.4mm, segment length=2mm,
        post length=6mm, pre=moveto
      },
      yshift=-2.2cm,
    ] (0, 0) -- (3, 0)
      node {3.2' add "decoration=\{..., post length=6mm, pre=moveto\}", ok};

    \draw[thick, red, shorten >=1mm, -to, decorate,
      decoration={
        snake, amplitude=.4mm, segment length=2mm, 
        pre length=1mm, post length=2mm, pre=moveto
      },
      yshift=-2.7cm
    ] (0, 0) -- (3, 0)
      node {3.3 combine 1.3 and 2.5, ok};
    \draw[|-|, yshift=-2.6cm] (2.9, 0) -- node[above, font=\tiny] {1mm} (3, 0);
  \end{scope}
\end{tikzpicture}

\end{document}

相关内容