![Cabeçalhos de tabela multilinha em negrito, alinhados horizontal e verticalmente](https://rvso.com/image/305749/Cabe%C3%A7alhos%20de%20tabela%20multilinha%20em%20negrito%2C%20alinhados%20horizontal%20e%20verticalmente.png)
Estou tentando imprimir uma tabela onde a primeira linha, contendo o cabeçalho, deve estar em negrito e centralizada horizontal e verticalmente. Além disso, estou usando longtable
o ambiente deeste pacote, já que tenho uma tabela muito longa que abrange várias páginas. Devido ao estresse horizontal, também quero ajustar alguns dos cabeçalhos da tabela em 2 linhas (mas não todos), o que fiz usandoshortstack
Dito isso, ainda não estou conseguindo alinhar o conteúdo do cabeçalho verticalmente, visto que algumas células possuem 2 linhas e outras possuem apenas 1. Veja abaixo um MWE:
\documentclass{report}
\usepackage{booktabs}
\usepackage{longtable}
\newcommand*{\thead}[1]{\multicolumn{1}{c}{\bfseries #1}}
\begin{document}
\begin{center}
\begin{longtable}{rcrrcc}
\toprule
\thead{ID} & \thead{Database name} & \thead{\shortstack{Size\\(MB)}} & \thead{\shortstack{No. of\\records}} & \thead{\shortstack{Time stamp\\1st record}} & \thead{\shortstack{Time stamp\\last record}} \\
\midrule
%\input{tab-metadata} Really long table
1 & dummie & 2.1 & 33 & dummie & dummie \\
2 & dummie & 4.3 & 67 & dummie & dummie \\
\bottomrule
\end{longtable}
\end{center}
\end{document}
Este código origina a seguinte tabela:
Peço sua ajuda para encontrar a maneira mais simples, correta e elegante de resolver este problema e centralizar todas as células do cabeçalho verticalmente.
Responder1
A centralização vertical dos títulos é mais fácil de fazer tabular
e removi, center
pois não centraliza tabelas longas. Reduzi um pouco o espaçamento entre colunas, pois sua tabela era um pouco larga demais para a página.
\documentclass{report}
\usepackage{booktabs}
\usepackage{longtable}
\newcommand*{\thead}[1]{%
\multicolumn{1}{c}{\bfseries\begin{tabular}{@{}c@{}}#1\end{tabular}}}
\begin{document}
\setlength\tabcolsep{5pt}
\begin{longtable}{@{}rcrrcc@{}}
\toprule
\thead{ID} &
\thead{Database name} &
\thead{Size\\(MB)} &
\thead{No. of\\records} &
\thead{Time stamp\\1st record} &
\thead{Time stamp\\last record} \\
\midrule
%\input{tab-metadata} Really long table
1 & dummie & 2.1 & 33 & dummie & dummie \\
2 & dummie & 4.3 & 67 & dummie & dummie \\
\bottomrule
\end{longtable}
\end{document}
Responder2
Outra solução com o makecell
pacote, que visa justamente escolher o alinhamento vertical e horizontal e uma formatação comum nas células com os comandos \thead
e . \makecell
Também carreguei cellspace
para ter um espaçamento vertical menos apertado nas tabelas:
\documentclass{report}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\usepackage{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\begin{document}
\begin{center}
\begin{longtable}{Srcrrcc}
\toprule
\thead{ID} & \thead{Database name} & \thead{\shortstack{Size & & & \\(MB)}} & \thead{\shortstack{No. of\\records}} & \thead{\shortstack{Time stamp\\1st record}} & \thead{\shortstack{Time stamp\\last record}} \\
\midrule
%\input{tab-metadata} Really long table
1 & dummie & 2.1 & 33 & dummie & dummie \\
2 & dummie & 4.3 & 67 & dummie & dummie \\
\bottomrule
\end{longtable}
\end{center}
\end{document}