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?
1 Answer
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}
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
.
-
2Just out of curiosity, how long does it take you to whip up an example like this?– RicardoCommented May 6, 2013 at 23:49
-
2@Ricardo I wouldn't know exactly how long, but I'd say no more than 15 minutes? Commented May 6, 2013 at 23:54
-
Thanks. That seemed like it would take me about 20 minutes and more pain than warranted. So many lines!– RicardoCommented May 7, 2013 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. Commented May 7, 2013 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-mode
in Emacs, "Save as CSV" in Excel andpgfplotstable
, 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.– RicardoCommented May 7, 2013 at 4:57
\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/….