I am trying to create a complex table to define a lot of concepts, that can have subconcepts with their own definitions.
Right now, my problem is controlling the width of every column of the table. Because the definitions use more than one line and can get pretty long, LaTeX does not break the line like I'm used to do at normal tables. For that, I tend to use p{0.X\columnwidth} instead of l/c/r, but it doesn't seem to work here.
Right now, the goals to attain for this table are:
- Make it autofit content inside the cell in an automatic/semi-automatic way (i.e.: without manually doing a line break);
- Vertically and horizontally center every cell that is not a definition;
- Make the whole table fit inside a page.
Here is a small example already built:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\begin{document}
\begin{table}[]
\begin{tabular}{p{0.1\columnwidth}p{0.1\columnwidth}p{0.1\columnwidth}p{0.5\columnwidth}}
\hline
\multirow{11}{*}{A} & \multicolumn{3}{l}{Definition of A} \\ \cline{2-4}
& \multirow{5}{*}{A1} & \multicolumn{2}{l}{Definition of A1} \\ \cline{3-4}
& & A11 & Definition of A11 \\ \cline{3-4}
& & A12 & Definition of A12 \\ \cline{3-4}
& & A13 & Definition of A13 \\ \cline{3-4}
& & A14 & Definition of A14 \\ \cline{2-4}
& A2 & \multicolumn{2}{l}{Definition of A2} \\ \cline{2-4}
& \multirow{4}{*}{A3} & \multicolumn{2}{l}{Definition of A3} \\ \cline{3-4}
& & A31 & Definition of A31 \\ \cline{3-4}
& & A32 & Definition of A32 \\ \cline{3-4}
& & A33 & Definition of A33 \\ \hline
\multirow{4}{*}{B} & \multicolumn{3}{l}{Definition of B} \\ \cline{2-4}
& B1 & \multicolumn{2}{l}{Definition of B1} \\ \cline{2-4}
& B2 & \multicolumn{2}{l}{Definition of B2} \\ \cline{2-4}
& B3 & \multicolumn{2}{l}{Definition of B3} \\ \hline
\multirow{3}{*}{C} & \multicolumn{3}{l}{Definition of C} \\ \cline{2-4}
& C1 & \multicolumn{2}{l}{Definition of C1} \\ \cline{2-4}
& C2 & \multicolumn{2}{l}{Definition of C1} \\ \hline
\end{tabular}
\end{table}
\end{document}
Unfortunately
multirowcan't deal well with this kind of table, because it doesn't get information of LaTeX'stabularabout the heights of the table cells. So you would have to count the actual number of lines that the cells occupy, which is annoying.This kind of table is much easier to do with the
tabularraypackage, which has its own implementation of the table mechanism which does have this kind of information available. Actually it is possible to use most of your code by just replacing\usepackage{tabular}with\usepackage{tabularray}and thetabularenvironment withtblr. However, althoug the\multirows will be properly positioned, you will not get the full power oftabularray, for example the entries will not be horizontally centered. Moreover, support for\multirowand\multicolumnintabularraywill disappear in a future version. So I rewrote it to use the syntax thattabularrayhas for these cases with\SetCell. A few remarks to begin with:tabularyou would use expressions like0.7\textwidth+2\tabcolsepto calculate the width of a\multicolumn. However,tabularraydoesn't use\tabcolsep. Instead it hasleftsepandrightsepparameters. These are available as\leftsepand\rightsepinside a cell, but unfortunately they are not set outside the cell, for example in a width specification. Therefor I (ab)used\tabcolsepin the width calculation, and setcolsep=\tabcolsepwhich sets bothleftsepandrightsep.tabularrayuses\raggedrightinternally forlandpcolumns, but with the standard LaTeX definitions this makes hyphenation very difficult. Therefore I used theragged2epackage to get better definitions for this. It has to be included beforetabularrayto work properly.\Mdoisand\Mtresfor the\multicolumn{2}and{3}cells. I included the\justifyingcommand (from theragged2epackage) to get fully justified text. You can leave this out if you don't want the text to be justified.cells={c,m}to get the cells both horizontally and vertically centered by default. I also usedm{}type column specifiers for vertical centering in the larger text columns.rowsep=1ptto get the rows closer to each other. Still I had to use\smallto get everything fit on the page. Actually the table is sticking into the page footer, so you might have to use an even smaller font size, like\footnotesize.\hspace{0pt}before it. I made a macro\HHfor this and put that before some large words like "Confidencialidade". You could actually put that in the column definition if you want.\multirowor\multicolumnstill have braces{...}around them although that is not longer necessary (they are not parameters of the\SetCell,\Mdoisor\Mtres. I thought it was too much work to remove them and they don't harm.So here is the solution. I reduced it to the minimum necessary for the table.