Eu tenho uma tabela com título horizontal acima das múltiplas colunas. Em alguns casos, o título horizontal é mais largo que as múltiplas colunas. Isso resulta em colunas distribuídas de forma não igual que não parecem boas. Preciso corrigir esse problema distribuindo igualmente as colunas pelo espaço. Este é um exemplo de script com afigure.
\documentclass[10pt]{article}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}
\newcommand{\xmark}{\ding{55}}
\newcommand*\rot{\rotatebox{90}}
\begin{document}
\begin{table}
\caption{MyTable}
\centering
\resizebox{\textwidth}{!} {
\begin{tabular} {@{} lc*{14}l @{}}
\hline
\\
\multicolumn{1}{c}{Column1}
&&\multicolumn{3}{c}{Column2}
&&\multicolumn{3}{c}{ColumnLongTitle}
&&\multicolumn{2}{c}{Column3}
&&\multicolumn{2}{c}{Column4}
\\
\cmidrule(lr){1-1}
\cmidrule(lr){3-5}
\cmidrule(lr){7-9}
\cmidrule(lr){11-12}
\cmidrule(lr){14-15}
\\
& \vline &\rot{Title1} & \rot{Title2} & \rot{Title3}
& \vline & \rot{Title1} & \rot{Title2} & \rot{Title3}
& \vline & \rot{Title1} & \rot{Title2}
& \vline & \rot{Title1} & \rot{Title2}
\\ \hline
Row1 & \vline & {} & \cmark & {} & \vline & \cmark & {} & {} & \vline & & \cmark & \vline & \cmark & {} & \\
\hline
Row2 & \vline & \cmark & {} & {} & \vline & \cmark & {} & {} & \vline & {} & \cmark & \vline & \cmark & {} & \\
\hline
Row3 & \vline & {} & \cmark & {} & \vline & \cmark & {} & {} & \vline & {} & \cmark & \vline & \cmark & {} & \\
\hline
\end{tabular}
}
\end{table}
\end{document}
EDITAR 2:Tentei a solução fornecida por @Bernard. Mas há outro problema. Quando preciso adicionar texto longo na primeira linha, toda a tabela fica distorcida. Você pode esclarecer como evitar esse problema. O comprimento do meu texto varia. Tenho um texto bastante longo na célula mais à esquerda de cada linha. Este é um exemplo de script que você pode executar para ver o problema.
\documentclass[10pt]{article}
%\usepackage{showframe}
%\renewcommand\ShowFrameLinethickness{0.3pt}
\usepackage{graphicx}
\usepackage{booktabs, tabularx, caption, makecell}
\setcellgapes{3pt}
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}
\newcommand{\xmark}{\ding{55}}
\newcommand*\rot{\rotatebox{90}}
\begin{document}
\begin{table}
\caption{MyTable}
\centering\makegapedcells
\begin{tabularx}{\linewidth}{@{} l|*{3}{>{\centering\arraybackslash}X} |*{3}{>{\centering\arraybackslash}X}| *{2}{>{\centering\arraybackslash}X}| *{2}{>{\centering\arraybackslash}X}|@{}}
\hline
\multicolumn{1}{c}{Column1}
&\multicolumn{3}{c}{Column2}
&\multicolumn{3}{c}{ColumnLongTitle}
&\multicolumn{2}{c}{Column3}
&\multicolumn{2}{c}{Column4}
\\
\cmidrule(lr){1-1}
\cmidrule(lr){2-4}
\cmidrule(lr){5-7}
\cmidrule(lr){8-9}
\cmidrule(lr){10-11}
\addlinespace
&\rot{Title1} & \rot{Title2} & \rot{Title3}
& \rot{Title1} & \rot{Title2} & \rot{Title3}
& \rot{Title1} & \rot{Title2}
& \rot{Title1} & \rot{Title2}
\\\hline
AAAAAAAAAAAAAAAAAAAAAAAA & {} & \cmark & {} & \cmark & {} & {} & & \cmark & \cmark & {} \\
\hline
Row2 & \cmark & {} & {} & \cmark & {} & {} & {} & \cmark & \cmark & {} \\
\hline
Row3 & {} & \cmark & {} & \cmark & {} & {} & {} & \cmark & \cmark & {} \\
\hline
\end{tabularx}
\end{table}
\end{document}
Responder1
Você pode tornar a largura natural das colunas mais larga que o vão. Também me livrei de todas as colunas vazias porque pareciam confusas.
\documentclass[10pt]{article}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}
\newcommand{\xmark}{\ding{55}}
\newcommand*\rot[1]{\rotatebox{90}{#1 }}
\usepackage{array}
\begin{document}
\begin{table}
\caption{MyTable}
\setlength\extrarowheight{4pt}
\centering
%\resizebox{\textwidth}{!} {% scaling tables is evil but of you do do it,. you need a % here
\begin{tabular*}{\textwidth} {@{\extracolsep{\textwidth minus \textwidth}}
l|ccc|ccc|cc|cc@{}}
\hline
\multicolumn{1}{@{}c}{Column1}
&\multicolumn{3}{c}{Column2}
&\multicolumn{3}{c}{\makebox[0pt]{ColumnLongTitle}}
&\multicolumn{2}{c}{Column3}
&\multicolumn{2}{c@{}}{Column4}
\\
\cmidrule(lr){1-1}
\cmidrule(lr){2-4}
\cmidrule(lr){5-7}
\cmidrule(lr){8-9}
\cmidrule(lr){10-11}
\multicolumn{1}{@{}c}{}
&\rot{Title1} & \rot{Title2} & \rot{Title3}
& \rot{Title1} & \rot{Title2} & \rot{Title3}
& \rot{Title1} & \rot{Title2}
& \rot{Title1} & \rot{Title2}
\\ \hline
Row1 & & \cmark & & \cmark & & & & \cmark & \cmark & \\
\hline
Row2 & \cmark & & & \cmark & & & & \cmark & \cmark & \\
\hline
Row3 & & \cmark & & \cmark & & & &\cmark & \cmark & \\
\hline
\end{tabular*}
\end{table}
\end{document}
Responder2
Uma solução com tabularx
e makecell
. Removi as linhas verticais e a coluna vazia. Se o cabeçalho da coluna for dois alargados, escreva-o em um \thead
comando, que permite quebras.
\documentclass[10pt]{article}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.3pt}
\usepackage{graphicx}
\usepackage{booktabs, tabularx, caption, makecell}
\setcellgapes{3pt}
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}
\newcommand{\xmark}{\ding{55}}
\newcommand*\rot{\rotatebox{90}}
\begin{document}
\begin{table}
\caption{MyTable}
\centering\makegapedcells
\begin{tabularx}{\linewidth}{@{} l|*{3}{>{\centering\arraybackslash}X} |*{3}{>{\centering\arraybackslash}X}| *{2}{>{\centering\arraybackslash}X}| *{2}{>{\centering\arraybackslash}X}|@{}}
\hline
\multicolumn{1}{c}{Column1}
&\multicolumn{3}{c}{Column2}
&\multicolumn{3}{c}{ColumnLongTitle}
&\multicolumn{2}{c}{Column3}
&\multicolumn{2}{c}{Column4}
\\
\cmidrule(lr){1-1}
\cmidrule(lr){2-4}
\cmidrule(lr){5-7}
\cmidrule(lr){8-9}
\cmidrule(lr){10-11}
\addlinespace
&\rot{Title1} & \rot{Title2} & \rot{Title3}
& \rot{Title1} & \rot{Title2} & \rot{Title3}
& \rot{Title1} & \rot{Title2}
& \rot{Title1} & \rot{Title2}
\\\hline
Row1 & {} & \cmark & {} & \cmark & {} & {} & & \cmark & \cmark & {} \\
\hline
Row2 & \cmark & {} & {} & \cmark & {} & {} & {} & \cmark & \cmark & {} \\
\hline
Row3 & {} & \cmark & {} & \cmark & {} & {} & {} & \cmark & \cmark & {} \\
\hline
\end{tabularx}
\end{table}
\end{document}
Uma variante, se as células na primeira coluna contiverem texto mais longo: a primeira coluna é uma X
coluna de tipo, duas vezes mais larga que o pacote de geometria 10 other
X columns in the cell. Also, I loaded the
, para margens horizontais mais sensíveis se você não tiver notas marginais:
\documentclass[10pt]{article}
\usepackage[showframe]{geometry}
\usepackage{graphicx}
\usepackage{booktabs, tabularx, caption, makecell}
\setcellgapes{3pt}
\newcolumntype{Y}{ >{\hsize=2\hsize\arraybackslash}X}
\newcolumntype{Z}{ >{\hsize=0.9\hsize\centering\arraybackslash}X}
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}
\newcommand{\xmark}{\ding{55}}
\newcommand*\rot{\rotatebox{90}}
\begin{document}
\begin{table}
\caption{MyTable}
\centering\makegapedcells
\begin{tabularx}{\linewidth}{@{}Y|*{3}{Z} |*{3}{Z}| *{2}{Z}| *{2}{Z}|@{}}
\hline
\multicolumn{1}{c}{Column1}
&\multicolumn{3}{c}{Column2}
&\multicolumn{3}{c}{ColumnLongTitle}
&\multicolumn{2}{c}{Column3}
&\multicolumn{2}{c}{Column4}
\\
\cmidrule(lr){1-1}
\cmidrule(lr){2-4}
\cmidrule(lr){5-7}
\cmidrule(lr){8-9}
\cmidrule(lr){10-11}
\addlinespace
&\rot{Title1} & \rot{Title2} & \rot{Title3}
& \rot{Title1} & \rot{Title2} & \rot{Title3}
& \rot{Title1} & \rot{Title2}
& \rot{Title1} & \rot{Title2}
\\\hline
AA AAA AAA AA AA AAA AAA AAA AAA & {} & \cmark & {} & \cmark & {} & {} & & \cmark & \cmark & {} \\
\hline
Row2 & \cmark & {} & {} & \cmark & {} & {} & {} & \cmark & \cmark & {} \\
\hline
Row3 & {} & \cmark & {} & \cmark & {} & {} & {} & \cmark & \cmark & {} \\
\hline
\end{tabularx}
\end{table}
\end{document}
Responder3
Ligeiramente modificadoBernardoresponder:
\documentclass[10pt]{article}
\usepackage{geometry}
\usepackage{rotating}
\usepackage{booktabs, makecell, tabularx}
\setcellgapes{3pt}
\renewcommand\theadfont{\normalsize}
\newcolumntype{C}{>{\setlength\hsize{0.7\hsize}\centering \arraybackslash}X}
\newcolumntype{L}{>{\setlength\hsize{3.0\hsize}\raggedright\arraybackslash}X}
\newcommand\mcn[2]{\multicolumn{#1}{c}{#2}}
\usepackage{caption}
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}
\newcommand{\xmark}{\ding{55}}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.3pt}
\renewcommand*\ShowFrameColor{\color{red}}
\begin{document}
\begin{table}
\caption{My Table}
\centering
\makegapedcells
\settowidth\rotheadsize{\theadfont Title 3}
\begin{tabularx}{\linewidth}{@{} L | *{3}{C} | *{3}{C} | *{2}{C} | *{2}{C} @{}}
\hline
\mcn{1}{Column1} & \mcn{3}{Column2} & \mcn{3}{ColumnLongTitle}
& \mcn{2}{Column3} & \mcn{2}{Column4} \\
\cmidrule(lr){1-1}\cmidrule(lr){2-4}\cmidrule(lr){5-7}
\cmidrule(lr){8-9}\cmidrule(lr){10-11}
& \rothead{Title1} & \rothead{Title2} & \rothead{Title3}
& \rothead{Title1} & \rothead{Title2} & \rothead{Title3}
& \rothead{Title1} & \rothead{Title2}
& \rothead{Title1} & \rothead{Title2} \\
\hline
AAAAAAAAAAAA AAAAAAAAAAAA
& & \cmark & & \cmark & & & & \cmark & \cmark & \\
\hline
Row 2 & \cmark & & & \cmark & & & & \cmark & \cmark & \\
\hline
Row 3 & & \cmark & & \cmark & & & & \cmark & \cmark & \\
\hline
\end{tabularx}
\end{table}
\end{document}
Principais diferenças:
- para cabeçalhos girados é usado
\rothead
no pacotemakecell
- definiu novo comando
\mcn{...}{...}
como atalho para\multicolumn{...}{c}{...}
- excluiu todas as chaves excedentes nas células vazias