1

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

enter image description here

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}
Jamgreen
  • 3,687
  • Please give us a complete example. We can't compile that to reproduce the error. Start with \documentclass... and end with \end{document}. – cfr Apr 18 '15 at 21:22
  • If this is based on the tikzmark library, you need to use the pic coordinate system to access the nodes. – cfr Apr 18 '15 at 21:25
  • 2
    I don't think you want overlay inside \tikzmark's definition. It seems that its output should actually be the size it has. (One could adjust the inner sep values maybe). — Your definition of \DrawHLine seems 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 \matrix without the need for overlays, two compile runs, etc. – Qrrbrbirlbel Apr 18 '15 at 21:45
  • Why reinvent the wheel when the wheel already exists in the form of a perfectly good library, complete with documentation?! That is, what is the motive for rolling your own here? – cfr Apr 18 '15 at 21:53
  • Because I unfortunately cannot set .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

0 Answers0