4

I am trying to draw a schematic with TikZ, and I need to have a curved line in it.

I know the basics, the problem is that the line should be curved on the left, while it is always curved on the right. Has anyone any idea of why it is happening this way.

Here is my environment:

\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}

And here is a capture of what I get:

Here you I have added a violet line with what I want Thanks for the help,

Krzysztof
  • 121
  • Please make MWE compilable. You haven't define colors blue 5 and green 5! Also a sketch of expected result would be helpful. – Zarko Jul 06 '23 at 07:52
  • 1
    Defining coordinates and then use these with the -| syntax works: \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);. – Jasper Habicht Jul 06 '23 at 07:54
  • @Zarko, those colors are defined by the ninecolors package. I have not added it in the code since I do not need to, it is loaded automatically in my installation. – Krzysztof Jul 06 '23 at 08:03
  • Thanks @JasperHabicht, your solution works great. But I must confess, it would be nice to understand the reason my original solution does not work – Krzysztof Jul 06 '23 at 08:08
  • 1
    I think that you can't mix the ($...$) coordinate calculation with the ( ... |- ...) one. Basically, the {...} are not really grouping there. – Rmano Jul 06 '23 at 08:42
  • 2
    Combining -|/|- with calc is a tricky thing. – Qrrbrbirlbel Jul 06 '23 at 09:03
  • But you mp load it in preamble ... – Zarko Jul 06 '23 at 09:58

2 Answers2

5

Whether this is a bug or not, I can't tell at the moment, but obviously, you can't mix the -| syntax and the $...$ syntax provided by the calc library with the bending options of a to path. You can't mix the -| syntax and the $...$ syntax at all, I would assume.

However, you can define two coordinates using the $...$ sytnax and then use these with the -| syntax:

\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}

enter image description here

Alternatively, since the problem more or less only affects the in option, you could use other ways to bend the path such as bend left or add relative as option (as in to[out=90, in=90, relative]).


I haven't found the reason for this behaviour yet, but a minimal working example to reproduce the problem is:

\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}

The expected output would be that the path describes a curve that is bent to the left only (so that it enters the target node from the left) as shown in red, but it does not:

enter image description here

  • Maybe worth an issue on https://github.com/pgf-tikz/pgf/issues ? I tried to ping @muzimuzhi but it seems it's not pinging... – Rmano Jul 06 '23 at 08:55
  • @Rmano I created a MWE without any remember picture or other stuff that should show the problem in an isolated way to play with. Let's wait for other users to add what they think the reason is first, maybe. – Jasper Habicht Jul 06 '23 at 08:58
  • 1
    This seems to be a problem with the implicit version, compare: \draw[red] (0,0) to[out=180, in=180] (perpendicular cs: horizontal line through={($(0,10)!0.5!(0,-5)$)}, vertical line through={($(-10,0)!0.5!(5,0)$)}); \draw[blue] (0,0) to[out=180, in=180] ({$(0,10)!0.5!(0,-5)$}-|{$(-10,0)!0.5!(5,0)$}); \draw[green, dashed] (0,0) to[out=180, in=180] ({$(-10,0)!0.5!(5,0)$}|-{$(0,10)!0.5!(0,-5)$}); – Qrrbrbirlbel Jul 06 '23 at 09:01
4

Not to be confused with the node cs:.

We'll setup the xyz coordinate system so that the values [0, 1] cover the (hopefully) rectangular node from left to right (x) and bottom to top (y)

  1. Shift the coordinate system to the south west corner of the node.
  2. The x and y key are used so that the x vector goes (from the new origin) to the south east corner and the y vector goes to the north west corner.
  3. We ignore z.

Since the default direction of the y vector is upwards, I'll also set this up in this solution. The values needs to be swapped in relation to your approach (downwards). You can see this in the code since all y values are subtracted from 1.

Code

\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}

Output

enter image description here

Qrrbrbirlbel
  • 119,821
  • Wow, nice! I was confused by the link, yes --- where is the description of this trick? – Rmano Jul 06 '23 at 09:08
  • 1
    @Rmano There's no trick. I've edited my answer. This, of course, doesn't solve the underlying problems but I think it is an easier way to specify coordinates in relation to a rectangular node. It should also be possible to do ([node cs=Wiring] 0.05, 0.85) but I haven't tested it properly. Of course, we might also just write our own cs: but then we need to think about input syntax and parsing. – Qrrbrbirlbel Jul 06 '23 at 09:23