LaTeX 中的表格代码

LaTeX 中的表格代码

大家好,我是 StackExchange 的新手!我在另一篇文章中发现了以下 LaTeX 代码 (漂亮的表格样本) 来自用户 AK16,并尝试编译它,但出现“!缺少 = 插入 \ifnum”且找不到错误!如果有人能帮忙,我将不胜感激。

\documentclass[10.8pt,a4]{article}
\usepackage[margin=1.1in,a4paper]{geometry}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{float}
\usepackage{titlesec}
\usepackage{capt-of}

%dashed line
\usepackage{array}
\usepackage{arydshln}
\setlength\dashlinedash{0.2pt}
\setlength\dashlinegap{1.5pt}
\setlength\arrayrulewidth{0.3pt}

%Widows & Orphans & Penalties

\widowpenalty500
\clubpenalty500
\clubpenalty=9996
\exhyphenpenalty=50 %for line-breaking at an explicit hyphen
\brokenpenalty=4991
\predisplaypenalty=10000
\postdisplaypenalty=1549
\displaywidowpenalty=1602
\floatingpenalty = 20000


\usepackage[T1]{fontenc}
\usepackage{fontspec}
\setmainfont[Scale=0.85, Ligatures={Required,Common,Contextual,TeX}]{TeX Gyre Schola} % Incredible font inside latex


\begin{document}
\begin{table*}[] \centering
%\ra{1.3}
\begin{small}
\begin{tabular}{@{}lrrrrrrrrrrrr@{}}\toprule
\textbf{Debt/Assets} & \textbf{2002} & \textbf{2003} & \textbf{2004} & \textbf{2005} & \textbf{2006} & \textbf{2007} & \textbf{2008} & \textbf{2009} & \textbf{2010} & \textbf{2011} & \textbf{2012} & \textbf{Total} \\ \midrule
\textbf{<50\%} & -\% & 10\% & 5\% & 7\% & 11\% & 2\% & -\% & -\% & -\% & -\% & 3\% & 2\%\\ \hdashline
\textbf{<50\% - 59.9\%} & 20\ & 5\ & 16\ & 7\ & 11\ & 8\ & 13\ & 11\ & 9\ & 15\ & 8\ & 11\ \\ \hdashline
\textbf{<60\% - 69.9\%} &  -\ & 10\ & 5\ & 13\ & 11\ & 10\ & 16\ & 16\ & 17\ & 11\ & 15\ & 13\ \\ \hdashline
\textbf{<70\% - 79.9\%} &  -\ & 10\ & 37\ & 13\ & 15\ & 8\ & 24\ & 29\ & 16\ & 14\ & 35\ & 22\ \\ \hdashline
\textbf{<80\% - 89.9\%} &  40\ & 10\ & 5\ & 17\ & 7\ & 24\ & 18\ & 18\ & 21\ & 6\ & 8\ & 15\ \\ \hdashline
\textbf{>90\%} &  40\ & 55\ & 32\ & 43\ & 46\ & 49\ & 29\ & 26\ & 38\ & 24\ & 35\ & 37\ \\ \midrule
\textbf{Total} &  100\% & 100\% & 100\% & 100\% & 100\% & 100\% & 100\% & 100\% & 100\% & 100\% & 100\% & 100\% \\ \midrule
\textbf{Mean} &  85\% & 80\% & 77\% & 80\% & 78\% & 85\% & 79\% & 79\% & 82\% & 77\% & 80\% & 80\% \\ \hdashline
\textbf{Median} &  85\% & 94\% & 76\% & 81\% & 80\% & 87\% & 79\% & 77\% & 82\% & 75\% & 72\% & 80\% \\ \hdashline
\textbf{No. of Projects} &  5\% & 20\% & 19\% & 30\% & 46\% & 51\% & 68\% & 38\% & 58\% & 54\% & 26\% & 415\% \\
\bottomrule
\end{tabular}
\end{small}
\caption{Initial capital structures of large projects (\$1bn.+) \emph{(Finnerty, 2013)}}
\end{table*}

