这些是代码:
\documentclass{article}
\usepackage{ragged2e}
\usepackage{tabularx, makecell}
\setlength{\extrarowheight}{2pt}
\setlength{\tabcolsep}{3pt}%
\begin{document}
\begin{tabularx}{\linewidth}{>{\RaggedRight\arraybackslash}X*{2}{|>{\RaggedRight\arraybackslash}X}}
\Xhline{0.8pt}
% \cline{1-8}
Shrinkage estimator &\makecell{Prior} & \makecell{Posterior estimator} \\
\hline
estimate1 &\makecell{ \(\beta_{i}\sim\Normal{0}{\frac{1}{\lambda}}}&\makecell{$\left(1-\frac{\lambda}{1+\lambda}\right)\hat{\beta}_{i}, \lambda > 0$} \\
estimate2 &\makecell{\(\beta_{i}\sim \mathrm{Laplace}(0, \frac{1}{\lambda})\)}&\makecell{$\mathrm{sign}(\hat{\beta}_i)(|\hat{\beta}_i| - \lambda)^+$} \\
estimate3 &\makecell{\(\beta_{i}\sim \Normal{M}{A}\)}&\makecell{$\left(1-\frac{N-3}{\sum_i^N(\hat{\beta}_{i}-\bar{\beta})^2}\right)^+(\hat{\beta}_{i}-\bar{\beta})+\bar{\beta}$} \\
\hline
\end{tabularx}
\label{tab3}
\hfill \break
\end{document}
但是对于这个表格的第三行,由于最右边的条目需要更大的空间,因此它使得这个表格的第三行不再水平对齐。我想要的是
同一行的文本水平对齐。有人能告诉我如何修复它吗?谢谢。
答案1
l
您可以通过将第一列类型设置makecell
为第一列标题分为两行来实现:
\documentclass{article}
\usepackage{mathtools, nccmath}
\DeclareMathOperator{\Laplace}{Laplace}
\DeclareMathOperator{\Normal}{Normal}
\DeclareMathOperator{\sign}{sign}
\usepackage{ragged2e}
\usepackage{tabularx, makecell}
\setlength{\tabcolsep}{3pt}%
\setcellgapes{4pt}
\begin{document}
\makegapedcells
\begin{tabularx}{\linewidth}{l*{2}{|>{\centering\arraybackslash}X}@{}}
\Xhline{0.8pt}
\makecell[lc]{Shrinkage\\ estimator} &\makecell{Prior} & \makecell{Posterior estimator} \\
\hline
estimate1 &\(\beta_{i}\sim\Normal\Bigl(0,\mfrac{1}{\lambda}\Bigr)\)&\makecell{$\Bigl(1-\mfrac{\lambda}{1+\lambda}\Bigr)\hat{\beta}_{i}, \lambda > 0$} \\
estimate2 &\makecell{\(\beta_{i}\sim \Laplace\Bigl(0, \mfrac{1}{\lambda}\Bigr)\)}&\makecell{$\sign\bigl(\hat{\beta}_i)(|\hat{\beta}_i| - \lambda\bigr)^+$} \\
estimate3 &\makecell{\(\beta_{i}\sim \Normal(M, A)\)}&\makecell{$\Bigl(1-\mfrac{N-3}{\medop\sum_i^N(\hat{\beta}_{i}-\bar{\beta})^2}\Bigr)^{\!+\!}\!(\hat{\beta}_{i}-\bar{\beta})+\bar{\beta}$}
\\
\hline
\end{tabularx}
\label{tab3}
\hfill \break
\end{document}
答案2
稍作修改伯纳德回答:
- 定义新的列类型
C
- 将最后两列置于“数学”模式,因此数学表达式不需要用
(
and括起来)
- 调整第二列和第三列的宽度
- 删除
\makecell{...}
单元格中的方程式
\documentclass{article}
\usepackage{mathtools, nccmath}
\DeclareMathOperator{\Laplace}{Laplace}
\DeclareMathOperator{\Normal}{Normal}
\DeclareMathOperator{\sign}{sign}
\usepackage{ragged2e}
\usepackage{makecell, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}%
\setcellgapes{4pt}
\begin{document}
\makegapedcells
\begin{tabularx}{\linewidth}{l| >{\hsize=0.4\hsize $}C<{$}
| >{\hsize=0.6\hsize $}C<{$}
@{}}
\Xhline{0.8pt}
\makecell[lc]{Shrinkage\\ estimator}
&\text{Prior}
& \text{Posterior estimator} \\
\hline
estimate1 & \beta_{i}\sim\Normal\Bigl(0,\mfrac{1}{\lambda}\Bigr)
& \Bigl(1-\mfrac{\lambda}{1+\lambda}\Bigr)\hat{\beta}_{i}, \lambda > 0 \\
estimate2 & \beta_{i}\sim \Laplace\Bigl(0, \mfrac{1}{\lambda}\Bigr)
& \sign\bigl(\hat{\beta}_i)(|\hat{\beta}_i| - \lambda\bigr)^{+} \\
estimate3 & \beta_{i}\sim \Normal
& \Bigl(1-\mfrac{N-3}{\medop\sum_i^N(\hat{\beta}_{i}-\bar{\beta})^2}\Bigr)^{+}
(\hat{\beta}_{i}-\bar{\beta})+\bar{\beta}
\\
\hline
\end{tabularx}
\end{document}