3

When I have a long text inside a cell, I create a new table on that cell and break the text in many lines. The other columns will automatically aligned. But, when I have a multirow, the others columns get mixed. An example:

\documentclass{article}
\usepackage{multirow}
\usepackage[latin1]{inputenc}
\begin{document}

\begin{tabular}{llrrr}
\hline
\multirow{2}{*}{Sexo} & \multirow{2}{*}{\begin{tabular}{@{\hskip 0pt}l} Você concorda que o \\ Brasil não deveria \\ ter aceitado \\ realizar a copa? \end{tabular}} & \multicolumn{3}{|c}{Estado} \\ \cline{3-5} 
 &  & \multicolumn{1}{|c}{PR} & \multicolumn{1}{|c}{RS} & \multicolumn{1}{|c}{SC} \\ \hline 
\multirow{5}{*}{Feminino} & \multicolumn{1}{l|}{Concordo} & 40 & 32 & 51 \\  
 & \multicolumn{1}{l|}{Concordo fortemente} & 33 & 35 & 30 \\  
 & \multicolumn{1}{l|}{Discordo} & 29 & 35 & 28 \\  
 & \multicolumn{1}{l|}{Discordo fortemente} & 42 & 34 & 35 \\  
 & \multicolumn{1}{l|}{\begin{tabular}{@{\hskip 0pt}l} Não concordo nem \\ discordo \end{tabular}} & 25 & 30 & 23 \\ \cline{1-5} 
\multirow{5}{*}{Masculino} & \multicolumn{1}{l|}{Concordo} & 31 & 35 & 51 \\  
 & \multicolumn{1}{l|}{Concordo fortemente} & 26 & 40 & 36 \\  
 & \multicolumn{1}{l|}{Discordo} & 26 & 38 & 34 \\  
 & \multicolumn{1}{l|}{Discordo fortemente} & 31 & 31 & 37 \\  
 & \multicolumn{1}{l|}{\begin{tabular}{@{\hskip 0pt}l} Não concordo nem \\ discordo \end{tabular}} & 30 & 25 & 27 \\ \hline 
\end{tabular}
\end{document}

Creates this table:

Bad table

And I want something like this:

Good table

Any suggestion?

4

I don't have a solution for \multirow, but I use to say that any table using it can be immediately improved by removing it. ;-)

Here's how I'd realize the table, choose one of the two forms.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs,siunitx}

\begin{document}

\begin{tabular}{l*{3}{S[table-format=2.0]}}
\toprule
\multicolumn{4}{c}{Você concorda que o Brasil não deveria} \\
\multicolumn{4}{c}{ter aceitado realizar a copa?} \\
\midrule[\heavyrulewidth]
& \multicolumn{3}{c}{Estado} \\
\cmidrule{2-4}
& {PR} & {RS} & {SC} \\
\midrule
\bfseries Feminino \\
Concordo                  & 40 & 32 & 51 \\  
Concordo fortemente       & 33 & 35 & 30 \\  
Discordo                  & 29 & 35 & 28 \\  
Discordo fortemente       & 42 & 34 & 35 \\  
Não concordo nem discordo & 25 & 30 & 23 \\
\midrule
\bfseries Masculino \\
Concordo                  & 31 & 35 & 51 \\  
Concordo fortemente       & 26 & 40 & 36 \\  
Discordo                  & 26 & 38 & 34 \\  
Discordo fortemente       & 31 & 31 & 37 \\  
Não concordo nem discordo & 30 & 25 & 27 \\
\bottomrule
\end{tabular}
\qquad
\begin{tabular}{l*{3}{S[table-format=2.0]}}
\toprule
\multicolumn{4}{c}{Você concorda que o Brasil não deveria} \\
\multicolumn{4}{c}{ter aceitado realizar a copa?} \\
\midrule[\heavyrulewidth]
& \multicolumn{3}{c}{Estado} \\
\cmidrule{2-4}
& {PR} & {RS} & {SC} \\
\midrule
\addlinespace
\multicolumn{4}{c}{\bfseries Feminino} \\
\addlinespace
Concordo                  & 40 & 32 & 51 \\  
Concordo fortemente       & 33 & 35 & 30 \\  
Discordo                  & 29 & 35 & 28 \\  
Discordo fortemente       & 42 & 34 & 35 \\  
Não concordo nem discordo & 25 & 30 & 23 \\
\midrule
\addlinespace
\multicolumn{4}{c}{\bfseries Masculino} \\
\addlinespace
Concordo                  & 31 & 35 & 51 \\  
Concordo fortemente       & 26 & 40 & 36 \\  
Discordo                  & 26 & 38 & 34 \\  
Discordo fortemente       & 31 & 31 & 37 \\  
Não concordo nem discordo & 30 & 25 & 27 \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

1
  • Very good example of table re-organisation.
    – user11232
    May 22 '14 at 23:32
1

Here are two solutions using the makecell package and its makecell & \multirowcell commands, the second using also booktabs, without vertical lines, that looks better in the opinion of most — the code is also simpler:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{array}
\usepackage{multirow}
\usepackage{booktabs}

\usepackage{makecell}
\renewcommand\cellalign{lc}

