[Tex/LaTex] How to draw a vertical line in a table cell

tablestechnical-drawingtikz-pgf

I hope the explanation will be clear: I have a table with 4 rows, and one of the columns there is a value that is identical in all rows. I want instead of copying it 4 times for each row, just put it in the middle (between the 2nd and 3rd row) and have two vertical lines stretching above and below it up to to the 1st row and 4th row.

I managed to put the number using multirow in the middle, but I don't know how to draw the two vertical lines. Any ideas?

EDIT: I want the vertical lines to stretch from the middle above the number — up and one from the middle below the number down.

Best Answer

An overkill TikZ solution; the common value is vertically centered as required:

\documentclass{article}
\usepackage{multirow}
\usepackage{tikz}
\usetikzlibrary{calc}

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

\begin{document}

\noindent\begin{tabular}{cccc}
column 1a &\tikzmark{a}\multirow{4}{*}{\tikzmark{c}50\tikzmark{d}} & column 3a & column 4a \\
column 1b & & column 3b & column 4b \\
column 1c & & column 3c & column 4c \\
column 1d &\tikzmark{b} & column 3d & column 4d \\
\end{tabular}
\tikz[remember picture,overlay]
{
\draw let \p1=( $ (c)!0.5!(d) $ ) in ([yshift=9pt]\x1,\y1) -- ([yshift=3pt]\p1|-a.north);
\draw let \p1=( $ (c)!0.5!(d) $ ) in ([yshift=-2pt]\x1,\y1) -- (\p1|-b);
}
\end{document}

enter image description here

In a comment, JLDiaz has proposed the following simplification not requiring the use of \multirow and drawing the line with the value in a single step:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

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

\begin{document}

\noindent\begin{tabular}{cccc}
column 1a &\tikzmark{a} & column 3a & column 4a \\
column 1b & & column 3b & column 4b \\
column 1c & & column 3c & column 4c \\
column 1d &\tikzmark{b} & column 3d & column 4d \\
\end{tabular}

\tikz[remember picture,overlay]
{\draw ([yshift=1ex]a) -- (b) node[midway,fill=white] {50};}

\end{document}

enter image description here