获取等宽的列 - threeparttable / siunitx / sidewaystable

获取等宽的列 - threeparttable / siunitx / sidewaystable

我对 LaTeX 还很陌生,非常感谢您的帮助。

我想要一个包含 6 列的表格,其中最后 5 列宽度相等。这全部使用 sidewaystable、threeparttable 和 siunitx。

我已经在这里得到了一些支持:关联- 但是,我仍然难以实施建议的解决方案。您能帮我解决我的新代码吗?

谢谢!

理想情况下,输出应该看起来像图片一样。

在此处输入图片描述

\documentclass[authoryear,11pt]{elsarticle}

%Packages
\usepackage[T1]{fontenc}
\usepackage{lmodern} 
\usepackage{natbib}
\usepackage{color}
\usepackage{setspace}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage{array}
\usepackage{rotating}
\usepackage{threeparttable}
\usepackage{longtable, lscape}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{soul}
\usepackage{endnotes}
\usepackage{eurosym}
\usepackage{mathabx}
\usepackage[font=small]{caption}
\usepackage[breaklinks=true,hidelinks,colorlinks=true,linkcolor=blauelsevier,urlcolor=blauelsevier, citecolor=blauelsevier]{hyperref}
\usepackage{rotating}
\usepackage{siunitx}
\usepackage{etoolbox}

\begin{small}
\begin{singlespace}
\vspace*{\fill}

\begin{sidewaystable}

\centering
\sisetup{table-column-width=13ex,
         detect-weight}

\begin{threeparttable}

\caption{\label{tab:tab_worldbank} tbd}

    \begin{tabular}{l S[table-format=2.1]
                      S[table-format=2.0]
                      S[table-format=2.1,table-space-text-post={\,\%}]<{\,\%}
                      S[table-format=1.1]
                      S[table-format=2.1,table-space-text-post={\,\%}]<{\,\%}
                         }

        \toprule

        \thead[b]{Country}
    &   {\thead[b]{Strength of\\ Insolvency\\ (0-16)}}
        &   {\thead[b]{Resolving\\ Insolvency\\ (rank)}}
            &   \multicolumn{1}{c}{Recovery\\ Rate\\ s(\%)}
                &   {\thead[b]{Recovery\\ Time\\ (years)}}
                    &   \multicolumn{1}{c}{Insolvency\\ Cost\\ (\%)}      \\

        \midrule
    Austria & 11.0  & 20    & 82.8 & 1.1   & 10.0 \cr
    Belgium & 11.5  & 10    & 89.9 & 0.9   & 3.5 \cr
    Denmark & 12.0  & 8     & 88.0 & 1.0   & 4.0 \cr
    Finland & 14.5  & 1     & 90.3 & 0.9   & 3.5 \cr
    France & 11.0  & 24    & 78.5 & 1.9   & 9.0 \cr
    Germany & 15.0  & 3     & 84.4 & 1.2   & 8.0 \cr
    Greece & 12.0  & 52    & 35.6 & 3.5   & 9.0 \cr
    Ireland & 10.5  & 17    & 87.7 & 0.4   & 9.0 \cr
    Italy & 13.5  & 25    & 63.9 & 1.8   & 22.0 \cr
    Luxembourg & 7.0   & 82    & 43.7 & 2.0   & 14.5 \cr
    Netherlands & 11.5  & 11    & 89.3 & 1.1   & 3.5 \cr
    Portugal & 14.5  & 7     & 74.2 & 2.0   & 9.0 \cr
    Spain & 12.0  & 18    & 78.3 & 1.5   & 11.0 \cr
    Sweden & 12.0  & 19    & 77.9 & 2.0   & 9.0 \cr
    United Kingdom & 11.0  & 13    & 88.6 & 1.0   & 6.0 \cr
    \textbf{EU15 average} & \bfseries{11.9} & \bfseries{21} & \bfseries{76.9} & \bfseries{1.5} & \bfseries{8.7} \cr

        \addlinespace

    Brazil & 13.0  & 67    & 15.8 & 4.0   & 12.0 \cr
    China & 11.5  & 53    & 36.9 & 1.7   & 22.0 \cr
    India & 6.0   & 136   & 26.0 & 4.3   & 9.0 \cr
    Russia & 11.5  & 51    & 38.6 & 2.0   & 9.0 \cr
    \textbf{BRIC average} & \bfseries{10.5} & \bfseries{77} & \bfseries{29.3} & \bfseries{3.0} & \bfseries{13.0} \cr

        \addlinespace

    United States of America & 15.0  & 5     & 78.6 & 1.5   & 10.0 \cr

        \bottomrule

        \end{tabular}%

\begin{tablenotes}[flushleft]\labelsep.0em
\item tbd
\end{tablenotes}

\end{threeparttable}

\end{sidewaystable}

\vspace*{\fill}
\end{singlespace}
\end{small}

答案1

