# [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…

Cheers

\begin{table}[htbp!]
\centering
\captionsetup{justification=centering}
\caption*{\textbf{Table 1.1: Summary Statistics}}
\vspace{-10pt}
\begin{threeparttable}
\begin{tabular}{p{1.5cm} p{2cm} p{2cm} p{1.5cm} p{2cm} p{1.8cm} p{1.8cm}}
\hline\hline
&              &                 &           &           &         &           \\
Variable & Number of    & Unit of         &           & Standard  & Minimum & Maximum   \\
name     & observations & observation     & Mean      & deviation & value   & value     \\
\hline
\hline\hline
\end{tabular}
\end{threeparttable}
\end{table}


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.

\documentclass{article}
\usepackage{tabularx}
\usepackage{geometry} % set page parameters suitably
\usepackage{threeparttable,caption,booktabs}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}

\begin{document}
\begin{table}[htbp]
\setlength\tabcolsep{3pt} % default value: 6pt
\captionsetup{justification=centering,skip=0.25\baselineskip}
\begin{threeparttable}
\caption*{\textbf{Table 1.1: Summary Statistics}}
\begin{tabularx}{\textwidth}{@{} LLL RRRR @{}}
\toprule
Variable Name & Number of observations & Unit of observation &
Mean & Standard deviation & Minimum value & Maximum value \\
\midrule
bla & bla & bla & blu & blu & blu & blu \\
\bottomrule
\end{tabularx}
\end{threeparttable}
\end{table}
\end{document}