\begin{document}

\begin{tabular}{ll|rrr}
\hline
\multirowcell{4}{Sexo} & \multirowcell{4}{Você concorda que o \\ Brasil não deveria \\ ter aceitado \\ realizar a copa?}& \multicolumn{3}{c}{\multirow{2}{*}{Estado}} \\
 & & & &\\
 \cline{3-5}
 & & \multicolumn{1}{c|}{\multirowcell{2} {PR}} & \multicolumn{1}{c|}{\multirowcell{2} {RS}} & \multirowcell{2} {SC} \\
  & & \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{} & \\
 \hline
\multirowcell{6}{Feminino} & Concordo & 40 & 32 & 51 \\
 & Concordo fortemente & 33 & 35 & 30 \\
 & Discordo & 29 & 35 & 28 \\
 & Discordo fortemente & 42 & 34 & 35 \\
 & \makecell{Não concordo nem \\ discordo } & 25 & 30 & 23 \\
 \cline{1-5}
\multirowcell{6} {Masculino} & Concordo & 31 & 35 & 51 \\
 & Concordo fortemente & 26 & 40 & 36 \\
 & Discordo & 26 & 38 & 34 \\
 & Discordo fortemente & 31 & 31 & 37 \\
 & \makecell{Não concordo nem \\ discordo} & 30 & 25 & 27 \\
 \hline
\end{tabular}
\clearpage

\begin{tabular}{ll rrr}
\toprule
\multirowcell{4}{Sexo} & \multirowcell{4}{Você concorda que o \\ Brasil não deveria \\ ter aceitado \\ realizar a copa?}& \multicolumn{3}{c}{\multirow{2}{*}{Estado}} \\
 & & & &\\
 \cmidrule{3-5}
 & & \multirowcell{2} {PR} & \multirowcell{2} {RS} & \multirowcell{2} {SC} \\
  & & & & \\
 \midrule
\multirowcell{6}{Feminino} & Concordo & 40 & 32 & 51 \\
 & Concordo fortemente & 33 & 35 & 30 \\
 & Discordo & 29 & 35 & 28 \\
 & Discordo fortemente & 42 & 34 & 35 \\
 & \makecell{Não concordo nem \\ discordo } & 25 & 30 & 23 \\
 \midrule
\multirowcell{6}{Masculino} & Concordo & 31 & 35 & 51 \\
 & Concordo fortemente & 26 & 40 & 36 \\
 & Discordo & 26 & 38 & 34 \\
 & Discordo fortemente & 31 & 31 & 37 \\
 & \makecell{Não concordo nem \\ discordo} & 30 & 25 & 27 \\
 \bottomrule
\end{tabular}

\end{document} 

enter image description here

enter image description here

1

In the multirow package the number a row actually means number of text lines which folowos in cels after multirow cell. This means, that in given mwe the first multirow cell should have 4 for number of rows (see correction below). This seem to me as bug in multirow package ...

\documentclass{article}
\usepackage{multirow}
\usepackage[latin1]{inputenc}
\begin{document}

\begin{tabular}{llrrr}
\hline
\multirow{4}{*}{Sexo} 
    &   \multirow{4}{*}{\begin{tabular}{@{\hskip 0pt}l} 
        Você concorda que o \\ 
        Brasil não deveria  \\ 
        ter aceitado        \\ 
        realizar a copa? 
                        \end{tabular}} 
        &   \multicolumn{1}{|c}{}                                   \\
    &   &   \multicolumn{3}{|c}{Estado}                             \\
    &   &   \multicolumn{1}{|c}{}                                   \\
\cline{3-5}
    &   &   \multicolumn{1}{|c}{PR}
            &   \multicolumn{1}{|c}{RS}
                &   \multicolumn{1}{|c}{SC}                         \\
\hline
    \multirow{6}{*}{Feminino} 
    &   \multicolumn{1}{l|}{Concordo}               & 40 & 32 & 51  \\
    &   \multicolumn{1}{l|}{Concordo fortemente}    & 33 & 35 & 30  \\
    &   \multicolumn{1}{l|}{Discordo}               & 29 & 35 & 28  \\
    &   \multicolumn{1}{l|}{Discordo fortemente}    & 42 & 34 & 35  \\
    &   \multicolumn{1}{l|}{\begin{tabular}{@{\hskip 0pt}l} 
        Não concordo \\ 
        nem discordo 
                            \end{tabular}}          & 25 & 30 & 23         \\ 
\hline
\multirow{6}{*}{Masculino} 
    &   \multicolumn{1}{l|}{Concordo}               & 31 & 35 & 51  \\
    &   \multicolumn{1}{l|}{Concordo fortemente}    & 26 & 40 & 36  \\
    &   \multicolumn{1}{l|}{Discordo}               & 26 & 38 & 34  \\
    &   \multicolumn{1}{l|}{Discordo fortemente}    & 31 & 31 & 37  \\
    &   \multicolumn{1}{l|}{\begin{tabular}{@{\hskip 0pt}l} 
        Não concordo \\ 
        nem  discordo       \end{tabular}}          & 30 & 25& 27   \\
\hline
    \end{tabular}
\end{document}

Edit: enter image description here

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.