0

These are the codes:

\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}

The table generated by the codes is: enter image description here

However for the third row of this table, since the entry in the rightmost side need larger space, then it makes the third row of this table no longer horizontally aligned. What I want is

enter image description here

which the text in the same row are horizontally aligned. Could anyone indicate me how to fix it? Thank you.

1
  • I suspect there is a blank line caused by the \makecell not fitting into the X column. Fix that and it should work. In other words, stop using X columns for single lines of text. Commented Aug 23, 2017 at 2:36

2 Answers 2

4

You can achieve it making the first column l type and using makecell to have the first column head split over two lines:

\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} 

enter image description here

1

slightly modified Bernard answer:

  • defined new column type C
  • put last two columns into "math" mode, consequently math expression not need to be enclosed by ( and )
  • resize widths of the second and third column
  • remove \makecell{...} around equations in cells

\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}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .