如何更改表中特定列的列大小

如何更改表中特定列的列大小

我想更改size特定 的column。我在这个网站上查看了很多类似的问题,似乎\parbox[c]\textwidth是需要调整的命令。我试过了,但无法理解根据我当前的代码将此命令附加到哪里。有人能告诉我在哪里可以调整我的代码来更改列宽吗?

    \documentclass{article}
    \usepackage{ragged2e}
    \usepackage{tabularx, makecell}
    \setlength{\extrarowheight}{2pt}
    \setlength{\tabcolsep}{3pt}%

\begin{document}
\makegapedcells
\begin{tabularx}{\linewidth}{l*{2}{|>{\centering\arraybackslash}X}@{}}
   \Xhline{0.9pt}
\makecell[lc]{Shrinkage\\ estimator} &\makecell{Prior} & \makecell{Posterior estimator} \\
\hline
Ridge &\(\beta_{i}\sim\mathcal{N}\Bigl(0,\mfrac{1}{\lambda}\Bigr)\)&\makecell{$\Bigl(1-\mfrac{\lambda}{1+\lambda}\Bigr)\hat{\beta}_{i}, \lambda > 0$} \\
Lasso &\makecell{\(\beta_{i}\sim \Laplace\Bigl(0, \mfrac{1}{\lambda}\Bigr)\)}&\makecell{$\sign\bigl(\hat{\beta}_i)(|\hat{\beta}_i| - \lambda\bigr)^+$} \\
James-Stein &\makecell{\(\beta_{i}\sim \mathcal{N}(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}$}
\\

Empirical Bayes &\makecell{\(\beta_{i}\sim g_i(.)\)}&\makecell{ $\hat{\beta}_i+\sigma^2_{i}\frac{d}{d \hat{\beta_{i}}}\log \hat{m}(\hat{\beta}_i)$}
\\
\makecell[lc]{New empirical\\ Bayes}  &\makecell{\(\mathrm{p}_{i\pm}\sim g_{i\pm}(.)\)}& \makecell[lc]{ \psi(1+z_{i+}) - \psi(1-z_{i+}+n_{i+}) + \frac{\partial}{\partial z_{i+}}\mathrm{log}m_{+}(z_{i+})
\\ - \psi(1+z_{i-}) - \psi(1-z_{i-}+n_{i-}) + \frac{\partial}{\partial z_{i-}}\mathrm{log}m_{-}(z_{i-})}
\\
\hline
\end{tabularx}
 \label{tab3}
 \caption{Summary of shrinkage estimators. The parametric Bayes estimators ridge, lasso, James-Stein estimator. The ridge and James-Stein estimator specify a normal prior while the lasso specify a Laplace prior. The empirical Bayes estimator and the assumption-free empirical Bayes estimator do not specify any prior.} \label{notaion}
\hfill \break

\end{document}

在此处输入图片描述

答案1

您可以为列指定不同的宽度X。我还加载了该geometry包,以便在您不使用边注时获得更合理的边距,并简化了公式代码。特别是,该esdiff包简化了(偏导数或非偏导数)的输入,并且nccmath具有用于中等大小公式的命令(约占 的 80% \displaystyle)。

 \documentclass{article}
 \usepackage{geometry}
    \usepackage{ragged2e}
\usepackage{nccmath, esdiff}
\newcommand\mdiffp[2]{\medmath{\diffp{#1}{{#2}}}}
\usepackage{tabularx, makecell, caption}
\DeclareMathOperator{\Laplace}{Laplace}
\DeclareMathOperator{\sign}{sign}

\begin{document}
\begin{table}[!htb]
  \setlength{\tabcolsep}{3pt}%
  \setcellgapes{3pt}\makegapedcells
  \noindent\begin{tabularx}{\linewidth}{l|>{\hsize=0.65\hsize\centering\arraybackslash$}X<{$}|>{\hsize=1.35\hsize\centering\arraybackslash$}X <{$}@{}}
    \Xhline{0.9pt}
    \makecell[lc]{Shrinkage \\ estimator} &\text{Prior} & \text{Posterior estimator} \\
    \hline
    Ridge & \beta_{i} ∼ \mathcal{N}\Bigl(0,\mfrac{1}{λ}\Bigr) & \makecell{ \Bigl(1-\mfrac{λ}{1+λ}\Bigr)\hat{β}_{i}, λ> 0 } \\
    Lasso & \makecell{\beta_{i} ∼ \Laplace\Bigl(0, \mfrac{1}{λ}\Bigr)} & \makecell{ \sign\bigl(\hat{β}_i)(|\hat{β}_i| - λ\bigr)^+} \\
    James-Stein & \makecell{\beta_{i} ∼ \mathcal{N}(M, A)} & \makecell{\Bigl(1-\mfrac{N-3}{\medop∑_i^N(\hat{β}_{i}-\bar{β})²}\Bigr)^{\!+\!}\!(\hat{β}_{i}-\bar{β})+\bar{β}}
    \\

    Empirical Bayes & \makecell{\beta_{i} ∼ g_i( · )} & \makecell{\hat{β}_i+\sigma²_{i}\diff{}{\hat{\beta_{i}}}\log \hat{m}(\hat{β}_i)}
    \\
    \makecell[lc]{New empirical \\ Bayes} &\makecell{\mathrm{p}_{i±} ∼ g_{i±}( · )}& \begin{aligned} & ψ(1+z_{i+}) - ψ(1-z_{i+}+n_{i+}) + \mdiffp{}{z_{i+}}\log m_{+}(z_{i+})
      \\[-0.5ex] & -ψ(1+z_{i-}) - ψ(1-z_{i-}+n_{i-}) + \mdiffp{}{z_{i-}}\log m_{-}(z_{i-})\end{aligned}
    \\
    \hline
  \end{tabularx}
  \label{tab3}
  \caption{Summary of shrinkage estimators. The parametric Bayes estimators ridge, lasso, James-Stein estimator. The ridge and James-Stein estimator specify a normal prior while the lasso specify a Laplace prior. The empirical Bayes estimator and the assumption-free empirical Bayes estimator do not specify any prior.} \label{notaion}
\end{table}

\end{document} 

在此处输入图片描述

答案2

你的错误太多了姆韦,从序言中缺少包,到缺少新命令的自身定义,再到未声明的数学运算符。此外,数学表达式的排版也很不寻常,难以理解你到底想表达什么(因此,由于误解,我的一些更正可能是错误的)

要使X列的宽度不同,您可以在tabularx文档中找到:

>{\hsize=x\hsize}X 

其中x,数字表示列宽的相对变化(有关详细信息,请参阅包文档。但是,这种变化不足以将最后一个数学表达式放在两行单元格中。必须至少将其分成三行(请参阅姆韦以下)。

其中一个主要原因是你的姆韦不起作用的是使用makegapedcell包中的宏makecell。相反,我建议使用cellspace宏和定义\cellspacetoplimit{...}和。为了在表中激活它们,必须将\cellspacebottomlimit{...}列说明符添加到具有最关键垂直间距的列中使用的列类型中(参见S姆韦以下)。

清理 mwe 并添加所有缺失的包、命令、声明、环境和一些代码重组后,你的姆韦变得:

\documentclass{article}
\usepackage{mathtools, nccmath}   % added
\DeclareMathOperator{\sign}{sign} % added

\usepackage{ragged2e}
\usepackage{cellspace,            % added
            makecell, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}  % added
\setlength\cellspacetoplimit{5pt}                 % added
\setlength\cellspacebottomlimit{5pt}              % added

\begin{document}
    \begin{table}[ht]                             % added
    \setlength{\tabcolsep}{3pt}%
\begin{tabularx}{\linewidth}{@{} Sl|              % changed
    >{\hsize=0.4\hsize $\displaystyle}C<{$}|
    >{\hsize=0.6\hsize $\displaystyle}SC<{$}
                             @{} }
   \Xhline{0.9pt}
\makecell[l]{Shrinkage\\ estimator}
    &   \makecell{\text{Prior}}                   % changed
        &   \makecell{\text{Posterior estimator}} % changed                          \\
\hline
Ridge
    &   \beta_{i}\sim\mathcal{N}\Bigl(0,\mfrac{1}{\lambda}\Bigr)
        &   \Bigl(1-\mfrac{\lambda}{1+\lambda}\Bigr)\hat{\beta}_{i},\lambda>0   \\
Lasso
    &   \beta_{i}\sim \mathcal{L}\Bigl(0, \mfrac{1}{\lambda}\Bigr)
        &   \sign\bigl(\hat{\beta}_i)(|\hat{\beta}_i| - \lambda\bigr)^+         \\
James-Stein
    &   \beta_{i}\sim \mathcal{N}(M, A)
        &   \Bigl(1-\mfrac{N-3}{\sum_i^N(\hat{\beta}_{i}-\bar{\beta})^2}
            \Bigr)^{+}\!(\hat{\beta}_{i}-\bar{\beta})+\bar{\beta}               \\
Empirical Bayes
    &   \beta_{i}\sim g_i(.)
        &   \hat{\beta}_i+\sigma^2_{i}
            \mfrac{d}{d \hat{\beta_{i}}}\log \hat{m}(\hat{\beta}_i)              \\
\makecell[l]{New empirical\\ Bayes}
    &   \mathrm{p}_{i\pm}\sim g_{i\pm}(.)
        &   \begin{multlined}[t][\linewidth]
            \psi(1+z_{i+}) - \psi(1-z_{i+}+n_{i+}) \\
            + \mfrac{\partial}{\partial z_{i+}}\log m_{+}(z_{i+}) -
                                    \psi(1+z_{i-})      \\
            - \psi(1-z_{i-}+n_{i-}) +
            \mfrac{\partial}{\partial z_{i-}}\log m_{-}(z_{i-})
            \end{multlined}                                                     \\
    \hline
\end{tabularx}
    \caption{Summary of shrinkage estimators. The parametric Bayes estimators ridge, lasso, James-Stein estimator. The ridge and James-Stein estimator specify a normal prior while the lasso specify a Laplace prior. The empirical Bayes estimator and the assumption-free empirical Bayes estimator do not specify any prior.}
\label{notaion}
    \end{table}
\end{document}

在此处输入图片描述

相关内容