
표에서 행을 강조 표시할 수 있지만(아래 참조) 텍스트 중앙에 표시되지 않습니다. 이 문제를 해결할 수 있는 방법이 있나요?
암호:
\documentclass[11pt]{article}
\usepackage{color, colortbl,booktabs}
\definecolor{Gray}{gray}{0.9}
\begin{document}
\begin{table}[!htbp]
\centering
\begin{tabular}{llccc}
\midrule
&&Mean&Sigma&Total Points \& Costs\\
\midrule
2014 & Unused & 377 & 214 & 1,618,193\\ [0.5ex]
& Deducted & 213 & 141 & 565,792\\ [0.5ex]
& Carryover & 245 & 91 & 1,052,401 \\ [0.5ex]
& Used & 308 & 187 & 1,115,463\\ [0.5ex]
\rowcolor{Gray}
& Costs (dollars) & 590 & 343 & 2,162,652 \\ [0.5ex]
\bottomrule
\end{tabular}
\end{table}
\end{document}
산출:
답변1
C 및 d와 같은 키가 큰 문자와 숫자가 있고 ()의 작은 부분 외에 디센더가 있는 문자가 없기 때문에 텍스트는 컬러 패널에서 상대적으로 높게 보입니다.
그러나 행의 내용 크기를 조정하려는 높이와 깊이에 따라 너비가 0인 규칙을 추가할 수 있습니다.
\documentclass[11pt]{article}
\usepackage{color, colortbl,booktabs}
\definecolor{Gray}{gray}{0.9}
\begin{document}
\begin{table}[!htbp]
\centering
\begin{tabular}{llccc}
\midrule
&&Mean&Sigma&Total Points \& Costs\\
\midrule
2014 & Unused & 377 & 214 & 1,618,193\\ [0.5ex]
& Deducted & 213 & 141 & 565,792\\ [0.5ex]
& Carryover & 245 & 91 & 1,052,401 \\ [0.5ex]
& Used & 308 & 187 & 1,115,463\\ [0.5ex]
\rowcolor{Gray}
\rule[-1cm]{0pt}{2.4cm} & Costs (dollars) & 590 & 343 & 2,162,652 \\ [0.5ex]
\bottomrule
\end{tabular}
\end{table}
\end{document}
답변2
나는 옵션을 사용 makecell
하고 로드하는 이 코드를 제안합니다 . 로드할 필요 없이 옵션이 이를 수행합니다. 색상이 있는 줄과 아래쪽 사이에 있는 얇은 흰색 줄을 제거하고 숫자를 더 잘 정렬하는 데 사용했습니다. 마지막으로 저를 더 기쁘게 하는 또 다른 회색 음영을 제안합니다… :-)xcolor
table
colortbl
siunitx
\documentclass[11pt]{article}
\usepackage{booktabs, makecell}
\usepackage[table, svgnames]{xcolor}
\usepackage{siunitx}
\definecolor{Gray}{gray}{0.9}
\begin{document}
\begin{table}[!htbp]
\centering
\sisetup{table-format=3.0, table-number-alignment=center, group-separator={,}}
\setlength{\extrarowheight}{0.5ex}
\begin{tabular}{llSSS[table-format=7.0]}
\midrule
&&{Mean}&{Sigma}& {\makecell{Total Points \\[-0.5ex] \& Costs}} \\
\midrule
2014 & Unused & 377 & 214 & 1618193\\
& Deducted & 213 & 141 & 565792\\
& Carryover & 245 & 91 & 052401 \\
& Used & 308 & 187 & 1115463\\
\rowcolor{WhiteSmoke!70!Lavender}
& Costs (dollars) & 590 & 343 & 2162652 \\
\noalign{\vskip-\aboverulesep}
\bottomrule
\end{tabular}
\end{table}
\end{document}
답변3
새로운 패키지 포함 tabularray
:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\begin{document}
\begin{table}[htb]
\centering
\sisetup{table-format=3.0,
group-separator={,}}
\begin{tblr}{colspec={ll *{2}{Q[c,m,si]}
Q[c,m,si={table-format=7},wd=6em]},
rows={rowsep=1pt},
row{Z}={bg=gray9, abovesep+=3pt, belowsep+=3pt},
}
\toprule
& & {{{Mean}}}
& {{{Sigma}}}
& {{{Total Points \& Costs}}}
\\
\midrule
2014 & Unused & 377 & 214 & 1618193 \\
& Deducted & 213 & 141 & 565792 \\
& Carryover & 245 & 91 & 052401 \\
& Used & 308 & 187 & 1115463 \\
& Costs (dollars)
& 590 & 343 & 2162652 \\
\bottomrule
\end{tblr}
\end{table}
\end{document}
답변4
와 호환되는 방식으로 행에 색상을 지정할 수 있는 \extrarowheight=0.5ex
설정 은 다음과 같습니다 .{NiceTabular}
booktabs
\documentclass[11pt]{article}
\usepackage{booktabs}
\usepackage[svgnames]{xcolor}
\usepackage{siunitx}
\definecolor{Gray}{gray}{0.9}
\usepackage{nicematrix}
\begin{document}
\begin{table}[!htbp]
\centering
\sisetup{table-format=3.0, table-number-alignment=center, group-separator={,}}
\setlength{\extrarowheight}{0.5ex}
\begin{NiceTabular}{llSSS[table-format=7.0]}[colortbl-like]
\midrule
&&{Mean}&{Sigma}& \Block{}{Total Points \\[-0.5ex] \& Costs} \\
\midrule
2014 & Unused & 377 & 214 & 1618193\\
& Deducted & 213 & 141 & 565792\\
& Carryover & 245 & 91 & 052401 \\
& Used & 308 & 187 & 1115463\\
\rowcolor{WhiteSmoke!70!Lavender}
& Costs (dollars) & 590 & 343 & 2162652 \\
\bottomrule
\end{NiceTabular}
\end{table}
\end{document}
여러 컴파일이 필요합니다( nicematrix
내부적으로 PGF/Tikz 노드를 사용하기 때문에).