为什么 calc 包不起作用?

为什么 calc 包不起作用?

我正在尝试xtabular通过以下命令跨越表中的两列(使用):

\multicolumn{2}{|p{(\linewidth-\tabcolsep*2-\arrayrulewidth*1)*2/2}|}

包裹calc必须计算这个方程:

\linewidth-\tabcolsep*2-\arrayrulewidth*1)*2/2

但我收到编译错误:

缺失数字,视为零。

甚至简单的操作都无法计算:

\arrayrulewidth*1

我使用 doxygen 文档并使用 HTML 标签创建表格。doxygen 生成的 TeX 表格如下:

\begin{TabularC}{2}
\hline
\multicolumn{2}{|p{(\linewidth-\tabcolsep*2-\arrayrulewidth*1)*2/2}|}{Environment  }\\\cline{1-2}
Gravity acceleration &0.\-0  \\\cline{1-2}
Water depth &0.\-0  \\\cline{1-2}
Water density &0.\-0  \\\cline{1-2}
Wave frequencies &$<$empty$>$  \\\cline{1-2}
\end{TabularC}

TabularC 定义:

\newcommand{\PBS}[1]{\let\temp=\\#1\let\\=\temp}%
\newlength{\tmplength}%
\newenvironment{TabularC}[1]%
{%
\setlength{\tmplength}%
     {\linewidth/(#1)-\tabcolsep*2-\arrayrulewidth*(#1+1)/(#1)}%
      \par\begin{xtabular*}{\linewidth}%
             {*{#1}{|>{\PBS\raggedright\hspace{0pt}}p{\the\tmplength}}|}%
}%
{\end{xtabular*}\par}%

HTML 表格:

<table cellspacing='0' cellpadding='5' style='border: 1px solid rgb(200, 200, 200)'>
<tr>
  <td colspan='2' style='background-color: black; color: white; text-align: center'>Environment</td>
</tr>
<tr>
  <td style='border-right: 1px solid rgb(200, 200, 200)'>Gravity acceleration</td>
  <td>0.0</td>
</tr>
<tr>
  <td style='border-right: 1px solid rgb(200, 200, 200)'>Water depth</td>
  <td>0.0</td>
</tr>
<tr>
  <td style='border-right: 1px solid rgb(200, 200, 200)'>Water density</td>
  <td>0.0</td>
</tr>
<tr>
  <td style='border-right: 1px solid rgb(200, 200, 200)'>Wave frequencies</td>
  <td>&lt;empty&gt;</td>
</tr>
</table>

\multicolumn从 生成的命令colspan

答案1

好吧,不要让任何人说LaTeX 伴侣没用!显然Doxygen是抄袭的(参见第 250 页)。

这是可行的,尽管表格的外观肯定还有待改善:

\documentclass[12pt]{article}
\listfiles
\usepackage{calc,xtab,array}

\newcommand{\PBS}[1]{\let\temp=\\#1\let\\=\temp}%
\newlength{\tmplength}%

\newenvironment{TabularC}[1]{%
  \setlength{\tmplength}%
  {\linewidth/(#1)-\tabcolsep*2-\arrayrulewidth*(#1+1)/(#1)}%
  \par\begin{xtabular*}{\linewidth}%
    {*{#1}{|>{\PBS
          \raggedright\hspace{0pt}} p{\the\tmplength}}|}%
  }%
  {\end{xtabular*}\par}%

\begin{document}

\begin{TabularC}{2}
  \hline \multicolumn{2}{|p{(\linewidth-\tabcolsep*2-\arrayrulewidth*1)*2/2}|}%
  {Environment  }\tabularnewline\cline{1-2}

  Gravity acceleration &0.\-0  \tabularnewline\cline{1-2}

  Water depth &0.\-0  \tabularnewline\cline{1-2}

  Water density &0.\-0  \tabularnewline\cline{1-2}

  Wave frequencies &$<$empty$>$  \tabularnewline\cline{1-2}
\end{TabularC}

\end{document}

我不确定具体的问题是什么,也许是没有加载包array。(这通常是为什么最小示例非常重要。

编辑 输出\listfiles(将命令放在前言中,如上面所做的那样):

 *File List*
 article.cls    2007/10/19 v1.4h Standard LaTeX document class
  size12.clo    2007/10/19 v1.4h Standard LaTeX file (size option)
    calc.sty    2007/08/22 v4.3 Infix arithmetic (KKT,FJ)
    xtab.sty    2011/07/31 v2.3f Extended supertabular package
   array.sty    2008/09/09 v2.4c Tabular extension package (FMi)
 ***********

相关内容