2

I am trying to use relative coordinate with notation ++(x,y) which usually works fine. But in the example below it doesn't. I would like to define the node relative the center of a matrix, which I did at the end of the code below \node [font=\color{blue}] at (m.center)++(1,-3) {$4$}; I thought this would work but it doesn't. If this line is deleted everything is fine. How can I do this?

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,fit}

\begin{document}

\begin{tikzpicture}

\matrix(m) [matrix of math nodes, nodes in empty cells, nodes={minimum size=1cm, outer sep=0pt, text height=1.5ex, text depth=.25ex}]
{
 7      &   & 4     &      \\
        &   &       &      \\
 8      &   & 3     &      \\
        &   &       &      \\
};

\draw (m-1-1.north west) rectangle (m-4-4.south east);

\foreach \i in {2,4} {
  \draw (m-\i-1.south west) -- (m-\i-4.south east);
}


\foreach \j in {2,4} {
  \draw (m-1-\j.north east) -- (m-4-\j.south east);
}

% dual ui
\node [font=\color{blue}] at (3,1) {$5$};
\node [font=\color{blue}] at (3,-1) {$6$};

% dual vj
\node [font=\color{blue}] at (-1,-3) {$14$};
% \node [font=\color{blue}] at (1,-3) {$4$};

% Testing new notation
\node [font=\color{blue}] at (m.center)  {$4$};

% This last line is not valid for some reason
\node [font=\color{blue}] at (m.center)++(1,-3)  {$4$};

\end{tikzpicture}

\end{document}
1
  • 1
    You probably want \node [font=\color{blue}] at ([shift={(1,-3)}]m.center) {$4$};. Mar 21, 2021 at 21:06

1 Answer 1

4

It is generally better to use

\path (x,y) node{bla};

than to use

\node {bla} at (x,y);

What you experience is just one of the reasons. With the first syntax, everything works as expected. The second really expects a specific syntax, which you could still make work with the calc library or by using a shift, but these are merely tricks to make a less powerful syntax work.

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,fit}

\begin{document}

\begin{tikzpicture}

\matrix(m) [matrix of math nodes, nodes in empty cells, nodes={minimum size=1cm, outer sep=0pt, text height=1.5ex, text depth=.25ex}]
{
 7      &   & 4     &      \\
        &   &       &      \\
 8      &   & 3     &      \\
        &   &       &      \\
};

\draw (m-1-1.north west) rectangle (m-4-4.south east);

\foreach \i in {2,4} {
  \draw (m-\i-1.south west) -- (m-\i-4.south east);
}


\foreach \j in {2,4} {
  \draw (m-1-\j.north east) -- (m-4-\j.south east);
}

% dual ui
\node [text=blue] at (3,1) {$5$};
\node [text=blue] at (3,-1) {$6$};

% dual vj
\node [text=blue] at (-1,-3) {$14$};
% \node [text=blue] at (1,-3) {$4$};

% Testing new notation
\node [text=blue] at (m.center)  {$4$};

% This last line is not valid for some reason
\path (m.center)++(1,-3) node [text=blue] {$4$};

\end{tikzpicture}

\end{document}

enter image description here

Not the answer you're looking for? Browse other questions tagged .