文字对齐而不是居中?

文字对齐而不是居中?

我正在使用此代码在下表中的标签下方插入文本

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

\begin{document}

\begin{table}[h!] 
\centering 
\caption{}
\label{Table1}{\textbf{Descriptive Statistics for the Industry. 2007 - 2017}} \\
 write here option 2 \\
 \begin{tabular}{lcccc}
    ....
 \end{tabular}  
 \end{table}

 \end{document}

但是,正如您在此处看到的,(在此处写选项 2)中的文本是居中的,我希望它对齐。

在此处输入图片描述

注意:如果我移除居中并将其放在下面,则标签不会居中,而我希望它居中。

谢谢你!

答案1

问题在于手动设置的标题后面的文本属于 的范围\centering

如果您定义合适的命令并使用选项,则可以获得更加统一的排版caption

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

\usepackage{lipsum} %% for mock text

\captionsetup[table]{
  font=bf,
  justification=centering,
  labelsep=newline,
  skip=0pt,
}
\NewDocumentCommand{\bigcaption}{O{#2}mm}{%
  \caption[#1]{#2}
  \parbox[t]{\columnwidth}{#3}\par
  \medskip
}

\begin{document}

\begin{table}[htp]
\centering 

\bigcaption{Descriptive Statistics for the Industry. 2007 - 2017}{%
  \lipsum[3]}\label{tab:desc-industry2007-2017}

\begin{tabular}{lcccc}
\toprule
A & B & C & D & E \\
\midrule
1 & 2 & 3 & 4 & 5 \\
1 & 2 & 3 & 4 & 5 \\
1 & 2 & 3 & 4 & 5 \\
\bottomrule
\end{tabular}  

\end{table}

\end{document}

当然,\lipsum[3]你可以输入

\bigcaption{Descriptive Statistics for the Industry. 2007 - 2017}{%
  This table shows...
  ...
  account for the analysis.}\label{tab:desc-industry2007-2017}

在此处输入图片描述

答案2

您可以根据makecell和获得此解决方案threeparttablex(需要使用 longtable环境,因此需要进行两次编译)。siunitx对于每列中的数字的对齐,也是如此:

\documentclass{article}
\usepackage{booktabs,caption}
\usepackage{longtable, threeparttablex, makecell}
\usepackage{siunitx}
\usepackage{lipsum}

\begin{document}

\begin{ThreePartTable}%
\captionsetup{font = bf, labelsep=newline}
\setTableNoteFont{\small}
\renewcommand{\theadfont}{\normalsize}
\sisetup{group-separator={,}, group-minimum-digits =3}
\setlength{\extrarowheight}{3pt}
\begin{TableNotes}[flushleft]
  \item[]\lipsum[11]
\end{TableNotes}
    \begin{longtable}{l *{2}{S[table-format = -1.1]<{\,\%} } S[table-format=3.0] S[table-format=4.0]}
    \caption{Descriptive Statistics for the Industry. 2007--2017}\label{Table1}\\[-2ex]
    \insertTableNotes\\
    \addlinespace[1.5ex]
    \toprule
    \endhead
            Year & \multicolumn{1}{c}{\thead{Avg. Monthly \\ Return}} & \multicolumn{1}{c}{\thead{Avg. Monthly \\ Std Dev. }} & {\thead{\# of Unique \\ Securities with \\ One Month Return}} & {\thead{Total \#\\of Observations}} \\
            \midrule
            2007 & -1.7 & 8.9 & 1043 & 11722 \\
            2008 & -3.5 & 17.0 & 986 & 11316 \\
            2009 & 1.1 & 22.4 & 907 & 10985 \\
            2010 & 1.6 & 15.8 & 840 & 9750 \\
        \bottomrule
     \end{longtable}
\end{ThreePartTable}

\end{document} 

在此处输入图片描述

答案3

在此处输入图片描述您可以手动将标签内容与环境置于中心,然后调整垂直空间。

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

\begin{document}

\begin{table}[h!] 
\caption{}
\label{Table1}{
    \begin{center}
        \textbf{Descriptive Statistics for the Industry. 2007 - 2017}
    \end{center}
}
%\vspace*{-0.5\baselineskip}%%%UNCOMMENT and adjust number if you want less space between lines
\lipsum[1] 
\begin{tabular}{lcccc}
   ....
\end{tabular}  
\end{table}

 \end{document}

相关内容