如何将标题与表格对齐?

如何将标题与表格对齐?

我有一张这样的桌子:

\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}

\captionsetup[table]{
  labelsep=newline,
  justification=justified,
  singlelinecheck=false,
  textfont=it,
}

\begin{document}

\begin{table}[h!]
\centering
\caption{List of Important Predictors when Predicting Rearrest (Random Forests)}
\label{rearrest.rftop.20}
\begin{threeparttable}
\begin{tabular}{lc}
\hline
\textbf{Predictor} & \textbf{Importance}\\ 
\cline{1-2}
\hspace{2pt}1. Age at first arrest &    100 \\ 
\hspace{2pt}2. Number of tattoos &  98.59 \\ 
\hspace{2pt}3. Age &    98.57 \\ 
\hspace{2pt}4. Number of times convicted of misdemeanors &  95.78 \\ 
\hspace{2pt}5. Minor disciplinary incidents (annual rate) &     85.64 \\ 
\hspace{2pt}6. Number of times convicted of felonies &  85.51 \\ 
\hspace{2pt}7. Good time lost from disciplinary incidents (annual rate) &   79.67 \\ 
\hspace{2pt}8. Number of days served  (current incarceration) &     75.66 \\ 
\hspace{2pt}9. Number of times convicted of class B misdemeanors &  72.04 \\
10. Number of times convicted of State Jail Felonies &  69.47 \\ 
11. Number of times convicted of a  property offense &  65.36 \\ 
12. Number of times convicted of  class A misdemeanors &    58.95 \\ 
13. Number of times arrested for misdemeanors &     58.51 \\ 
14. Days sentenced (current incarceration) &    57.55 \\ 
15. Number of times convicted of drug possession &  50.31 \\ 
16. Number of times convicted of a drug offense &   50.16 \\ 
17. Number of times arrested for felonies &     49.94 \\ 
18. Years of education &    46.48 \\ 
19. Number of scars &   46.02 \\ 
20. Number of times arrested for a property offense &   44.43 \\ 
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}

\end{document}

在此处输入图片描述

如何将标题与表格对齐(即,将其向右移动一点)。注意:表格编号和标题需要保留在不同的行上。

答案1

像这样?

在此处输入图片描述

你需要\caption向内移动threeparttable

无关:

  • booktabs我建议对表格中的所有水平线使用规则
  • 对于最后一列,使用包S中的列类型siunitx
  • 对于表格内容开头的数字,请将其放在自己的列r
  • 预测器投入\multicolumn{2}{l}{...}
  • 而不是在最后,为了使用threeparttable你需要加载可预置的包threeparttable

姆韦

\documentclass{article}
\usepackage{booktabs, threeparttable}
\usepackage{caption}
\captionsetup[table]{
  labelsep=newline,
  justification=justified,
  singlelinecheck=false,
  textfont=it,
}
\usepackage{siunitx}

\begin{document}
    \begin{table}[ht]
\centering
\label{rearrest.rftop.20}
\begin{threeparttable}
\caption{List of Important Predictors when Predicting Rearrest (Random Forests)}
\begin{tabular}{rlS[table-format=3.2]}
    \toprule
\multicolumn{2}{l}{\textbf{Predictor}} & \textbf{Importance}\\
    \midrule
 1.   & Age at first arrest &    100 \\
 2.   & Number of tattoos &  98.59 \\
 3.   & Age &    98.57 \\
 4.   & Number of times convicted of misdemeanors &  95.78 \\
 5.   & Minor disciplinary incidents (annual rate) &     85.64 \\
 6.   & Number of times convicted of felonies &  85.51 \\
 7.   & Good time lost from disciplinary incidents (annual rate) &   79.67 \\
 8.   & Number of days served  (current incarceration) &     75.66 \\
 9.   & Number of times convicted of class B misdemeanors &  72.04 \\
10.   & Number of times convicted of State Jail Felonies &  69.47 \\
11.   & Number of times convicted of a  property offense &  65.36 \\
12.   & Number of times convicted of  class A misdemeanors &    58.95 \\
13.   & Number of times arrested for misdemeanors &     58.51 \\
14.   & Days sentenced (current incarceration) &    57.55 \\
15.   & Number of times convicted of drug possession &  50.31 \\
16.   & Number of times convicted of a drug offense &   50.16 \\
17.   & Number of times arrested for felonies &     49.94 \\
18.   & Years of education &    46.48 \\
19.   & Number of scars &   46.02 \\
20.   & Number of times arrested for a property offense &   44.43 \\
\bottomrule
\end{tabular}
\end{threeparttable}
    \end{table}
\end{document}

答案2

这里有一些改进:右对齐的行自动编号。顺便说一句,诀窍是嵌套\caption 里面环境threeparttable

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{array, caption, threeparttable}

\captionsetup[table]{
  labelsep=newline,
  justification=justified,
  singlelinecheck=false,
  textfont=it,
}

\begin{document}

\begin{table}[h!]
\centering\setlength{\extrarowheight}{2pt}
\label{rearrest.rftop.20}
\begin{threeparttable}
\caption{List of Important Predictors when Predicting Rearrest (Random Forests)}
\newcounter{tabenum}\setcounter{tabenum}{0}
\newcommand{\tabitem}{\refstepcounter{tabenum}\arabic{tabenum}.}
\begin{tabular}{ >{\tabitem\hspace*{\labelsep}}r@{}lc}
\toprule
\multicolumn{2}{l}{\textbf{Predictor}} & \textbf{Importance}\\
\midrule
& Age at first arrest & 100 \\
& Number of tattoos & 98.59 \\
& Age & 98.57 \\
& Number of times convicted of misdemeanors & 95.78 \\
& Minor disciplinary incidents (annual rate) & 85.64 \\
& Number of times convicted of felonies & 85.51 \\
& Good time lost from disciplinary incidents (annual rate) & 79.67 \\
& Number of days served (current incarceration) & 75.66 \\
& Number of times convicted of class B misdemeanors & 72.04 \\
& Number of times convicted of State Jail Felonies & 69.47 \\
& Number of times convicted of a property offense & 65.36 \\
& Number of times convicted of class A misdemeanors & 58.95 \\
& Number of times arrested for misdemeanors & 58.51 \\
& Days sentenced (current incarceration) & 57.55 \\
& Number of times convicted of drug possession & 50.31 \\
& Number of times convicted of a drug offense & 50.16 \\
& Number of times arrested for felonies & 49.94 \\
& Years of education & 46.48 \\
& Number of scars & 46.02 \\
& Number of times arrested for a property offense & 44.43 \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}

\end{document}

在此处输入图片描述

相关内容