TikZ:曲线弯曲方向错误

TikZ:曲线弯曲方向错误

我正在尝试用 TikZ 绘制示意图,并且需要在其中画一条曲线。

我知道基本原理,问题是这条线应该在左边弯曲,而它总是在右边弯曲。有人知道为什么会这样吗?

这是我的环境:

\documentclass[aspectratio=169, 14pt, notes]{beamer}

\usetheme{Madrid}

\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc, datavisualization.formats.functions, fadings, fit, graphs, intersections, math, patterns, positioning, shapes, shadows, through, tikzmark}

\begin{document}
  \begin{frame}
    \frametitle{My frame title}
    \framesubtitle{My frame subtitle}
    \begin{tikzpicture}[remember picture, overlay]
      \node[inner sep=0pt, anchor=center, opacity=0.15, draw=blue5, font=\small, fit={({$(current page.north)!0.38!(current page.south)$} -| {$(current page.west)!0.08!(current page.east)$}) ({$(current page.north)!0.82!(current page.south)$} -| {$(current page.west)!0.92!(current page.east)$})}] (Wiring) at (current page.center) {This is my first box};
      \draw[stealth-, dashed, line width=0.25mm, draw=green5] ($(Wiring.north west)!0.10!(Wiring.south west)$) to[out=180, in=180] ({$(Wiring.north)!-0.15!(Wiring.south)$} -| {$(Wiring.west)!0.05!(Wiring.east)$});
    \end{tikzpicture}
  \end{frame}
\end{document}

以下是我所得到的结果:

在这里我添加了一条紫色的线,上面写着我想要的 谢谢您的帮助,

答案1

目前我还不能确定这是否是一个错误,但显然,你不能将语法-|和库$...$提供的语法calc与路径的弯曲选项混合在一起。我认为to你根本不能将-|语法和语法混合在一起。$...$

然而,你使用语法定义两个坐标$...$,然后使用以下语法-|

\documentclass[aspectratio=169, 14pt, notes]{beamer}

\usetheme{Madrid}

\usepackage{tikz}
\usetikzlibrary{calc, fit}

\usepackage{ninecolors}

\begin{document}
  \begin{frame}
    \frametitle{My frame title}
    \framesubtitle{My frame subtitle}
    \begin{tikzpicture}[remember picture, overlay]
      \node[inner sep=0pt, anchor=center, opacity=0.15, draw=blue5, font=\small, fit={({$(current page.north)!0.38!(current page.south)$} -| {$(current page.west)!0.08!(current page.east)$}) ({$(current page.north)!0.82!(current page.south)$} -| {$(current page.west)!0.92!(current page.east)$})}] (Wiring) at (current page.center) {This is my first box};
      \coordinate (A) at ($(Wiring.north)!-0.15!(Wiring.south)$); 
      \coordinate (B) at ($(Wiring.west)!0.05!(Wiring.east)$); 
      \draw[stealth-, dashed, line width=0.25mm, draw=green5] ($(Wiring.north west)!0.10!(Wiring.south west)$) to[out=180, in=180] (A -| B);
    \end{tikzpicture}
  \end{frame}
\end{document}

在此处输入图片描述

或者,由于问题或多或少只影响选项in,您可以使用其他方式来弯曲路径,例如bend left或添加relative作为选项(如to[out=90, in=90, relative])。


我还没有找到这种行为的原因,但重现该问题的最小工作示例是:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
    \begin{tikzpicture}
        \draw[->] (0,0) to[out=180, in=180] ({$(0,10)!0.5!(0,-5)$} -| {$(-10,0)!0.5!(5,0)$});
        \draw[->, red] (0,0) to[out=180, in=180] (0,2.5 -| -2.5,0);
    \end{tikzpicture}
\end{document}

预期的输出是路径描述一条仅向左弯曲的曲线(以便它从左侧进入目标节点),如红色所示,但事实并非如此:

在此处输入图片描述

答案2

不要与node cs:

我们将设置坐标坐标系这样值 [0, 1] 从左到右覆盖(希望是)矩形节点(X)和从下到上(

  1. 将坐标系移至节点的西南角。
  2. xy密钥被使用,以便X矢量(从新的原点)移到东南角,向量指向西北角。
  3. 我们忽略了

由于默认方向向量向上,我也会在这个解决方案中设置它。值需要根据你的方法交换(向下)。你可以在代码中看到这一点,因为所有值从 1 中减去。

代码

\documentclass[aspectratio=169, 14pt, notes]{beamer}
\usetheme{Madrid}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, fit}
\tikzset{
  node cs/.default=current page,
  node cs/.style={%
    shift={(#1.south west)},
    x={(#1.south east)},
    y={(#1.north west)}}}
\begin{document}
\begin{frame}
\frametitle{My frame title}
\framesubtitle{My frame subtitle}
\begin{tikzpicture}[remember picture, overlay]
\path[node cs] node[inner sep=0pt, anchor=center, opacity=0.15, draw=blue, font=\small, 
  fit={(0.08, 1-0.38)(0.92, 1-0.82)}] (Wiring) at (current page.center) {This is my first box};
\draw[Stealth-, dashed, line width=0.25mm, draw=green, node cs=Wiring]
  (0, 1-0.10) to[out=180, in=180, looseness=2] (0.05, 1+0.15);
\end{tikzpicture}
\end{frame}
\end{document}

输出

在此处输入图片描述

相关内容