包含表格(包含 2 行或更多行)的多行单元格

包含表格(包含 2 行或更多行)的多行单元格

当我在单元格中有一个长文本时,我会在该单元格上创建一个新表格,并将文本分成多行。其他列将自动对齐。但是,当我有多行时,其他列会混在一起。举个例子:

\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}

创建该表:

坏桌子

我想要这样的东西:

好桌子

有什么建议吗?

答案1

我没有解决方案\multirow,但我常说任何使用它的表都可以通过删除它来立即得到改进。;-)

以下是我实现表格的方法,请选择两种形式之一。

\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}

在此处输入图片描述

答案2

下面是两个使用makecell包及其makecell&\multirowcell命令的解决方案,第二个解决方案也使用booktabs,没有垂直线,大多数人认为这看起来更好 - 代码也更简单:

\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} 

在此处输入图片描述

在此处输入图片描述

答案3

在多行包中,行数实际上表示多行单元格之后单元格中的文本行数。这意味着,在给定的 mwe 中,第一个多行单元格的行数应为 4(请参阅下面的更正)。在我看来,这是多行包中的错误...

\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}

编辑: 在此处输入图片描述

相关内容