
내에서는 table
각 셀의 중앙에 텍스트를 배치하기 위해 다음을 사용하고 있습니다.
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
간단한 대신 p{1.5cm}
에
>{\centering\arraybackslash}p{1.5cm}
\toprule
, \midrule
, 및 도 \bottomrule
함께 사용하고 있습니다 \usepackage{booktabs}
.
내 코드는 다음과 같습니다
\documentclass[12pt]{article}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{booktabs}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{| >{\centering\arraybackslash}p{1.5cm} | >{\centering\arraybackslash}p{1.2cm} | >{\centering\arraybackslash}p{1.2cm} | >{\centering\arraybackslash}p{1.2cm} | >{\centering\arraybackslash}p{1.2cm} |>{\centering\arraybackslash}p{1.2cm} | >{\centering\arraybackslash}p{1.2cm} | >{\centering\arraybackslash}p{1.2cm} | >{\centering\arraybackslash}p{1.2cm}|}
\toprule
\multirow{2}{*}{} & \multicolumn{4}{c|}{Payoffs} & \multicolumn{4}{c}{ROR} \\
\cline{2-9}
& $\theta =1$ & $\theta =2$ & $E(P)$ & $\sigma(P)$ & $\theta =1$ & $\theta =2$ & $E(r)$ & $\sigma(r)$ \\
\midrule
Asset 1 & 110 & 95 & & & & & & \\
Asset 2 & 105 & 90 & & & & & & \\
Asset 3 & 120 & 90 & & & & & & \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
내 결과는 다음과 같이 매우 이상해 보입니다.
첫째, 맨 오른쪽 수직선이 짧습니다. 첫 번째 행은 오른쪽이 닫혀 있지 않습니다.
둘째, 모든 수직선이 잘립니다.
이견있는 사람?
답변1
오른쪽의 수직선은 짧지 않고 누락되었습니다.
\multicolumn{4}{c}{ROR}
대신에
\multicolumn{4}{c|}{ROR}
그러나 수직 규칙을 추가하는 대신 다음을 따르십시오.지침의 생각booktabs
(어쨌든 그것을 사용하고 있기 때문에) :
항상 두 가지 간단한 지침을 기억한다면 크게 잘못되지 않을 것입니다.
- 절대로 수직 규칙을 사용하지 마십시오.
- 이중 규칙을 사용하지 마십시오.
\documentclass{article}
\usepackage{booktabs,array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\begin{tabular}{ P{15mm} *{8}{P{12mm}} }
\toprule
& \multicolumn{4}{c}{Payoffs} & \multicolumn{4}{c}{ROR} \\
\cmidrule(lr){2-5}\cmidrule(lr){6-9}
& $\theta = 1$ & $\theta = 2$ & $E(P)$ & $\sigma(P)$ & $\theta = 1$ & $\theta = 2$ & $E(r)$ & $\sigma(r)$ \\
\midrule
Asset 1 & 110 & 95 & & & & & & \\
Asset 2 & 105 & 90 & & & & & & \\
Asset 3 & 120 & 90 & & & & & & \\
\bottomrule
\end{tabular}
\end{document}
값의 기둥형 스택은 수직 규칙을 어느 정도 사용하여 시각적 정렬을 촉진합니다.쓸모없는.
답변2
booktabs
북탭은 수평 규칙 주위에 수직 패딩을 추가하기 때문에 수직 규칙과 함께 규칙을 사용할 수 없습니다 . 같은 이유로 책탭이 있는 표 셀에 색상을 사용하려고 하면 문제가 발생합니다.
다양한 종류의 북 탭 규칙을 에뮬레이트하기 위해 테이블의 가변 너비 규칙을 허용하는 로 booktabs
대체 할 수 있습니다 . boldlines
그러나 많은 사람들은 수평선만 사용하면 테이블이 더 좋아 보일 것이라고 생각합니다.
다음 코드에서는 두 가지 솔루션의 예를 제공합니다. \multirow
빈 셀에는 사용할 필요가 없습니다 .
\documentclass[12pt]{article}
\usepackage{array, boldline}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{booktabs}
\begin{document}
\begin{table}[!h]
\centering\renewcommand\arraystretch{1.25}
\begin{tabular}{|P{1.5cm} | *{8}{P{1.2cm} |}}
\hlineB{2}
& \multicolumn{4}{c|}{Payoffs} & \multicolumn{4}{c|}{ROR} \\
\cline{2-9}
& $\theta =1$ & $\theta =2$ & $E(P)$ & $\sigma(P)$ & $\theta =1$ & $\theta =2$ & $E(r)$ & $\sigma(r)$ \\
\hlineB{2}
Asset 1 & 110 & 95 & & & & & & \\
Asset 2 & 105 & 90 & & & & & & \\
Asset 3 & 120 & 90 & & & & & & \\
\hlineB{2}
\end{tabular}
\end{table}
\vskip1cm
\begin{table}[!h]
\centering\renewcommand\arraystretch{1.25}
\begin{tabular}{P{1.5cm}*{8}{P{1.2cm}}}
& \multicolumn{4}{c}{Payoffs} & \multicolumn{4}{c}{ROR} \\
\cmidrule[0.6pt](lr){2-5}\cmidrule[0.6pt](lr){6-9}
& $\theta =1$ & $\theta =2$ & $E(P)$ & $\sigma(P)$ & $\theta =1$ & $\theta =2$ & $E(r)$ & $\sigma(r)$ \\
\midrule[\heavyrulewidth]
Asset 1 & 110 & 95 & & & & & & \\
Asset 2 & 105 & 90 & & & & & & \\
Asset 3 & 120 & 90 & & & & & & \\
\bottomrule
\end{tabular}
\end{table}
\end{document}