0

I would like to have all the values in the table aligned. However, when using tabularx, this looks even worse. I guess it may stem from the fact that I have something like this: \thead[l]{Potatoes \ Pasta \ Rice}, because in my other table (11) that only has single words, tabularx works just fine. enter image description here

   \documentclass{article}
    \usepackage{geometry}
    \usepackage{float}
    \usepackage{siunitx}
    \usepackage{tabularx}

\begin{document}

\begin{table}[H]
       \centering
       \renewcommand{\arraystretch}{1.7}
       \begin{tabular}[width=\textwidth]{l l l l l l l}
       \hline
       \hline
        \multicolumn{7}{c}{Price} \\
       \hline
          & Meat & Dairy & Vegetables & Fruits & \thead[l]{Potatoes \\ Pasta \\ Rice} & \thead[l]{Bread \\ Oats}  \\
          \hline
          \hline
          Meat &  -1.017***   &  0.044***  &  -0.090***  &  -0.140***  &  -0.049***  &  -0.165***\\
          
          Dairy &   0.097***  &  -1.009***  &  -0.044***  &  -0.009  &      0.030***  &  -0.021**\\
          
          Fruits  &  0.000   &    -0.044***  &  -0.688***  &   0.006  &      -0.039***   &  0.020 \\
          
          Vegetables &  -0.089*** &    0.057***  &   0.025*  &    -0.673*** &   -0.001    &    0.009\\
          
          \thead[l]{Potatoes \\ Pasta \\ Rice}   & -0.194***  &  -0.046** &     -0.016   &    -0.073***  &  -0.780***  &  -0.043*\\
          
          \thead[l]{Bread \\ Oats}   &  0.003  &     -0.099***  &  -0.118***  &  -0.047**  &    0.010    &   -0.496***\\ 
          \hline
          \hline
           \multicolumn{7}{c}{\footnotesize  * p$<$0.1, ** p$<$0.05, *** p$<$0.01}
       \end{tabular}
       \caption{First stage estimation of own- and cross-price elasticities}
       \label{cross_price_1}
\end{table}

\begin{table}[H]
       \centering
       \renewcommand{\arraystretch}{1.7}
       \begin{tabularx}{0.7\textwidth}{XSSS}
       \hline
       \hline
        \multicolumn{4}{c}{Price} \\
       \hline
          & {Beef} & {Pork} & {Poultry}  \\
          \hline
          \hline
          Beef & -0.494***   &  -0.516***  & -0.228***   \\
          
          Pork & -0.048***   &  -0.903***   &  0.008  \\
          
          Poultry  &   -0.209***  &   -0.082**  &  -0.822***  \\
          \hline
          \hline
           \multicolumn{4}{c}{\footnotesize  * p$<$0.1, ** p$<$0.05, *** p$<$0.01}
       \end{tabularx}
       \caption{Second stage estimation of own- and cross-price elasticities}
       \label{cross_price_2m}
\end{table}

\end{document}
5
  • Please extend your sniplet to an actual minimal example that others can copy and test as is. Here we have to add stuff in order to even get this to compile, and w might add stuff that aren't in your setup
    – daleif
    May 10, 2022 at 8:50
  • 1
    Note that unless you are using some special package, \begin{tabular}[width=\textwidth]{l l l l l l l} is the wrong syntax. Tabularx uses \begin{tabularx}{width}{...}
    – daleif
    May 10, 2022 at 8:51
  • That edit is still not compilable. There is no \begin/end{document} and note my second comment.
    – daleif
    May 10, 2022 at 9:00
  • 1
    And \thead is not defined.You miss something else ...
    – Fran
    May 10, 2022 at 9:05
  • Sorry missed the second table, but the first is still wrong, tabular does not take a width like that.
    – daleif
    May 10, 2022 at 9:19

1 Answer 1

2
  • At such tables are usual used S columns defined in siunitx package, which enable align numbers at decimal points.
  • You use \thead command defined in the makecell packae, but not load this package.
  • To tabular you cant prescribe table width. This is possible at tabular*
  • try the following MWE (Minimal Working Example):
\documentclass{article}
\usepackage{geometry}
\usepackage{siunitx}
\usepackage{makecell,    % <---
            tabularx}

\begin{document}
\begin{table}[ht]
   \centering
   \renewcommand{\arraystretch}{1.7}
   \sisetup{table-format=-1.3{***}}
            
   \begin{tabular}{l *{6}{S}}
       \hline
       \hline
       \multicolumn{7}{c}{Price} \\
       \hline
        & {Meat} & {Dairy} & {Vegetables} & {Fruits} & {\thead[l]{Potatoes \\ Pasta \\ Rice}} & {\thead[l]{Bread \\ Oats}}  \\
          \hline
          \hline
Meat    & -1.017*** &  0.044*** & -0.090*** & -0.140*** & -0.049*** & -0.165***     \\
Dairy   &  0.097*** & -1.009*** & -0.044*** & -0.009    &  0.030*** & -0.021**      \\
Fruits  &  0.000    & -0.044*** & -0.688*** &  0.006    & -0.039*** &  0.020        \\
Vegetables 
        & -0.089*** &  0.057*** &  0.025*   & -0.673*** & -0.001    &  0.009        \\
\thead[l]{Potatoes \\ Pasta \\ Rice}   
        & -0.194*** & -0.046**  & -0.016    & -0.073*** & -0.780*** & -0.043*       \\
\thead[l]{Bread \\ Oats}   
        &  0.003    & -0.099*** & -0.118*** & -0.047**  &  0.010    & -0.496***     \\
    \hline
    \hline
\multicolumn{7}{c}{\footnotesize  * p$<$0.1, ** p$<$0.05, *** p$<$0.01}
    \end{tabular}
\caption{First stage estimation of own- and cross-price elasticities}
\label{cross_price_1}
\end{table}
\end{document}

enter image description here

You must log in to answer this question.

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