为了保证五个数字列都具有相同的宽度,我将使用环境tabularx。请注意,以下示例中采用了混合方法:数字列的主要列类型是S,但五个标题单元格被封装在使用列类型的包装器中,这只是包提供的列类型C的居中版本。Xtabularx

请注意,如果您愿意使用“美利坚合众国”的标准缩写,则可以轻松地以普通纵向模式呈现表格——sidewaystable如果普通方式有效,则无需使用,对吗?还请注意,没有必要指示 LaTeX在数据列 3 和 5 的右边缘附加table大量符号:将标记放在标题中就足够了,对吗?我不会使用%(%)大胆的对于标题材料——没有必要大喊大叫,不是吗?最后,请注意\bfseries——与\textbf——不同不是提出论点。

在此处输入图片描述

\documentclass[authoryear,11pt]{elsarticle}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
% 'natbib' is loaded automatically by 'elsarticle' document class
\usepackage[table]{xcolor}
\usepackage{setspace,booktabs,makecell,array,graphicx}
\usepackage{threeparttable,longtable,tabularx,ragged2e}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\newcommand\mC[1]{\multicolumn{1}{C}{#1}} % handy shortcut macro
\usepackage{amsmath,soul,endnotes,eurosym,siunitx}
\usepackage[font=small]{caption}

\usepackage{etoolbox}
\robustify{\bfseries} % for use inside 'S'-type columns

\usepackage[breaklinks=true, hidelinks,
   colorlinks=true,
   linkcolor=blauelsevier,
   urlcolor=blauelsevier, 
   citecolor=blauelsevier]{hyperref}

\begin{document}
\begin{table}
\setlength\tabcolsep{3pt} % default: 6pt
\small
\sisetup{detect-weight}

\begin{threeparttable}
\caption{\label{tab:tab_worldbank} tbd}

\begin{tabularx}{\textwidth}{@{}
                       l S[table-format=2.1]
                         S[table-format=2.0]
                         S[table-format=2.1]
                         S[table-format=1.1]
                         S[table-format=2.1] @{}}
    \toprule
    Country
    & \mC{Strength of Insolvency}
    & \mC{Resolving Insolvency}
    & \mC{Recovery Rate}
    & \mC{Recovery Time}
    & \multicolumn{1}{C@{}}{Insolvency Cost}\\
    & {(0--16)} & {(rank)} & {(\%)} & {(years)} & {(\%)} \\
    \midrule
    Austria & 11.0  & 20    & 82.8 & 1.1   & 10.0 \cr
    Belgium & 11.5  & 10    & 89.9 & 0.9   & 3.5 \cr
    Denmark & 12.0  & 8     & 88.0 & 1.0   & 4.0 \cr
    Finland & 14.5  & 1     & 90.3 & 0.9   & 3.5 \cr
    France  & 11.0  & 24    & 78.5 & 1.9   & 9.0 \cr
    \addlinespace
    Germany & 15.0  & 3     & 84.4 & 1.2   & 8.0 \cr
    Greece  & 12.0  & 52    & 35.6 & 3.5   & 9.0 \cr
    Ireland & 10.5  & 17    & 87.7 & 0.4   & 9.0 \cr
    Italy   & 13.5  & 25    & 63.9 & 1.8   & 22.0 \cr
    Luxembourg     & 7.0   & 82    & 43.7 & 2.0   & 14.5 \cr
    \addlinespace
    Netherlands    & 11.5  & 11    & 89.3 & 1.1   & 3.5 \cr
    Portugal       & 14.5  & 7     & 74.2 & 2.0   & 9.0 \cr
    Spain          & 12.0  & 18    & 78.3 & 1.5   & 11.0 \cr
    Sweden         & 12.0  & 19    & 77.9 & 2.0   & 9.0 \cr
    United Kingdom & 11.0  & 13    & 88.6 & 1.0   & 6.0 \cr
    \bfseries EU15 average & \bfseries 11.9 & 
    \bfseries 21 & \bfseries 76.9 & \bfseries 1.5 & 
    \bfseries 8.7  \cr

    \addlinespace

    Brazil & 13.0  & 67    & 15.8 & 4.0   & 12.0 \cr
    China & 11.5  & 53    & 36.9 & 1.7   & 22.0 \cr
    India & 6.0   & 136   & 26.0 & 4.3   & 9.0 \cr
    Russia & 11.5  & 51    & 38.6 & 2.0   & 9.0 \cr
    \bfseries BRIC average & \bfseries 10.5 & 
    \bfseries 77 & \bfseries 29.3 & \bfseries 3.0 & 
    \bfseries 13.0 \cr

    \addlinespace

    Memo: USA & 15.0  & 5 & 78.6 & 1.5   & 10.0 \cr

    \bottomrule

\end{tabularx}%

\begin{tablenotes}[flushleft]\labelsep0.0em
\item Notes: tbd
\end{tablenotes}

\end{threeparttable}
\end{table}
\end{document}

相关内容