表格列中的文本右对齐

表格列中的文本右对齐

我有一张定义为的表

\documentclass[12pt]{article}
%\documentclass[man]{apa}
\usepackage{amsmath,amssymb,latexsym}
\usepackage[dviwin]{graphicx}
\linespread{1.6}
\title{}
\begin{document}
\begin{table}[!h]
    \caption{British Open 2012 (round 2): Hole score frequencies and estimated values for $p$, $q$ and $r$ for round 2 (N = 156, 2: two strokes needed, 3: three strokes needed, etc.).}
    \label{tab:2}      
\begin{center}
\begin{tabular}   {p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}}
\hline
   &   &   & \multicolumn{9}{c}{hole score} & \multicolumn{3}{c}{parameter}\\
\hline
Hole &  length & par & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & $\hat{p}$ & $\hat{q}$ & $\hat{r}$\\
\hline
 1 & 205 & 3 & 21 & 117 & 17 & 1 &   &   &      &   &   &        .076 & .049 & -.005 \\
 2 & 481 & 4 & 1 & 20 & 104 & 30 & 1 &   &     &   &   &        .065 & .074 & -.021 \\
 3 & 478 & 4 &   & 11 & 79 & 51 & 14 & 1 &     &   &   &        .072 & .168 & -.062 \\
 4 & 392 & 4 &   & 18 & 115 & 20 & 2 & 1 &     &   &   &        .044 & .044 & .001 \\
 5 & 219 & 3 & 22 & 114 & 18 & 2 &   &   &     &   &   &        .078 & .053 & -.001 \\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}

我想要将列中的文本右对齐。我该怎么做?

答案1

我建议根据siunitxandbooktabs或进行以下重新设计tabular*

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\begin{table}[!h]
\centering
    \caption{British Open 2012 (round 2): Hole score frequencies and estimated values for $p$, $q$ and $r$ for round 2 (N = 156, 2: two strokes needed, 3: three strokes needed, etc.).}
    \label{tab:2} 
    \small
    \setlength{\tabcolsep}{3pt}     
    \sisetup{add-integer-zero=false}
\begin{tabular}{lS[table-format=3] c *{9}{S[table-format=3]} *{3}{S[table-format=-.3]}}
\toprule
   &   &   & \multicolumn{9}{c}{hole score} & \multicolumn{3}{c}{parameter}\\
\cmidrule(r){4-12} \cmidrule(l){13-15}
{Hole} &  {length} & {par} & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & {$\hat{p}$} & {$\hat{q}$} & {$\hat{r}$}\\
\midrule
 1 & 205 & 3 & 21 & 117 & 17 & 1 &   &   &      &   &   &        .076 & .049 & -.005 \\
 2 & 481 & 4 & 1 & 20 & 104 & 30 & 1 &   &     &   &   &        .065 & .074 & -.021 \\
 3 & 478 & 4 &   & 11 & 79 & 51 & 14 & 1 &     &   &   &        .072 & .168 & -.062 \\
 4 & 392 & 4 &   & 18 & 115 & 20 & 2 & 1 &     &   &   &        .044 & .044 & .001 \\
 5 & 219 & 3 & 22 & 114 & 18 & 2 &   &   &     &   &   &        .078 & .053 & -.001 \\
\bottomrule
\end{tabular}
\end{table}


    \begin{table}[!h]
\centering
    \caption{British Open 2012 (round 2): Hole score frequencies and estimated values for $p$, $q$ and $r$ for round 2 (N = 156, 2: two strokes needed, 3: three strokes needed, etc.).}
    \label{tab:2} 
    \setlength{\tabcolsep}{0pt}     
    \sisetup{add-integer-zero=false}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}*{12}{r}*{3}{>{$}r<{$}}}
\toprule
   &   &   & \multicolumn{9}{c}{hole score} & \multicolumn{3}{c}{parameter}\\
\cmidrule(r){4-12} \cmidrule(l){13-15}
{Hole} &  {length} & {par} & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & \hat{p} & \hat{q} & \hat{r}\\
\midrule
 1 & 205 & 3 & 21 & 117 & 17 & 1 &   &   &      &   &   &        .076 & .049 & -.005 \\
 2 & 481 & 4 & 1 & 20 & 104 & 30 & 1 &   &     &   &   &        .065 & .074 & -.021 \\
 3 & 478 & 4 &   & 11 & 79 & 51 & 14 & 1 &     &   &   &        .072 & .168 & -.062 \\
 4 & 392 & 4 &   & 18 & 115 & 20 & 2 & 1 &     &   &   &        .044 & .044 & .001 \\
 5 & 219 & 3 & 22 & 114 & 18 & 2 &   &   &     &   &   &        .078 & .053 & -.001 \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}

