Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
1  
MWE please..... |c| does not work for you? –  Harish Kumar Nov 30 '12 at 1:12
    
|c| is not what I am looking for -- because I want the line to stretch from the middle, not at the edges of the cell. I don't have an MWE, because I have nothing that works or doesn't work, unfortunately. –  kloop Nov 30 '12 at 1:16
2  
in the absence of a MWE, could you provide a picture to what you want? even if you have to draw it by hand :) –  cmhughes Nov 30 '12 at 1:19
    
also, why the tikz tag? –  cmhughes Nov 30 '12 at 1:48
    
@cmhughes because I suspected tikz could help here. and it actually did (see answer below). –  kloop Nov 30 '12 at 5:22
add comment

2 Answers 2

up vote 8 down vote accepted

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

share|improve this answer
    
an overkill, but works quite well... thanks! –  kloop Nov 30 '12 at 5:21
    
@Gonzalo_Medina: I would simplify that solution by omitting the multirow, leaving the first row simply as: column 1a &\tikzmark{a}& column 3a.... After this, the final line is drawn in a single stroke as \draw ([yshift=1ex]a) -- (b) node[midway,fill=white] {50};. <br/>Also, my \tikzmark definition uses [coordinate] option for the empty node. –  JLDiaz Nov 30 '12 at 9:26
    
@JLDiaz nice simplification. I've added it to my answer. Thank you! –  Gonzalo Medina Nov 30 '12 at 17:51
add comment

Here's an example which achieves the effect by create faux columns in which a multicolumn command will be called.

Here's MWE.

\documentclass{article}
\begin{document}
Create faux columns 2 and 3.

The hspaces in the first line are to make the centering work correctly.

\begin{tabular}[t]{cc|ccc}%
 1a & \hspace*{1em} & \hspace*{1em} & 3 & 4 \\
 1b & & & 3 & 4 \\
 1c & \multicolumn{2}{c}{value} & 3 & 4 \\
 1d & & & 3 & 4 \\
\end{tabular}


\end{document}

Is this what you're looking for?

enter image description here

share|improve this answer
    
this is what i to tried to get. btw is there a way to vertically center the content of second column automatically. i am thinking of some way to combine Gonzalo's and your solution. –  mythealias Nov 30 '12 at 1:45
    
this is a simple solution, and almost works but not quite -- because value is not centered between the 2nd row and 3rd row. thanks, though! –  kloop Nov 30 '12 at 5:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.