0

I'm trying to write a table in LaTeX using multirows and multicolumns right in the header. I managed to get it just like I want it with this code (which I compiled easily in overleaf):

\documentclass[12pt,a4paper]{article}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage[margin=3cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{multirow}
\usepackage{array}


\begin{document}
\setlength\extrarowheight{2pt}%%precisei definir isso para dar meis espaço para a bottom rule da tabela
\noindent
\small
\centering
\begin{tabular}{ccccc}
    \toprule
    \multirow{2}{*}{\parbox{0.15\linewidth}{\centering Dimensão da Teoria do Fluxo}} \multirow{2}{*}{\parbox{0.15\linewidth}{\centering Componente do Framework}} & \multicolumn{3}{c}{\parbox{0.7\linewidth}{\centering Heurísticas}} \\ %%defini parboxes para setar as dimensões de cada coluna de acordo com a margem do texto.
    \cmidrule{2-4}
     & &
    \parbox{0.1\linewidth}{\centering N} &
    \parbox{0.3\linewidth}{\centering Descrição detalhada} & 
    \parbox{0.3\linewidth}{\centering Referências CALL} \\
    \midrule
    \bottomrule
  \end{tabular}
\end{document}

It gives me the following table:

my table

However, as soon as I enter some lines, the table gets stretched and it's not entering data according to my 5-cell rule, I don't know why!

enter image description here

2
  • 1
    Welcome to TeX.SE! In the future, you can copy and paste code into your question, I have copied it from dropbox into your question (if the edit is approved). There is a symbol that looks like {}, this formats code in the question, hope someone can help!
    – JamesT
    Feb 17 at 17:56
  • 2
    Please provide some more information as to what "as soon as I enter some lines" entails.
    – Mico
    Feb 17 at 18:40

1 Answer 1

1
  • It is not entirely clear how your table should look, so proposed possible solution is based on guessing what you after
  • I would not use \parboxes for text in table cells. Instead of it I would rather prescribe of column widths
  • Splitting cells in the first columns lead to troubles. Better is divide column into two columns in where is needed, merge adjacent columns into \multicolumn cell.
  • In MWE below is assumed that you like to have multi column cells only at first two column, so for this columns are defined special new command.
  • For more sophisticate table structure can be managed by use Tabularray package. However, for its use I need more information about your table (so please extend your table code to more rows (with some dummy text),
\documentclass[12pt,a4paper]{article}
\usepackage[margin=3cm]{geometry}% http://ctan.org/pkg/geometry
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{tabularx}
\newcolumntype{C}[1]{>{\hsize=#1\hsize%
                       \centering\arraybackslash}X}
\NewExpandableDocumentCommand\mcxx{m}
{\multicolumn{2}
             {>{\centering\arraybackslash}p{%
                    \dimexpr.3\linewidth+2\tabcolsep+\arrayrulewidth}}
             {#1}
}



\begin{document}
\setlength\extrarowheight{2pt}%%precisei definir isso para dar meis espaço para a bottom rule da tabela
\noindent
\small
\renewcommand\multirowsetup{\centering}%
\begin{tabularx}{\textwidth}{@{}    C{0.15} C{0.15}
                                    c
                                    C{0.3}  C{0.3}
                             @{}}
    \toprule
\multirow{2}{=}{Dimensão da Teoria do Fluxo}
    &   \multirow{2}{=}{Componente do Framework}
        & \multicolumn{3}{c}{Heurísticas}           \\
    \cmidrule(l){3-5}
    &   &   N
            &   Descrição detalhada
                &       Referências CALL            \\
    \midrule
\mcxx{some quite long text over three columns}
            &   &                                   \\
    \midrule
A   & B & C & D & E                                 \\
    \bottomrule
  \end{tabularx}
\end{document}

enter image description here

(red lines indicate document pages layouts)

2
  • my table isn't just large, it's really big too. I migrated to longtablearray(longtablr) a while ago (I developed my table a bit more: tex.stackexchange.com/questions/675637/…), but I can't make it so that the table gets large (so it occupies the whole paper width), AND also gets in 2 pages. do you know how? Feb 17 at 22:44
  • @FabioPhillip, it seems that question in your link is follows up question where you already use codes from my answer on this question. If so, make this question solved by accepting it (click on the check mark at top left side of answer). I would try to answer on newer question.
    – Zarko
    Feb 18 at 7:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .