I've defined the commands
\newcommand{\tikzmark}[2]{%
\tikz[overlay,remember picture,baseline] \node[anchor=base] (#1) {$#2$};
}
\newcommand{\DrawVLine}[3][]{%
\begin{tikzpicture}[overlay,remember picture]
\draw[shorten <=0.3ex, thick, #1] (#2.north) -- (#3.south);
\end{tikzpicture}
}
\newcommand{\DrawHLine}[3]{%
\begin{tikzpicture}[overlay,remember picture]
\draw[shorten <=0.2em, thick, #1] (#2.west) -- (#3.east);
\end{tikzpicture}
}
and I'm using them as
\begin{equation}
\bordermatrix{
& (A) & (B) & (C) & (D) & (E) \cr
(1) & 6 & 4 & 3 & \tikzmark{topD}{2} & \tikzmark{topA}{0} \cr
(2) & 5 & 4 & 3 & 5 & 0 \cr
(3) & 3 & 7 & 3 & 0 & 0 \cr
(4) & \tikzmark{leftB}{1} & 0 & 0 & 4 & \tikzmark{rightB}{0} \cr
(5) & \tikzmark{leftC}{0} & 0 & 6 & \tikzmark{bottomD}{4} & \tikzmark{bottomA}{0}
}
\DrawVLine[color=red]{topA}{bottomA}
\DrawHLine[color=blue]{leftC}{bottomA}
\DrawVLine[color=green]{topD}{bottomD}
\DrawHLine[color=orange]{leftB}{rightB}
\end{equation}
I get the error

What am I doing wrong?
Edit
A complete example
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{fit}
\usetikzlibrary{chains}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\newcommand{\tikzmark}[2]{%
\tikz[overlay,remember picture,baseline] \node[anchor=base] (#1) {#2};
}
\newcommand{\DrawVLine}[3][]{%
\begin{tikzpicture}[overlay,remember picture]
\draw[shorten <=0.3ex, thick, #1] (#2.north) -- (#3.south);
\end{tikzpicture}
}
\newcommand{\DrawHLine}[3]{%
\begin{tikzpicture}[overlay,remember picture]
\draw[shorten <=0.2em, thick, #1] (#2.west) -- (#3.east);
\end{tikzpicture}
}
\begin{document}
\begin{equation}
\bordermatrix{
& (A) & (B) & (C) & (D) & (E) \cr
(1) & 6 & 4 & 3 & \tikzmark{topD}{2} & \tikzmark{topA}{0} \cr
(2) & 5 & 4 & 3 & 5 & 0 \cr
(3) & 3 & 7 & 3 & 0 & 0 \cr
(4) & \tikzmark{leftB}{1} & 0 & 0 & 4 & \tikzmark{rightB}{0} \cr
(5) & \tikzmark{leftC}{0} & 0 & 6 & \tikzmark{bottomD}{4} & \tikzmark{bottomA}{0}
}
\DrawVLine[color=red]{topA}{bottomA}
\DrawHLine[color=blue]{leftC}{bottomA}
\DrawVLine[color=green]{topD}{bottomD}
\DrawHLine[color=orange]{leftB}{rightB}
\end{equation}
\end{document}
\documentclass...and end with\end{document}. – cfr Apr 18 '15 at 21:22tikzmarklibrary, you need to use thepiccoordinate system to access the nodes. – cfr Apr 18 '15 at 21:25overlayinside\tikzmark's definition. It seems that its output should actually be the size it has. (One could adjust theinner sepvalues maybe). — Your definition of\DrawHLineseems to be missing the declaration of the first and optional argument:\newcommand{\DrawHLine}[3][]{%(compare\DrawVLine). — There is also the possibility to put everything in a TikZ\matrixwithout the need for overlays, two compile runs, etc. – Qrrbrbirlbel Apr 18 '15 at 21:45.west,.east, etc. in the tikzmark library. I would love to use the library if I could. See http://tex.stackexchange.com/questions/235632/setting-west-east-north-south-to-position-with-tikzmark/235638?noredirect=1#comment558852_235638 – Jamgreen Apr 18 '15 at 21:56