3

I have three questions about the code below.

  1. I fail to use an xy-shift : see the final (2-2)++(6pt,2pt). What is the standard way to achieve this?
  2. The code is not one of mine. I don't understand the meaning of \p1 and \x1. The rest of the code is no mystery to me. ;-)
  3. How to just use 80% of \x1 for the radius?
\documentclass{standalone}

\usepackage{tikz} \usepackage{nicematrix} \usetikzlibrary{calc} \begin{document}

$det = \begin{NiceArray}{ccc} u & & v \ x & \kern.1pt & x' \ y & \kern.1pt & y' \CodeAfter \SubMatrix|{2-1}{3-3}| \begin{tikzpicture} \path (2-2.north) -- node[red,circle,inner sep=1pt] (minus) {$-$} (3-2.south);

 \draw [red,->] 
       let \p1=($(minus.east)-(minus.center)$) in
       (2-2)++(-6pt,2pt) 
       to[out=0,in=150]
       (minus.60)
       arc[start angle=60,end angle=-240,radius=\x1]
       to[out=30,in=180] 
       (2-2)++(6pt,2pt);
\end{tikzpicture}

\end{NiceArray} = ...$

\end{document}

This gives the following unwanted output.

enter image description here

projetmbc
  • 13,315
  • 2
    You probably want ([shift={(6pt,2pt)}]2-2) at the end. Doing (foo) ++ (bar) is a move to operation from foo to foo + bar. It is not (foo + bar). You need to do either the shift as above or use calc again: ($(2-2)+(6pt,2pt)$). – Qrrbrbirlbel Feb 14 '23 at 14:41
  • Yes, the 2nd comment does the job. Thanks for clarifying the use of ++. – projetmbc Feb 14 '23 at 14:48

2 Answers2

5
  1. There are a number of path operations available with TikZ.

    The most common are -- (a straight line to), -| and |- as well as .. controls .. and the special to (also edge but that's even more special).

    However, there is one more:
    That's right, nothing: A move to.

    When you write

    \path (<coordinate>);
    

    you already instruct TikZ to move to <coordinate>.

    Now the Pluses (+ and ++) aren't part of the path operation, they are part of the coordinate specification. Here we differentiate between

    1. one +(<coordinate>) which describes a coordinate that is relative to the last absolute coordinate and
    2. two ++(<coordinate>) which also describes a coordinate that is relative to the last absolute coordinate but also sets the new coordinate to be the next absolute coordinate.

    In your case, the differentation isn't important because your next coordinate (minus.60) is absolute anyway.

    The path (c1) -- (c2) ++ (c3) has two operations: One straight line from c1 to c2 and one move to (from c2) to c2 + c3.

    If you want c2 + c3 to be the target of your path operation you need to specify one coordinate. This can be done with

    1. ([shift=(c2)] c3),
    2. ([shift=(c3)] c2) or,
    3. with the calc library, ($(c2) + (c3)$)

    I would also do the same for the starting coordinate, though usually it won't matter since in your case (2-2) is already part of the bounding box (yes, a move to updates the bounding box) and you don't decorate the path (some decorations do something with a move to you wouldn't want).

  2. The let … in syntax is described in the manual.

    \p1 is actually \p{1} (i.e. it is possible to use everything, not just a digit: \p{name}).

    The calc library evaluates the specified coordinate and stores its x and y value (in the canvas coordinate system) in \x{name} and \y{name}, \p{name} expands then to \x{name}, \y{name}.

  3. .8*\x1 should work. Though, you also need to adjust minus.60 then.

Code

\documentclass{standalone}
\usepackage{tikz}
\usepackage{nicematrix}
\usetikzlibrary{calc}
\begin{document}
$det = \begin{NiceArray}{ccc}
    u &           & v       \\
    x & \kern.1pt & x'      \\
    y & \kern.1pt & y'
\CodeAfter
  \SubMatrix|{2-1}{3-3}|
    \begin{tikzpicture}
     \path (2-2.north) 
           -- 
           node[red,circle,inner sep=1pt] (minus) {$-$} 
           (3-2.south);
 \draw [red,-&gt;] 
       let \p1=($(minus.east)-(minus.center)$) in
       (2-2) ++(-6pt,2pt) % fine but maybe better:
                          % a. ([shift={(-6pt,2pt)}] 2-2)
                          % b. ($(2-2)+(-6pt,2pt)$)
       to[out=0,in=150]
       ([xshift=-.1*\x1]minus.60) % adjusting this also!
       arc[start angle=60,end angle=-240,radius=.8*\x1]
       to[out=30,in=180] 
       ([shift={(6pt,2pt)}] 2-2) % or with calc:
                                 % ($(2-2)+(6pt,2pt)$)
       % node[above left=2pt,scale=.2,black]{\p1}
       ;
\end{tikzpicture}

\end{NiceArray} = ...$ \end{document}

Output

I've added a node with \p1 as text in the output. In the code above that line is commented.

enter image description here

Qrrbrbirlbel
  • 119,821
4

Here is a simpler version with some other corrections:

  • Use option first-row so the matrix has the correct vertical placement.
  • Use the built-in coordinates provided by nicematrix
  • \cdots
  • vNiceArray will place the delimiters automatically

enter image description here

\documentclass{article}
\usepackage{tikz}
\usepackage{nicematrix}
\begin{document}

$det = \begin{vNiceArray}{ccc}[first-row] u && v \ x && x' \ &\color{red}-&\ y && y' \CodeAfter \begin{tikzpicture} \draw->, red, looseness=2 toout=0, in=0 to[out=180, in=180] (1.5-|3); \end{tikzpicture} \end{vNiceArray} = \cdots$

\end{document}

Or if you'd rather have only 2 rows and 2 columns, you can place the - as a node:

enter image description here

\documentclass{article}
\usepackage{tikz}
\usepackage{nicematrix}
\usetikzlibrary{calc}
\begin{document}

$det = \begin{vNiceArray}{c!{\hspace{5mm}}c}[first-row] u & v \ x & x' \[5mm] y & y' \CodeAfter \begin{tikzpicture} \draw->, red, looseness=2 toout=0, in=0node[above=1mm]{$-$} to[out=180, in=180] (1-2.west|-1-1); \end{tikzpicture} \end{vNiceArray} = \cdots$

\end{document}

Sandy G
  • 42,558
  • Thanks for the suggestion, but the minus sign is deliberately not put in a cell to make the decoration looks better. For vNiceArray and first-row, you are totally right: I was too confused by the problems with TikZ. – projetmbc Feb 14 '23 at 16:53
  • @projetmbc: I added an alternative. You can adjust the placement of the minus sign bu changing above=1mm. – Sandy G Feb 14 '23 at 17:17
  • Again, thank you, but I prefer the first solution which does not rely on the contents of the table. I did not indicate in my question, as it was not my problem, that one should take into account cases where one has for example x and yyyyyy. – projetmbc Feb 14 '23 at 17:26