\begin{table*}[] \centering
%\ra{1.3}
\begin{small}
\begin{tabular}{@{}lrrrrrrrrrr@{}}\toprule
 & \textbf{1995} & \textbf{1996} & \textbf{1997} & \textbf{1998} & \textbf{1999} & \textbf{2000} & \textbf{2001} & \textbf{2002} & \textbf{Total}\\ \midrule
\textbf{Bank Loans} & \$23.33 & \$42.83 & \$67.43 & \$56.65 & \$72.39 & \$110.89 & \$108.48 & \$62.20 & \$557.88\\ \hdashline
\textbf{Bonds} & 3.79 & 4.79 & 7.70 & 9.79 & 19.79 & 20.81 & 25.00 & 13.80 & 109.26\\ \hdashline
\textbf{Development Agencies} & 17.59 & 18.96 & 22.05 & 20.97 & 16.62 & 17.69 & 18.75 & 18.75 & 162.63\\ \hdashline
\textbf{Total Debt} & 44.71 & 66.58 & 96.98 & 87.41 & 108.80 & 149.39 & 152.23 & 94.75 & 829.77\\ \hdashline
\textbf{Equity} & 19.16 & 28.54 & 41.56 & 37.46 & 46.70 & 64.02 & 65.24 & 40.61 & 355.68\\ \midrule
\textbf{Total} & \$63.88 & \$95.12 & \$138.54 & \$124.87 & \$155.68 & \$213.40 & \$217.47 & \$135.36 & \$1185.63\\ \midrule
\textbf{Bank Loans} & 37\% & 45\% & 49\% & 45\% & 46\% & 52\% & 50\% & 46\% & 42\% \\ \hdashline
\textbf{Bonds} & 6 & 5 & 5 & 8 & 13 & 10 & 11 & 10 & 9\\ \hdashline
\textbf{Development Agencies} & 28 & 20 & 16 & 17 & 11 & 8 & 9 & 14 & 14\\ \hdashline
\textbf{Total Debt} & 70 & 70 & 70 & 70 & 70 & 70 & 70 & 70 & 70\\ \hdashline
\textbf{Equity} & 30 & 30 & 30 & 30 & 30 & 30 & 30 & 30 & 30\\ \midrule
\textbf{Total} & 100  & 100  & 100  & 100  & 100  & 100  & 100  & 100  & 100\\
\bottomrule
\end{tabular}
\end{small}
\caption{Project funding by source (US\$ billions) \emph{(Finnerty, 2013)}}
\end{table*}

\begin{table*}[] \centering
%\ra{1.3}
\begin{small}
\begin{tabular}{@{}lllrrr@{}}\toprule
\textbf{Rank} & \textbf{Lead Arranger} & \textbf{Number of Deals} & \textbf{Dollar Amount} & \textbf{Market Share} & \textbf{Equator Principles Adoption}\\ \midrule
\textbf{1} & State Bank of India & 52 & \$21,631.6 & 10.1\% & NA\\ \hdashline
\textbf{2} & Mitsubishi UFJ Financial & 88 & 9,486.1 & 4.4 & Dec 2005\\ \hdashline
\textbf{3} & Sumitomo Mitsui & 71 & 8,188.1 & 3.8 & Jan 2006\\ \hdashline
\textbf{4} & Credit Agrocole & 60 & 6,506.4 & 3.1 & Jun 2005\\ \hdashline
\textbf{5} & Mizuho Financial & 55 & 5,797.5 & 2.7 & Oct 2003\\ \hdashline
\textbf{6} & Soci\'{e}t\'{e} Generale & 55 & 5,760.5 & 2.7 & Sep 2007\\ \hdashline
\textbf{7} & BNP Paribas & 55 & 5,390.8 & 2.5 & Oct 2008\\ \hdashline
\textbf{8} & Axis Bank & 18 & 5,216.9 & 2.4 & NA\\ \hdashline
\textbf{9} & IDBI Bank & 10 & 5,162.3 & 2.4 & NA\\ \hdashline
\textbf{10} & ING & 49 & 4,916.1 & 2.3 & Jun 2003\\ \midrule
 & Others & 102 & 135,430.4 & 63.6 & \\ \midrule
 & Total Market & 615 & \$213,486.7 & 100\% & \\
