tabular/siunitx 环境错误

tabular/siunitx 环境错误

我正在尝试使用在线找到的下表,但具体几行有错误:

 \begin{tabular}{%
    >{\begin{math}}c<{\end{math}}

我不知道是什么导致 latex 编译器发出抱怨。错误消息是

在 \end{math} 处找到未封闭的 \begin{tabular} 在 \end{math} 处找到未封闭的开群 {

有任何想法吗?

\documentclass{article}
\usepackage[utf8]{inputenc}    
\usepackage[T1]{fontenc}
\usepackage{array,booktabs}
\usepackage{siunitx}
 \usepackage{etoolbox}

\begin{document}

\begin{tabular}{%
>{\begin{math}}c<{\end{math}} % first column centered in math mode
S[% second column uses siunitx
output-exponent-marker = {\mathrm{E}},% use `E' as exponent marker
print-implicit-plus,% add + to positive numbers
reset-text-family=false,% use active text font (\ttfamily)
mode=text,% print as text
table-format=1.15e2,% one integer digit, 14 decimal digits, 2 exponent digits
minimum-decimal-digits=15,% pad to 14 decimal places
group-digits=false% don't put digits in blocks of 3
]}
\midrule
\multicolumn{1}{c}{\textrm{\textbf{Variable}}} & \multicolumn{1}{c}{\textrm{\textbf{magnitude}}} \\
\toprule
x_{1}  & 8.337723370858222e-01  \\
y_{2}  & -3.690152225162680e-01  \\
z_{3}  & 7.763961719898990e-01  \\
\bottomrule
\end{tabular}



\end{document}

答案1

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document}

\begin{tblr}{colspec = {Q[c,mode=math] 
                        S[output-exponent-marker = {\mathrm{E}}, % use `E' as exponent marker
                          print-implicit-plus,                   % add + to positive numbers
                          %reset-text-family=false,              % use active text font (\ttfamily)
                          %mode=text,                            % print as text
                          table-format=-1.15e-1,                   % one integer AND 14 decimal digits, 2 exponent digits
                          minimum-decimal-digits=15,             % pad to 14 decimal places
                          group-digits=false                     % don't put digits in blocks of 3
                          ]
                         },
            row{1} = {guard, mode=text, font=\bfseries}
            }
    \toprule
Variable    & Magnitude             \\
    \midrule
    x_{1}  &  8.337723370858222e-01  \\
    y_{2}  & -3.690152225162680e-01  \\
    z_{3}  &  7.763961719890e-01     \\
    \bottomrule
\end{tblr}

\end{document}

在此处输入图片描述

答案2

请帮您的读者一个大忙,让表格更具可读性和视觉吸引力。例如,显示十五 [15!] 位小数的目的是什么?三位小数足以传达您想要通过显示数字传达的任何信息。幸运的是,列S类型可以轻松地将数字四舍五入为预设的位数。请参阅下面的代码以了解此声明的实现。哦,不要使用大胆的标题行,除非您想冒险创建粗俗的印刷效果。

在此处输入图片描述

\documentclass{article}
%%\usepackage[utf8]{inputenc}  % that's the default nowadays   
\usepackage[T1]{fontenc}
\usepackage{array,booktabs,siunitx}

\begin{document}

\begin{tabular}{@{}
   >{$}c<{$} % not ">{\begin{math}}c<{\end{math}}"
   S[round-mode      = places,
     round-precision = 3,
     table-format    = -1.3e-1,
     exponent-product= \cdot] @{}}
   \toprule
   \text{Variable} & {\text{Magnitude}} \\
   \midrule
   x_{1} &  8.337723370858222e-01  \\
   y_{2} & -3.690152225162680e-01  \\
   z_{3} &  7.763961719898990e-01  \\
   \bottomrule
\end{tabular}

\end{document}

相关内容