![表格单元格间距](https://linux22.com/image/416454/%E8%A1%A8%E6%A0%BC%E5%8D%95%E5%85%83%E6%A0%BC%E9%97%B4%E8%B7%9D.png)
考虑下表及其结果。我希望增加单元格内的间距,使它们居中并与墙壁保持一定距离。我还希望在表格周围添加边框线。
\begin{table}
\resizebox{\textwidth}{!}{
\begin{tabular}{l | c | c | c | c | }
Name & Estimator & Mean & Bias & Variance \\
\hline \\
Sample& $\frac{1}{n}\sum_{i}(Y_i-\mu)^2$ & $\sigma^2$ & 0 & $\frac{2\sigma^4}{n}$ \\
\hline \\
Un-adjusted & $\frac{1}{n}\sum_{i}(Y_i-\bar{Y})^2$ &$\frac{n-1}{n}$ $\sigma^2$ & $\frac{\sigma^2}{n}$ & $\frac{2\sigma^4}{n}$\\
\hline \\
Adjusted & $\frac{1}{n-1}\sum_{i}(Y_i-\bar{Y})^2$ & $\sigma^2$ & 0 & $\frac{2\sigma^4}{n-1}$
\end{tabular}}
\caption{Comparison of Estimators}
\end{table}
答案1
不要\resizebox
让表格材料与文本块一样宽(并在此过程中造成印刷灾难!),我建议您(a)使用环境tabular*
,(b)去掉所有垂直线,(c)使用更少但间距适当的水平线,以及(d)对公式使用显示样式而不是内联样式数学。
以下屏幕截图显示了逐步实施这些建议的效果。
\documentclass{article}
\usepackage{graphicx} % for \resizebox directive
\usepackage{array} % for \newcolumntype directive
\newcolumntype{C}{>{$\displaystyle}c<{$}}
\usepackage{booktabs} % \toprule, \midrule, \bottomrule, \addlinespace
\begin{document}
\begin{table}[ht!]
\resizebox{\textwidth}{!}{
\begin{tabular}{l | c | c | c | c | }
Name & Estimator & Mean & Bias & Variance \\
\hline & & & & \\
Sample& $\frac{1}{n}\sum_{i}(Y_i-\mu)^2$ & $\sigma^2$ & 0 & $\frac{2\sigma^4}{n}$ \\
\hline & & & & \\
Un-adjusted & $\frac{1}{n}\sum_{i}(Y_i-\bar{Y})^2$ &$\frac{n-1}{n}$ $\sigma^2$ & $\frac{\sigma^2}{n}$ & $\frac{2\sigma^4}{n}$\\
\hline & & & & \\
Adjusted & $\frac{1}{n-1}\sum_{i}(Y_i-\bar{Y})^2$ & $\sigma^2$ & 0 & $\frac{2\sigma^4}{n-1}$
\end{tabular}}
\caption{OP's table format with cont.\ vertical lines}
\end{table}
\begin{table}[h!]
\centering
\begin{tabular}{l | c | c | c | c | }
Name & Estimator & Mean & Bias & Variance \\
\hline
Sample& $\frac{1}{n}\sum_{i}(Y_i-\mu)^2$ & $\sigma^2$ & 0 & $\frac{2\sigma^4}{n}$ \\
\hline
Un-adjusted & $\frac{1}{n}\sum_{i}(Y_i-\bar{Y})^2$ &$\frac{n-1}{n}$ $\sigma^2$ & $\frac{\sigma^2}{n}$ & $\frac{2\sigma^4}{n}$\\
\hline
Adjusted & $\frac{1}{n-1}\sum_{i}(Y_i-\bar{Y})^2$ & $\sigma^2$ & 0 & $\frac{2\sigma^4}{n-1}$
\end{tabular}
\caption{Without \texttt{\string\resizebox}, without all-blank lines}
\end{table}
\begin{table}[h!]
\setlength\tabcolsep{0pt} % default: 6pt
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} lcccc }
Name & Estimator & Mean & Bias & Variance \\
\hline
Sample& $\frac{1}{n}\sum_{i}(Y_i-\mu)^2$ & $\sigma^2$ & 0 & $\frac{2\sigma^4}{n}$ \\
\hline
Un-adjusted & $\frac{1}{n}\sum_{i}(Y_i-\bar{Y})^2$ &$\frac{n-1}{n}$ $\sigma^2$ & $\frac{\sigma^2}{n}$ & $\frac{2\sigma^4}{n}$\\
\hline
Adjusted & $\frac{1}{n-1}\sum_{i}(Y_i-\bar{Y})^2$ & $\sigma^2$ & 0 & $\frac{2\sigma^4}{n-1}$
\end{tabular*}
\caption{With \texttt{tabular*} and no vertical rules}
\end{table}
\begin{table}[h!]
\setlength\tabcolsep{0pt} % default: 6pt
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} lCCCC }
%\toprule %optional
Name & $Estimator$ & $Mean$ & $Bias$ & $Variance$ \\
\midrule
Sample& \frac{1}{n}\sum\nolimits_{i}(Y_i-\mu)^2 & \sigma^2 & 0 & \frac{2\sigma^4}{n} \\
\addlinespace
Un-adjusted & \frac{1}{n}\sum\nolimits_{i}(Y_i-\bar{Y})^2 &\frac{n-1}{n}\, \sigma^2 & \frac{\sigma^2}{n} & \frac{2\sigma^4}{n}\\
\addlinespace
Adjusted & \frac{1}{n-1}\sum\nolimits_{i}(Y_i-\bar{Y})^2 & \sigma^2 & 0 & \frac{2\sigma^4}{n-1}\\
%\bottomrule % optional
\end{tabular*}
\caption{Fewer but well-spaced horizontal rules, display-style math mode}
\end{table}
\end{document}
答案2
使用nccmath
包(用于中等大小的分数)和makecell
包在单元格内容周围留出更多垂直空间。对于表格周围的“框架”,您只需要在hline
表格主体前后添加(参见下面的 MWE)以及|
在第一列之前和最后一列之后添加垂直线说明符。
完整的 MWE 是:
\documentclass{article}
\usepackage{nccmath}
\usepackage{booktabs, makecell}
\begin{document}
\begin{table}[ht]
\setcellgapes{5pt}
\makegapedcells
\centering
\begin{tabular}{|l | c | c | c | c | }\hline
Name & Estimator & Mean & Bias & Variance \\
\hline
Sample& $\mfrac{1}{n}\sum_{i}(Y_i-\mu)^2$ & $\sigma^2$ & 0 & $\mfrac{2\sigma^4}{n}$ \\
\hline
Un-adjusted & $\mfrac{1}{n}\sum_{i}(Y_i-\bar{Y})^2$ & $\mfrac{n-1}{n}$ $\sigma^2$ & $\mfrac{\sigma^2}{n}$ & $\frac{2\sigma^4}{n}$ \\
\hline
Adjusted & $\mfrac{1}{n-1}\sum_{i}(Y_i-\bar{Y})^2$ & $\sigma^2$ & 0 & $\mfrac{2\sigma^4}{n-1}$ \\
\hline
\end{tabular}
\caption{Comparison of Estimators}
\end{table}
\end{document}
答案3
你可以选择选项 1 或选项 2
\begin{table}
\setcellgapes{3pt}
\makegapedcells
% \resizebox{\textwidth}{!}
{
\begin{tabular}{|l | c | c | c | c | }\hline
Name & Estimator & Mean & Bias & Variance \\
\hline
Sample& $\frac{1}{n}\sum_{i}(Y_i-\mu)^2$ & $\sigma^2$ & 0 & $\frac{2\sigma^4}{n}$ \\
\hline
Un-adjusted & $\frac{1}{n}\sum_{i}(Y_i-\bar{Y})^2$ &$\frac{n-1}{n}$ $\sigma^2$ & $\frac{\sigma^2}{n}$ & $\frac{2\sigma^4}{n}$\\
\hline
Adjusted & $\frac{1}{n-1}\sum_{i}(Y_i-\bar{Y})^2$ & $\sigma^2$ & 0 & $\frac{2\sigma^4}{n-1}$\\\hline
\end{tabular}}
\caption{Comparison of Estimators}
\end{table}
\begin{table}
\begin{tabular}{l c c c c }
Name & Estimator & Mean & Bias & Variance \\
\hline \\
Sample& $\frac{1}{n}\sum_{i}(Y_i-\mu)^2$ & $\sigma^2$ & 0 & $\frac{2\sigma^4}{n}$ \\
\\
Un-adjusted & $\frac{1}{n}\sum_{i}(Y_i-\bar{Y})^2$ &$\frac{n-1}{n}$ $\sigma^2$ & $\frac{\sigma^2}{n}$ & $\frac{2\sigma^4}{n}$\\
\\
Adjusted & $\frac{1}{n-1}\sum_{i}(Y_i-\bar{Y})^2$ & $\sigma^2$ & 0 & $\frac{2\sigma^4}{n-1}$
\end{tabular}
\caption{Comparison of Estimators}
\end{table}