答案2

修改了几项内容后——scriptsize 因为表格太宽——captio 被删除了,表格标签必须通过修改宏来制作成 scriptsize——Hole 缩写为 Ho 和 length 缩写为 lth——可以根据 OP 的喜好再次更改——captio 可以作为一行放在表格的上面或下面

在此处输入图片描述

\documentclass[12pt]{article}
%\documentclass[man]{apa}
\usepackage{amsmath,amssymb,latexsym,array}
\usepackage[dviwin]{graphicx}
%\linespread{1.6}
\newcolumntype{R}{>{\raggedleft\arraybackslash}p{0.65cm}@{}}
\title{}
\begin{document}

\begin{table}[!h]
        \scriptsize
    { Table1: British Open 2012 (round 2): Hole score frequencies and estimated values for $p$, $q$ and $r$ for round 2 (N = 156, 2: two strokes needed, 3: three strokes needed, etc.).}
    \label{tab:2}      
\begin{center}
\begin{tabular}   {RRRRRRRRRRRRRRRR}
%   {p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}}
\hline
   &   &   & \multicolumn{9}{c}{hole score} & \multicolumn{3}{c}{parameter}\\
\hline
Ho &  lth & par & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & $\hat{p}$ & $\hat{q}$ & $\hat{r}$\\
\hline
 1 & 205 & 3 & 21 & 117 & 17 & 1 &   &   &      &   &   &        .076 & .049 & -.005 \\
 2 & 481 & 4 & 1 & 20 & 104 & 30 & 1 &   &     &   &   &        .065 & .074 & -.021 \\
 3 & 478 & 4 &   & 11 & 79 & 51 & 14 & 1 &     &   &   &        .072 & .168 & -.062 \\
 4 & 392 & 4 &   & 18 & 115 & 20 & 2 & 1 &     &   &   &        .044 & .044 & .001 \\
 5 & 219 & 3 & 22 & 114 & 18 & 2 &   &   &     &   &   &        .078 & .053 & -.001 \\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}

在此处输入图片描述

\documentclass[12pt]{article}
%\documentclass[man]{apa}
\usepackage{amsmath,amssymb,latexsym,array}
\usepackage[dviwin]{graphicx}
%\linespread{1.6}
\newcolumntype{R}{>{\raggedleft\arraybackslash}p{0.65cm}@{}}
\title{}
\begin{document}

\begin{table}[!h]
        \scriptsize
%    { Table1: British Open 2012 (round 2): Hole score frequencies and estimated values for $p$, $q$ and $r$ for round 2 (N = 156, 2: two strokes needed, 3: three strokes needed, etc.).}
    \label{tab:2}      
\begin{center}
\begin{tabular}   {RRRRRRRRRRRRRRRR}
%   {p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}p{0.8cm}}
\hline
   &   &   & \multicolumn{9}{c}{hole score} & \multicolumn{3}{c}{parameter}\\
\hline
Ho &  lth & par & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & $\hat{p}$ & $\hat{q}$ & $\hat{r}$\\
\hline
 1 & 205 & 3 & 21 & 117 & 17 & 1 &   &   &      &   &   &        .076 & .049 & -.005 \\
 2 & 481 & 4 & 1 & 20 & 104 & 30 & 1 &   &     &   &   &        .065 & .074 & -.021 \\
 3 & 478 & 4 &   & 11 & 79 & 51 & 14 & 1 &     &   &   &        .072 & .168 & -.062 \\
 4 & 392 & 4 &   & 18 & 115 & 20 & 2 & 1 &     &   &   &        .044 & .044 & .001 \\
 5 & 219 & 3 & 22 & 114 & 18 & 2 &   &   &     &   &   &        .078 & .053 & -.001 \\ \hline
 \multicolumn{16}{l}{Table1: British Open 2012 (round 2): Hole score frequencies and estimated}\\
 \multicolumn{16}{l}{ values for $p$, $q$ and $r$ for round 2 (N = 156, 2: two strokes needed, }\\
 \multicolumn{16}{l}{3: three strokes needed, etc.).}
\end{tabular}
\end{center}
\end{table}
\end{document}

相关内容