# Putting a vertical line through text in a table

I am trying to strike through both vertically and horizontally in a table when working horizontally most methods work as row heights are all the same, however, a vertical strikethrough always ends up diagonally using the method outlined below

The relevant code in preamble:

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\newcommand{\DrawVLine}[3][]{%
\begin{tikzpicture}[overlay,remember picture]
\draw [#1] ($(#2.north)$) -- ($(#3.north)$);
\end{tikzpicture}%
}%
\newcommand{\DrawLine}[3][]{%
\begin{tikzpicture}[overlay,remember picture]
\draw [#1] ($(#2)+(-0.4,0.6ex)$) -- ($(#3)+(0.6,0.6ex)$);
\end{tikzpicture}%
}%


Relevant array:

$\begin{array}{|c|c|c|c|} \hline &Dig&\tikzmark{StartB}Weed&Cut\\ \hline Boris&50&0&50\\ \hline Percival&20&0&30\\ \hline \tikzmark{StartA}Spike&0&\tikzmark{EndB}0&\tikzmark{EndA}0\\ \hline \end{array}\\$
\DrawLine[red, very thick,dotted]{StartA}{EndA}
\DrawVLine[red,very thick,dotted]{StartB}{EndB}


However this ends up like this:

What I want is to have the red line centred in the column and straight, it is possible to adjust this by adding values to 2.north and 3.north but this is seperate for each table, meaning it is not robust enough for my use.

Although more of a workaround than a solution you could do something like this:

\documentclass{amsart}
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\newcommand{\DrawVLine}[3][]{%
\begin{tikzpicture}[overlay,remember picture]
\draw [#1] ($(#2.north)$) -- ($(#3.north)$);
\end{tikzpicture}%
}%
\newcommand{\DrawLine}[3][]{%
\begin{tikzpicture}[overlay,remember picture]
\draw [#1] ($(#2)+(-0.4,0.6ex)$) -- ($(#3)+(0.6,0.6ex)$);
\end{tikzpicture}%
}%

\begin{document}

$\begin{array}{|c|c|c|c|} \multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{\vspace{-.3cm}\tikzmark{StartB}}&\multicolumn{1}{c}{}\\\hline &Dig&Weed&Cut\\ \hline Boris&50&0&50\\ \hline Percival&20&0&30\\ \hline \tikzmark{StartA}Spike&0&0&\tikzmark{EndA}0\\ \hline \multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{\raisebox{.6\normalbaselineskip}{\tikzmark{EndB}}}&\multicolumn{1}{c}{}\\ \end{array}\\$
\DrawLine[red, very thick,dotted]{StartA}{EndA}
\DrawVLine[red,very thick,dotted]{StartB}{EndB}

\end{document}


Yields:

The downside of course is that you have two extra "invisible" rows.

A very simple solution with pstricks: defining four nodes and connecting them with the relevant parameters:

\documentclass[svgnames]{amsart}
\usepackage{array}
\usepackage{pst-node}
\usepackage{auto-pst-pdf} %% to compiile with pdflatex -shell-escape (TeX Live, MacTeX)
%% or pdflatex --enable-write18 (MiKTeX)

\begin{document}

$\begin{postscript} \setlength{\extrarowheight}{3pt} \begin{array}{|c|c|c|c|} \hline & Dig & \Rnode{W}{Weed} & Cut\\ \hline Boris & 50 & 0 & 50\\ \hline Percival & 20 & 0 & 30 \\ \hline \pnode[-4pt, 0.7ex]{A}Spike & 0 &\Rnode{O}{0} & 0\pnode[4pt, 0.7ex]{B} \\ \hline \end{array} %% Node connections: \psset{linewidth=0.6pt, linecolor=Crimson, linestyle=dashed, dash=3pt 3pt} \ncline[nodesep=-9pt]{W}{O} \ncline{A}{B} \end{postscript}$

\end{document}


• Is there a difference between pspicture and postscript environments? I'm not aware of postscript at this time? – pzorba75 Nov 6 '17 at 4:05
• @pzorba75: If I remember well, the postscript environment is known only to auto-pst-pdf. But you may as well use `pspicture (without dimensions, in such a case). – Bernard Nov 6 '17 at 7:57