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 have the following code that produces the table that is shown. What I am trying to do is to get the fourth and fifth column titles vertically aligned at the top. Is this possible?

\documentclass{article}
\usepackage{multirow}
\usepackage{array}

\newcolumntype{x}[1]{%
>{\raggedright\hspace{0pt}}p{#1}}%

\begin{document}
\centering
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{| m{2cm} | p{2cm} | p{2cm} | p{2cm} | p{2cm} | p{2cm} |} \hline
    \multirow{3}{1.7cm}{Data Set} &%
    \multicolumn{3}{c |}{Raw Data} &%
    Offline Processing Time &
    Index Size (KB)\\ \cline{2-4}
%
    & %
    RDF N3 File SizeKB (sec)    &%
    Number of Triples &%
    Number of Entities\\    \hline
\end{tabular}
\end{document}

enter image description here

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Better don't use them (vertical lines) at all!

I think your problem is missing vertical lines. You have to use the ampersands even if those cells are empty, like

Number of Entities & & \\    \hline

You are done as those titles are already aligned at the top.

share|improve this answer
    
Thank you. But I don't understand what you mean by "Better don't use them at all" –  ozsu Oct 6 '12 at 23:53
    
@ozsu have a look at the booktabs package –  cmhughes Oct 6 '12 at 23:55
    
@ozsu: They are not considered as good typographical practice as they reduce readability. See cmhughe's comment above about `booktab manual. –  Harish Kumar Oct 6 '12 at 23:57
    
Got it. Learning booktabs is on my list of things to do, but I'm trying to finish a paper first. Thanks much. –  ozsu Oct 7 '12 at 0:03

Not sure if this is the desired layout:

\documentclass{article}
\usepackage{multirow}
\usepackage{array}

\newcolumntype{x}[1]{%
>{\raggedright\arraybackslash\hspace{0pt}}p{#1}}%

\begin{document}
\centering
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{| m{2cm} | x{2cm} | x{2cm} | x{2cm} | x{2cm} | x{2cm} |} \hline
    \multirow{4}{*}{Data Set} &%
    \multicolumn{3}{c |}{Raw Data} &%
    \multirow{3}{2cm}{Offline Processing Time} &
    \multirow{3}{2cm}{Index Size (KB)}\\ \cline{2-4}
%
    & %
    RDF N3 File SizeKB (sec)    &%
    Number of Triples &%
    Number of Entities & &\\    \hline
\end{tabular}
\end{document}

enter image description here

Some remarks: the lines were missing because you didn't complete the columns in the last row (adding the necessary & characters). Also, since you have narrow columns, it is better to have the contents \ragedright, so I changed your p{} columns to x{} columns (adding \arraybackslash).

You should consider not using vertical rules in your tables; the booktabs package discusses this and helps you to create better looking tables.

share|improve this answer
    
Thanks for fixing this. I was going to use the x{} only after I solved this problem, but I missed the \arraybackslash. Thanks again. –  ozsu Oct 7 '12 at 0:04

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.