TikZ-PGF – Fixing Vertical Strikethrough in Tables that is Too Long

tablestikz-pgf

So I just started using LateX yesterday and ran into a problem. I'm making a table where a number is circled and the whole row is crossed out. I found different codes on the internet and tried applying them to the table.
Here's the code:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,amssymb,amsthm, amsfonts}
\usepackage{tikz-inet}
\usepackage{graphicx}
\usetikzlibrary{matrix}
\usepackage{tikz}

Command to make circle:

\usetikzlibrary{fit,shapes.geometric}

\newcounter{nodemarkers}
\newcommand\circletext[1]{%
    \tikz[overlay,remember picture] 
        \node (marker-\arabic{nodemarkers}-a) at (0,1.5ex) {};%
    #1%
    \tikz[overlay,remember picture]
        \node (marker-\arabic{nodemarkers}-b) at (0,0){};%
    \tikz[overlay,remember picture,inner sep=2pt]
        \node[draw,ellipse,fit=(marker-\arabic{nodemarkers}-a.center) 
        (marker-\arabic{nodemarkers}-b.center)] {};%
    \stepcounter{nodemarkers}%
}

Command to make lines in the table:

\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, #1] (#2.north) -- (#3.south);
  \end{tikzpicture}
}

\newcommand{\DrawHLine}[3][]{%
  \begin{tikzpicture}[overlay,remember picture]
    \draw[shorten <=0.2em, #1] (#2.west) -- (#3.east);
  \end{tikzpicture}
}

The table:

\begin{document}
\begin{center}
\renewcommand{\arraystretch}{1.3}
  \begin{tabular}{c|cccc}
   \multicolumn {1}{c|}{} & 60 & 110 & 80 & 110 \\ \hline

    80 & \tikzmark{topA}{3}   & \tikzmark{topB}{10}   & 
    \tikzmark{topC}{20} & \tikzmark{topD}{ \circletext{0} }  \\  

    20 & 2 & 1 & 3 &        \tikzmark{rightB}{0}     \\ 
    50 & 2,5 & 3,5 & 4 &    \tikzmark{rightC}{0}    \\ 
    210 & 4 & 5 & 9 &       \tikzmark{rightD}{0}        \\ 
    \DrawVLine[blue, thick, opacity=0.8]{topD}{rightD}
  \end{tabular}
  \end{center}
\end{document}

The table looks like this

As you can see the vertical line is too long.

Can anyone tell me where the code went wrong?

If I try to remove

\DrawVLine[blue, thick, opacity=0.8]{topD}{rightD}

it looks fine though.

Best Answer

With this, you get correct lines

\begin{document}
\begin{center}
\renewcommand{\arraystretch}{1.3}
  \begin{tabular}{c|cccc}
   \multicolumn {1}{c|}{} & 60 & 110 & 80 & 110 \\ \hline

    80 & \tikzmark{topA}{3}   & \tikzmark{topB}{10}   &
    \tikzmark{topC}{20} & \tikzmark{topD}{ \circletext{0} }  \\

    20 & 2 & 1 & 3 &        \tikzmark{rightB}{0}     \\
    50 & 2,5 & 3,5 & 4 &    \tikzmark{rightC}{0}    \\
    210 & 4 & 5 & 9 &       \tikzmark{rightD}{0}          %% remove \\ here
  \end{tabular}
  \DrawVLine[blue, thick, opacity=0.8]{topD}{rightD}      %% move this after \end{tabular}
  \end{center}
\end{document}

enter image description here

The \\ in the last row introduces an additional row and the \DrawVLine has its natural place outside the tabular environment.