调整位置计算方式为|-

调整位置计算方式为|-

我有这个片段,它工作正常:

\coordinate(foo) at (start |- something.south);

something.south但是,我想在计算之前在 y 上添加一些值|-。我尝试了我能想到的所有语法组合,包括我认为应该有效的这个:

\coordinate(foo) at (start |- something.south+(0,1mm));

然而,这会产生一个错误:

Package tikz Error: Giving up on this path. Did you forget a semicolon?.

在应用操作符之前如何调整点|-

答案1

有三种方法可以实现这一点,只有最后一种方法需要calc库。此列表并不详尽。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
  \begin{scope}[x=0.5mm,local bounding box=L]%
    \coordinate(start) at (0,0);
    \coordinate(end) at (230, 0);
    \node (something) at (50,3) {something};
    \coordinate(foo) at ([yshift=1mm]something.south-|start); 
    \draw[thick,->] (start) -- (foo);
  \end{scope}
  \node[above] at (L.north){with \texttt{yshift}};
  \begin{scope}[xshift=6cm,x=0.5mm,local bounding box=M]%
    \coordinate(start) at (0,0);
    \coordinate(end) at (230, 0);
    \node (something) at (50,3) {something};
    \path (something.south-|start) + (0,1mm) coordinate(foo); 
    \draw[thick,->] (start) -- (foo);
  \end{scope}
  \node[above] at (M.north){with \texttt{path}};
  \begin{scope}[xshift=12cm,x=0.5mm,local bounding box=R]%
    \coordinate(start) at (0,0);
    \coordinate(end) at (230, 0);
    \node (something) at (50,3) {something};
    \coordinate(foo) at ($(something.south-|start)+(0,1mm)$); 
    \draw[thick,->] (start) -- (foo);
  \end{scope}
  \node[above] at (R.north){with \texttt{calc}};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容