I'd like to draw vertical/horizontal lines over the entries of a column/row in an array. I find the method to draw horizontal lines at Draw a horizonal line over the entries of a row in an array.
But when I used the same way to draw the vertical lines. It didn't look well.
My codes are:
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawLine}[3][]{%
\begin{tikzpicture}[overlay,remember picture]
\draw [#1] ($(#2)+(0,0.6ex)$) -- ($(#3)+(0,0.6ex)$);
\end{tikzpicture}%
}%
\begin{displaymath}
\left[
\begin{array}{cccc}
\tikzmark{11}{15} & 0 & \tikzmark{13}{0} &0\tikzmark{14} \\
0 & 50 & 20 & 25 \\
35 & 5 & 0 & 10\\
\tikzmark{41}{0} & 65 & \tikzmark{43}{50} & 65
\end{array}
\right].
\DrawLine[black,thick]{11}{14}
\DrawLine[black,thick]{11}{41}
\DrawLine[black,thick]{13}{43}
\end{displaymath}
The result looks like
But the result I want is
Does anyone know how to fix this?
Thank you.
Best Answer
Here is an adaption of Draw a line through one column of a matrix:
Notes:
tikzmark
package, but for this particular case it is simpler to not use that package: The custom defined\MyTikzmark
provides anchor points.north
and.south
which are automatically centered vertically. Similarly.east
and.west
are centered vertically. In thetikzmark
package version the lines were extended viashorten >=
andshorten <=
and shifted usingyshift
to provide similar results.Code: Without
tikzmark
package.Code: With
tikzmark
package.