8

table

The above can easily be created in MS word, but how can I create something like this in latex? Basically changing the columns for specific cells, merging a bunch of cells together, wrapping text in a cell?

doncherry
  • 54,637
Levi H
  • 1,511
  • 5
    No offense but the reason it can be replicated in Word is because Word has no consciousness about what you are doing :P – percusse May 06 '13 at 19:40
  • What do you mean? I have no other choice than to create it like this. – Levi H May 06 '13 at 19:46
  • I think you answered your own question quite well. Add the multirow package (\usepackage{multirow}). Starting with a regular grid of cells, use \multirow and \multicolumn to define the cells you need. See e.g., http://www.andrewjpage.com/?archives/43-Multirow-and-multicolumn-spanning-with-latex-tables.html. – Andy Clifton May 06 '13 at 19:47
  • Hmm, what about wrapping and resizing individual cells? – Levi H May 06 '13 at 19:55
  • Try creating something similar in Excel, and then use excel2latex – Herr K. May 06 '13 at 20:13
  • 1
    @percusse I would be astounded if Word, or LaTeX to that matter, will ever have any consciousness about anything at all. :P – NVaughan May 06 '13 at 23:59

1 Answers1

14

To merge columns, you can use the \multicolumn command; to merge rows, you can use \multirow (from the multirow package); to have text wrapping, you can use columns of p{<length>} type; a little example:

\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage{tabularx}
\usepackage{array}
\usepackage{multirow}

\newlength\Colwd
\setlength\Colwd{1.2cm}

\begin{document}

\noindent\begin{tabular}{| p{\Colwd} | p{0.5\Colwd} | p{0.5\Colwd} *{7}{|p{\Colwd}} |}
\hline
& & \multicolumn{2}{p{1.5\Colwd}|}{} & \multicolumn{2}{p{2\Colwd}|}{\multirow{3}{*}{}} & & & & \\
\cline{1-4}\cline{7-10}
& & \multicolumn{2}{p{1.5\Colwd}|}{} & \multicolumn{2}{p{2\Colwd}|}{} & & & & \\
\cline{1-4}\cline{7-10}
& & \multicolumn{2}{p{1.5\Colwd}|}{} & \multicolumn{2}{p{2\Colwd}|}{} & & & & \\
\hline
& \multicolumn{2}{p{\Colwd}|}{} & & \multicolumn{6}{p{2\Colwd}|}{} \\
\hline
& \multicolumn{2}{p{\Colwd}|}{} & & \multicolumn{6}{p{2\Colwd}|}{} \\
\hline
& \multicolumn{2}{p{\Colwd}|}{} & & & & & & & \\
\hline
& \multicolumn{2}{p{\Colwd}|}{} & & & & & & & \\
\hline
\multicolumn{4}{|p{3\Colwd}|}{\multirow{5}{*}{}} & \multicolumn{3}{p{3\Colwd}|}{\multirow{5}{*}{}} & \multicolumn{3}{p{3\Colwd}|}{\multirow{5}{*}{}} \\
\multicolumn{4}{|p{3\Colwd}|}{} & \multicolumn{3}{p{3\Colwd}|}{} & \multicolumn{3}{p{3\Colwd}|}{} \\
\multicolumn{4}{|p{3\Colwd}|}{} & \multicolumn{3}{p{3\Colwd}|}{} & \multicolumn{3}{p{3\Colwd}|}{} \\
\multicolumn{4}{|p{3\Colwd}|}{} & \multicolumn{3}{p{3\Colwd}|}{} & \multicolumn{3}{p{3\Colwd}|}{} \\
\multicolumn{4}{|p{3\Colwd}|}{} & \multicolumn{3}{p{3\Colwd}|}{} & \multicolumn{3}{p{3\Colwd}|}{} \\
\hline
\end{tabular}

\end{document}

enter image description here

Since there was no definitive information about the real content for the cells, I set every one of them to be of p{...} type (paragraph-type); it's well known this kind of column is not very suitable for long texts. Narrow columns would be better set of type l, r, or c.

Moriambar
  • 11,466
Gonzalo Medina
  • 505,128
  • 2
    Just out of curiosity, how long does it take you to whip up an example like this? – Ricardo May 06 '13 at 23:49
  • 2
    @Ricardo I wouldn't know exactly how long, but I'd say no more than 15 minutes? – Gonzalo Medina May 06 '13 at 23:54
  • Thanks. That seemed like it would take me about 20 minutes and more pain than warranted. So many lines! – Ricardo May 07 '13 at 00:34
  • 1
    @Ricardo Actually with a serious editor (nvi user here) and help of some scripting language (I use mostly combination of sed, AWK, and ksh) such table can be cooked in surprisingly little time. – Predrag Punosevac May 07 '13 at 03:29
  • @PredragPunosevac, could I entice you into working the example above as an answer to this question? Not the final result, but the workflow. I use a combination of org-modein Emacs, "Save as CSV" in Excel and pgfplotstable, but when it comes to multirows and multicolumns I get sad, sigh in resignation and just go at it by hand after creating an initial template. – Ricardo May 07 '13 at 04:57