![굵게, 가로 및 세로로 정렬된 여러 줄의 테이블 헤더](https://rvso.com/image/305749/%EA%B5%B5%EA%B2%8C%2C%20%EA%B0%80%EB%A1%9C%20%EB%B0%8F%20%EC%84%B8%EB%A1%9C%EB%A1%9C%20%EC%A0%95%EB%A0%AC%EB%90%9C%20%EC%97%AC%EB%9F%AC%20%EC%A4%84%EC%9D%98%20%ED%85%8C%EC%9D%B4%EB%B8%94%20%ED%97%A4%EB%8D%94.png)
머리글이 포함된 첫 번째 행이 굵게 표시되고 가로 및 세로 중앙에 배치되어야 하는 테이블을 인쇄하려고 합니다. 또한 저는 longtable
다음 환경을 사용하고 있습니다.이 패키지, 여러 페이지에 걸쳐 있는 매우 긴 테이블이 있기 때문입니다. 수평 스트레스로 인해 테이블 헤더 중 일부를 2줄로 맞추고 싶습니다(모두는 아님).shortstack
즉, 일부 셀에는 줄이 2개 있고 다른 셀에는 줄이 1개뿐이므로 헤더 내용을 수직으로 정렬할 수 없습니다. 아래 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}
이 코드는 다음 테이블에서 시작됩니다.
이 문제를 해결하고 모든 헤더 셀을 수직 중앙에 배치하는 가장 간단하고 정확하며 우아한 방법을 찾는 데 도움을 요청합니다.
답변1
제목의 수직 중앙 정렬은 가장 쉽게 수행할 수 있으며 긴 테이블을 중앙에 정렬하지 않기 때문에 tabular
제거했습니다 . center
테이블이 페이지에 비해 너무 넓기 때문에 열 간 간격을 조금 줄였습니다.
\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}
답변2
수직 및 수평 정렬과 및 명령을 makecell
사용하여 셀의 공통 서식을 선택하도록 정확하게 설계된 패키지 의 또 다른 솔루션 입니다 . 또한 테이블의 세로 간격을 덜 좁게 하기 위해 로드했습니다 .\thead
\makecell
cellspace
\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}