p{}
假设我使用列宽,如何在以下示例中进行右对齐?
理想情况下,我希望右侧四列右对齐,其他列左对齐。
我可以找到一个解决方法,\multicolumn{1}{r}{...}
针对每个单独的单元格使用,但是坦白说它有点长......
干杯
\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}
答案1
我建议您使用一个tabularx
环境,将宽度设置为\textwidth
。左对齐和右对齐可以通过定义适当修改的列类型版本来实现X
。除此之外,这样的设置还大大简化了需要换行的单元格内容的输入。
\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}