4

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

4

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.

  • 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. – user11232 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
4

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.

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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