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?

  • 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 6 '13 at 19:40
  • What do you mean? I have no other choice than to create it like this. – Levi H May 6 '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., andrewjpage.com/?archives/…. – Andy Clifton May 6 '13 at 19:47
  • Hmm, what about wrapping and resizing individual cells? – Levi H May 6 '13 at 19:55
  • 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 6 '13 at 23:59
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.

  • 2
    Just out of curiosity, how long does it take you to whip up an example like this? – Ricardo May 6 '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 6 '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 7 '13 at 0: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 7 '13 at 3: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 7 '13 at 4:57

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.