# Error when using tikz \node, \subnode

In the code below, building off solutions found here, I am trying to use the \node and \subnode options to draw the arrow, but I cannot get the file to compile. Can you help me to fix the code to get the arrow to point to the text and the highlighted cell like this

Here is the code:

\documentclass{article}
\usepackage{tikz}
\usepackage{blkarray}
\usetikzlibrary{fit,calc,arrows,shapes,decorations.pathreplacing,pgfplots.groupplots, matrix}
\tikzset{%
highlight/.style={rectangle,rounded corners,fill=red!15,draw,
fill opacity=0.5,thick,inner sep=0pt}
}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,
baseline=(#1.base)] \node (#1) {#2};}
%
\newcommand{\Highlight}[1][submatrix]{%
\tikz[overlay,remember picture]{
\node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}
\begin{document}
$M = \left(\begin{array}{*5{c}} \tikzmark{left}{1} & 2 & 3 & 4 & 5 \\ 6 & 7 & 8 & 9 & 10 \\ 11 & 12 & \tikzmark{right}{13} & 14 & 15 \\ 16 & 17 & 18 & 19 & 20 \end{array}\right) \Highlight[first] \qquad M^T = \left(\begin{array}{*5{c}} \tikzmark{left}{1} & 6 & 11 & 16 \\ 2 & 7 & 12 & 17 \\ 3 & 8 & \tikzmark{right}{13} & 18 \\ 4 & 9 & 14 & 19 \\ 5 & 10 & 15 & 20 \end{array}\right)$
\Highlight[second]
%
\tikz[overlay,remember picture] {
\draw[->,thick,red,dashed] (first) -- (second) node [pos=0.66,above] {Transpose};
\node[above of=first] {$N$};
\node[above of=second] {$N^T$};
}

$\begin{blockarray}{ccccc} x_{1} & x_{2} & x_{3} & x_{4} & \\ \begin{block}{[cccc|c]} 1 & 0 & \tikzmark{left}{-1} & 0 & 0 \\ 0 & 1 & 2 & 0 & 0 \\ 0 & 0 & \tikz{\node{\subnode{d1}\tikzmark{right}{0}};} & 1 & 0 \\ \end{block} \end{blockarray} \Highlight[new1]$

%\begin{tikzpicture}[remember picture,overlay]
%    \node [shift={(3.0em,-4.0ex)}, anchor=west] at ({pic cs:starta}) (X) {Tip measurement};
%    \draw [mybluei, thick, -latex] (X.west) -| ($({pic cs:starta})!0.5!({pic cs:enda})+(0,-0.5ex)$);
%\end{tikzpicture}

\end{document}

• Also, you try to also use \mytikzmark within the node, but that is not going to work. That is why \subnode was written: so that you could mark stuff within nodes, when the usual methods of setting tikzmarks (however defined) aren't available. So either don't use a subnode here or a TikZ picture and just use \mytikzmark. Or use \subnodes inside the TikZ picture. But I can't see why you want a TikZ picture here. What are you trying to produce exactly? – cfr Feb 8 '16 at 21:37
• @cfr, thanks for your comments. Please see my updated question with the image of what I am trying to accomplish. – Joe Feb 8 '16 at 21:47

So the problem with the code is that \subnode is never defined. You can get it defined by loading the tikzmark library. However, \newcommand\tikzmark... will then fail as the library defines the standard \tikzmark command. This problem can be avoided by simply choosing a different macro name, such as \mytikzmark.

You cannot, however, use \mytikzmark or \tikzmark inside a node inside a TikZ picture. Indeed, the raison d'être of \subnode is for use in this context precisely because tikzmarks cannot be used there.

So you can either use \mytikzmark or \tikzmark without the surrounding TikZ picture environment. Or you can use \subnodes within one.

Here's a comparison of the two methods:

\documentclass{article}
\usepackage{tikz}
\usepackage{blkarray}
\usetikzlibrary{fit,tikzmark}
\tikzset{%
highlight/.style={rectangle,rounded corners,fill=red!15,draw, fill opacity=0.5,thick,inner sep=0pt}
}
\newcommand{\mytikzmark}[2]{\tikz[overlay,remember picture, baseline=(#1.base)] \node (#1) {#2};}

\newcommand{\Highlight}[1][submatrix]{%
\tikz[overlay,remember picture]{
\node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}
\begin{document}
$\begin{blockarray}{ccccc} x_{1} & x_{2} & x_{3} & x_{4} & \\ \begin{block}{[cccc|c]} 1 & 0 & \mytikzmark{left}{-1} & 0 & 0 \\ 0 & 1 & 2 & 0 & 0 \\ 0 & 0 & \tikz{\node{\subnode{d1}{d1}\subnode{right}{0}};} & 1 & 0 \\ \end{block} \end{blockarray} \Highlight[new1]$
\tikz[remember picture,overlay]{%
\node [fit=(d1), inner sep=-2.5pt, draw=blue, circle] {};
\node [fit=(right), inner sep=-2.5pt, draw=green!50!black, circle] {};
}
$\begin{blockarray}{ccccc} x_{1} & x_{2} & x_{3} & x_{4} & \\ \begin{block}{[cccc|c]} 1 & 0 & \mytikzmark{left}{-1} & 0 & 0 \\ 0 & 1 & 2 & 0 & 0 \\ 0 & 0 & \mytikzmark{d1}{d1} \mytikzmark{right}{0} & 1 & 0 \\ \end{block} \end{blockarray} \Highlight[new1]$
\tikz[remember picture,overlay]{%
\node [fit=(d1), inner sep=-2.5pt, draw=blue, circle] {};
\node [fit=(right), inner sep=-2.5pt, draw=green!50!black, circle] {};
}

\end{document}


Given your updated question, I don't think you want \subnode at all. Why not just use the marks you already have?

\documentclass{article}
\usepackage{tikz}
\usepackage{blkarray}
\usetikzlibrary{fit,arrows.meta}
\tikzset{%
highlight/.style={rectangle,rounded corners,fill=red!15,draw, fill opacity=0.5,thick,inner sep=0pt}
}
\newcommand{\mytikzmark}[2]{\tikz[overlay,remember picture, baseline=(#1.base)] \node (#1) {#2};}

\newcommand{\Highlight}[1][submatrix]{%
\tikz[overlay,remember picture]{
\node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}
\begin{document}
$\begin{blockarray}{ccccc} x_{1} & x_{2} & x_{3} & x_{4} & \\ \begin{block}{[cccc|c]} 1 & 0 & \mytikzmark{left}{-1} & 0 & 0 \\ 0 & 1 & 2 & 0 & 0 \\ 0 & 0 & \mytikzmark{right}{0} & 1 & 0 \\ \end{block} \end{blockarray} \Highlight[new1]$
\tikz[remember picture,overlay]{%
\draw [LaTeX-] (new1.south) ++(0,-2.5pt) [out=-90,in=160] to ++(5mm,-10mm) node [right, xshift=-2.5mm, font=\itshape, text=red, align=center] {free\\variable};
}

\end{document}


• I think you should add TikZnician to you title :) – Sveinung Feb 8 '16 at 22:06