
tabularx
나는 의 컬럼 유형이 중앙에 있는 것처럼 수평 및 수직 방향으로도 중앙에 위치하는 자동 너비의 열을 가질 수 있는 방법을 찾으려고 노력 중입니다 X
.
그래서 지금까지 시도한 내용은 다음과 같습니다.
\documentclass{article}
\usepackage{tabularx,booktabs}
\newcolumntype{Z}[0]{>{\centering\arraybackslash\let\newline\\\hspace{0pt}}X}%
\begin{document}
\begin{table}
\begin{tabularx}{7cm}{l|X|X}
& long\newline heading 1 & short heading\\
\toprule
row 1 & 2314 & 2134
\end{tabularx}
\end{table}
\begin{table}
\begin{tabularx}{7cm}{l|Z|Z}
& long\linebreak heading 1 & short heading\\
\toprule
row 1 & 2314 & 2134
\end{tabularx}
\end{table}
\end{document}
두 번째는 이미 내가 원하는 것과 거의 비슷합니다. 세 번째 열의 수직 중심이 누락되었습니다. 이 문제를 해결하는 방법은 무엇입니까?
답변1
수직 센터링의 경우 뒤에 놓일 m
기둥이 아닌 기둥을 원합니다.p
X
\documentclass{article}
\usepackage{tabularx,booktabs}
\newcolumntype{Z}[0]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}X}%
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}
\begin{table}
\begin{tabularx}{7cm}{l|X|X}
& long\newline heading 1 & short heading\\
\toprule
row 1 & 2314 & 2134
\end{tabularx}
\end{table}
\begin{table}
\begin{tabularx}{7cm}{l|Z|Z}
& long\linebreak heading 1 & short heading\\
\toprule
row 1 & 2314 & 2134
\end{tabularx}
\end{table}
\end{document}
답변2
makecell
패키지와 해당 명령을 사용하십시오 \thead
.
\documentclass{article}
\usepackage{tabularx,booktabs, makecell}
\newcolumntype{Z}[0]{>{\centering\arraybackslash\let\newline\\\hspace{0pt}}X}%
\begin{document}
\begin{table}
\begin{tabularx}{7cm}{l|X|X}
&\thead{ long\\ heading 1} & \thead{short heading}\\
\toprule
row 1 & 2314 & 2134
\end{tabularx}
\end{table}
\begin{table}
\begin{tabularx}{7cm}{l|Z|Z}
&\thead{long\\ heading 1} & \thead{short heading}\\
\toprule
row 1 & 2314 & 2134
\end{tabularx}
\end{table}
\end{document}
makecell을 사용하면 헤드 셀의 내용 형식을 쉽게 지정할 수 있습니다. 수직선을 다음과 함께 사용해서는 안 된다는 점을 지적하겠습니다 booktabs
. 보시다시피, 수직선은 수평선을 자르지 않습니다.