[Tex/LaTex] Right align in table when using p{}

horizontal alignmenttablesthreeparttable

How do I right align in the following example, given that I am using p{} for column widths?

Ideally I'd like the right hand side four columns to be right aligned, and the others left aligned.

I can get a workaround, using \multicolumn{1}{r}{...} for each individual cell, but it's a bit long tbf…


  \caption*{\textbf{Table 1.1: Summary Statistics}}
    \begin{tabular}{p{1.5cm} p{2cm} p{2cm} p{1.5cm} p{2cm} p{1.8cm} p{1.8cm}}
             &              &                 &           &           &         &           \\
    Variable & Number of    & Unit of         &           & Standard  & Minimum & Maximum   \\
    name     & observations & observation     & Mean      & deviation & value   & value     \\

Best Answer

I would like to suggest that you use a tabularx environment, with a width set to \textwidth. Left- and right-alignment may be achieved by definining suitably modified versions of the X column type. Among other things, such a setup greatly simplifies inputting of cell contents that require line-breaks.

enter image description here

\usepackage{geometry} % set page parameters suitably

\setlength\tabcolsep{3pt} % default value: 6pt
  \caption*{\textbf{Table 1.1: Summary Statistics}}
  \begin{tabularx}{\textwidth}{@{} LLL RRRR @{}}
    Variable Name & Number of observations & Unit of observation &
    Mean & Standard deviation & Minimum value & Maximum value \\
    bla & bla & bla & blu & blu & blu & blu \\