\bottomrule
\end{tabular}
\end{small}
\caption{Global project bank facility lead arrangers \emph{(Finnerty, 2013)}}
\end{table*}


\end{document}

答案1

在下面的代码中,我总结了问题下方评论中的所有建议,并稍微重新设计了表格。tabular我建议使用tabular*,而不是使用\thead包中的命令makecell,它允许在两行(或更多行)中写入列标题。这在第三个表中很重要(否则它太大并且不适合文本宽度):

\documentclass[11pt]{article}
\usepackage[margin=1.1in,a4paper]{geometry}
\usepackage{caption}
\usepackage{float}     %  not used in this mwe
\usepackage{titlesec}  %  not used in this mwe
% \usepackage{capt-of} % it is contained in caption

%dashed line
\usepackage{booktabs, makecell}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadgape{}
\usepackage{arydshln}
\setlength\dashlinedash{0.2pt}
\setlength\dashlinegap{1.5pt}
\setlength\arrayrulewidth{0.3pt}

\usepackage[T1]{fontenc}
\usepackage{fontspec}
\setmainfont[Scale=0.85, Ligatures={Required,Common,Contextual,TeX}]{TeX Gyre Schola} % Incredible font inside latex

\begin{document}
\begin{table}[htb]
%\ra{1.3}
\small
\setlength\tabcolsep{0pt}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}>{\bfseries}l *{12}{r}}
    \toprule
Debt/Assets & \thead{2002} & \thead{2003} & \thead{2004} & \thead{2005} & \thead{2006} & \thead{2007}
            & \thead{2008} & \thead{2009} & \thead{2010} & \thead{2011} & \thead{2012} & \thead{Total} \\ \midrule
<50\%           & -\% & 10\% & 5\% & 7\% & 11\% & 2\% & -\% & -\% & -\% & -\% & 3\% & 2\%\\ \hdashline
<50\% - 59.9\%  & 20\ & 5\ & 16\ & 7\ & 11\ & 8\ & 13\ & 11\ & 9\ & 15\ & 8\ & 11\ \\ \hdashline
<60\% - 69.9\%  &  -\ & 10\ & 5\ & 13\ & 11\ & 10\ & 16\ & 16\ & 17\ & 11\ & 15\ & 13\ \\ \hdashline
<70\% - 79.9\%  &  -\ & 10\ & 37\ & 13\ & 15\ & 8\ & 24\ & 29\ & 16\ & 14\ & 35\ & 22\ \\ \hdashline
<80\% - 89.9\%  &  40\ & 10\ & 5\ & 17\ & 7\ & 24\ & 18\ & 18\ & 21\ & 6\ & 8\ & 15\ \\ \hdashline
>90\%           &  40\ & 55\ & 32\ & 43\ & 46\ & 49\ & 29\ & 26\ & 38\ & 24\ & 35\ & 37\ \\ \midrule
Total           &  100\% & 100\% & 100\% & 100\% & 100\% & 100\% & 100\% & 100\% & 100\% & 100\% & 100\% & 100\% \\ \midrule
Mean            &  85\% & 80\% & 77\% & 80\% & 78\% & 85\% & 79\% & 79\% & 82\% & 77\% & 80\% & 80\% \\ \hdashline
Median          &  85\% & 94\% & 76\% & 81\% & 80\% & 87\% & 79\% & 77\% & 82\% & 75\% & 72\% & 80\% \\ \hdashline
No. of Projects &  5\% & 20\% & 19\% & 30\% & 46\% & 51\% & 68\% & 38\% & 58\% & 54\% & 26\% & 415\% \\
\bottomrule
\end{tabular*}
\caption{Initial capital structures of large projects (\$1bn.+) \emph{(Finnerty, 2013)}}
\end{table}

\begin{table}[htb]
%\ra{1.3}
\small
\setlength\tabcolsep{0pt}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}>{\bfseries}l *{9}{r}}
    \toprule
    & \thead{1995} & \thead{1996} & \thead{1997} & \thead{1998} & \thead{1999} & \thead{2000}
    & \thead{2001} & \thead{2002} & \thead{Total}\\
    \midrule
