
라텍스에서 다음 그림과 같은 테이블을 어떻게 가질 수 있습니까?
답변1
가능한 해결책. 나는 제안한다수직선을 사용하지 않음, 그러나 오히려booktabs
패키지. 수평 정렬을 위해 20
다음을 활용할 수 있습니다.multirow
패키지의 경우 수직 정렬의 경우 다음을 통해 첫 번째 열의 가장 큰 항목 너비를 계산할 수 있습니다.calc
패키지.
\documentclass{article}
\usepackage{booktabs,calc,multirow}
\newlength\wdx% for vertical alignment
\setlength{\wdx}{\widthof{66}}
\begin{document}
\begin{table}
\centering
\addtolength{\tabcolsep}{10pt}% increase distance between cells
\begin{tabular}{cccccc}
\toprule
\textsf{x} & \multicolumn{5}{c}{\textsf{y}}\\
\cmidrule(l{\wdx}r{\wdx}){1-1}\cmidrule(l){2-6}
10 & 22 & 33 \\
\multirow{2}[2]{\wdx}{20} & 45 & 34 & 88 & 77 & 80 \\
& 34 & 67\\
66 & 12 & 10 & 45 & 66\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
답변2
테이블에서 수직 규칙을 사용해야 하는 경우 "스트럿"을 삽입하여 에서 그린 수평선 위와 아래에 더 나은 수직 간격을 확보하는 것이 좋습니다 \hline
. 하지만 일반적으로 테이블을 구성하는 것이 더 바람직하다고 생각합니다.없이수직 규칙을 사용하고 패키지를 사용하여 , 등 booktabs
으로 그려진 간격이 넉넉한 수평선을 얻습니다 .\toprule
\midrule
두 번째 항목을 첫 번째 열의 세로 가운데에 맞추려면 \multirow
명령을 사용하십시오.
첫 번째 열을 항상 굵게 표시하는 작업을 자동화할 수도 있습니다.
마지막으로, 패키지를 사용하려는 경우 tabularx
, 예를 들어 미리 지정된 테이블 너비를 얻고 싶고 내용을 중앙에 맞추려면(게시한 스크린샷의 경우인 것 같습니다) 다음도 필요합니다. 패키지 X
에서 제공하는 열 유형 의 특별한 "중앙" 버전을 정의합니다 tabularx
.
아래 첫 번째 표는 tabular
환경을 사용하고, 두 번째 표는 tabularx
총 너비가 로 설정된 환경을 사용합니다 0.7\textwidth
. 두 번째 테이블도 산세리프로 설정되어 있습니다.
\documentclass[10pt,a4paper]{article}
\usepackage{multirow,array}
% define "struts" as suggested by Claudio Beccari in
% a piece in TeX and TUG News, Vol. 2, 1993.
\newcommand\T{\rule{0pt}{2.6ex}} % = `top' strut
\newcommand\B{\rule[-0.9ex]{0pt}{0pt}} % = `bottom' strut
\newcommand\TB{\T\B} % top-and-bottom strut
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{tabular}{>{\bfseries}c|ccccc}
x & \multicolumn{5}{c}{\bfseries y\B}\\
\hline
10 & 22 & 33\TB\\
\hline
\multirow{2}{*}{20} & 45 & 34 & 88 & 77 & 80\T\\
& 34 & 67\B \\
\hline
66 & 12 & 10 & 45 & 66\T\\
\end{tabular}
\bigskip
\textsf{ % switch to sans-serif for the second table
\begin{tabularx}{0.7\textwidth}{>{\bfseries}C|CCCCC}
x & \multicolumn{5}{c}{\bfseries y\B}\\
\hline
10 & 22 & 33\TB\\
\hline
\multirow{2}{*}{20} & 45 & 34 & 88 & 77 & 80\T\\
& 34 & 67\B \\
\hline
66 & 12 & 10 & 45 & 66\T\\
\end{tabularx}}
\end{document}
답변3
array
패키지 만 추가로 사용하는 솔루션입니다 makecell
. 한 가지 장점은 명령을 사용하면 행이 훨씬 덜 빡빡해질 수 있다는 것입니다 \makecell*
.\jot
대칭적으로와 달리 셀의 위쪽과 아래쪽에 있습니다 \renewcommand{\arraystretch}{…}
. 또 다른 하나는 hlines 두께를 변경할 수 있는 가능성입니다( 와 유사 booktabs
하지만 수직선을 사용할 수 있는 가능성은 유지함).
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array, makecell}
\begin{document}
\begin{table}
\centering\sffamily
\addtolength{\tabcolsep}{10pt}% increase distance between cells
\begin{tabular}{c!{\vline width1pt}*{5}{c}}
\makecell*{x} & \multicolumn{5}{c}{y}\\
\Xhline{1pt}
\makecell*{10} & 22 & 33 \\
\hline
\makecell{20\\[-2.5ex]}& \makecell*[tc]{45\\34} & \makecell[tc]{34\\67} & 88 & 77 & 80 \\
\hline
\makecell*{66} & 12 & 10 & 45 & 66
\end{tabular}
\end{table}
\end{document}