Bank Loans  & \$23.33 & \$42.83 & \$67.43 & \$56.65 & \$72.39 & \$110.89 & \$108.48 & \$62.20 & \$557.88\\ \hdashline
Bonds       & 3.79 & 4.79 & 7.70 & 9.79 & 19.79 & 20.81 & 25.00 & 13.80 & 109.26\\ \hdashline
Development Agencies
             & 17.59 & 18.96 & 22.05 & 20.97 & 16.62 & 17.69 & 18.75 & 18.75 & 162.63\\ \hdashline
Total Debt  & 44.71 & 66.58 & 96.98 & 87.41 & 108.80 & 149.39 & 152.23 & 94.75 & 829.77\\ \hdashline
Equity      & 19.16 & 28.54 & 41.56 & 37.46 & 46.70 & 64.02 & 65.24 & 40.61 & 355.68\\ \midrule
Total       & \$63.88 & \$95.12 & \$138.54 & \$124.87 & \$155.68 & \$213.40 & \$217.47 & \$135.36 & \$1185.63\\ \midrule
Bank Lons   & 37\% & 45\% & 49\% & 45\% & 46\% & 52\% & 50\% & 46\% & 42\% \\ \hdashline
Bonds       & 6 & 5 & 5 & 8 & 13 & 10 & 11 & 10 & 9\\ \hdashline
Development Agencies
            & 28 & 20 & 16 & 17 & 11 & 8 & 9 & 14 & 14\\ \hdashline
Total Debt  & 70 & 70 & 70 & 70 & 70 & 70 & 70 & 70 & 70\\ \hdashline
Equity      & 30 & 30 & 30 & 30 & 30 & 30 & 30 & 30 & 30\\ \midrule
Total       & 100  & 100  & 100  & 100  & 100  & 100  & 100  & 100  & 100\\
    \bottomrule
\end{tabular*}
\caption{Project funding by source (US\$ billions) \emph{(Finnerty, 2013)}}
\end{table}

\begin{table}[htb]
%\ra{1.3}
\small
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}>{\bfseries}l l *{4}{r}}
    \toprule
\thead{Rank} & \thead[l]{Lead Arranger}
             & \thead{Number\\ of Deals}
             & \thead{Dollar\\ Amount}
             & \thead{Market\\ Share}
             & \thead{Equator\\ Principles Adoption}\\
    \midrule
1   & State Bank of India & 52 & \$21,631.6 & 10.1\% & NA\\ \hdashline
2   & Mitsubishi UFJ Financial & 88 & 9,486.1 & 4.4 & Dec 2005\\ \hdashline
3   & Sumitomo Mitsui & 71 & 8,188.1 & 3.8 & Jan 2006\\ \hdashline
4   & Credit Agrocole & 60 & 6,506.4 & 3.1 & Jun 2005\\ \hdashline
5   & Mizuho Financial & 55 & 5,797.5 & 2.7 & Oct 2003\\ \hdashline
6   & Soci\'{e}t\'{e} Generale & 55 & 5,760.5 & 2.7 & Sep 2007\\ \hdashline
7   & BNP Paribas & 55 & 5,390.8 & 2.5 & Oct 2008\\ \hdashline
8   & Axis Bank & 18 & 5,216.9 & 2.4 & NA\\ \hdashline
9   & IDBI Bank & 10 & 5,162.3 & 2.4 & NA\\ \hdashline
10  & ING & 49 & 4,916.1 & 2.3 & Jun 2003\\ \midrule
    & Others & 102 & 135,430.4 & 63.6 & \\ \midrule
    & Total Market & 615 & \$213,486.7 & 100\% & \\
    \bottomrule
\end{tabular*}
\caption{Global project bank facility lead arrangers \emph{(Finnerty, 2013)}}
\end{table}
\end{document}

使用 编译上述代码xelatex不会给出任何错误、警告或坏框。第一个表的图像是:

在此处输入图片描述

第三个是:

在此处输入图片描述

相关内容