使用 siunitx 以所需单位显示一列

使用 siunitx 以所需单位显示一列

我有这个基本表:

\begin{table}[]
\centering
\begin{tabular}{lll}
 & a/W & b/W \\
v & 0.00001 & 1000 \\
w & 0.002 & 200 \\
x & 0.000003 & 30000 \\
y & 0.00004 & 40
\end{tabular}
\caption{Actual Data}
\label{tab:actual}
\end{table}

该表格主体中的数字是通过编程生成的。我想为每列选择一个单位,值会自动转换为该单位。我可以使用 siunitx 实现这一点吗?输出应该如下所示:

\begin{table}[]
\centering
\begin{tabular}{lll}
 & a/mW & b/kW \\
v & 0.01 & 1 \\
w & 2 & 0.2 \\
x & 0.003 & 30 \\
y & 0.04 & 0.04
\end{tabular}
\caption{Can I achieve this using siunitx?}
\label{tab:actual}
\end{table}

答案1

我不确定你到底想如何具体说明这些因素。假设我们可以进行一些手动工作,那么我们可以使用exponent-mode = fixed合适的fixed-exponent

\documentclass{article}

\usepackage{siunitx}

\begin{document}
\begin{table}
\centering
% Shared settings
\sisetup{exponent-mode = fixed, drop-exponent}
\begin{tabular}{
      l
      S[table-format = 1.3, fixed-exponent = -3]
      S[table-format = 2.3, fixed-exponent = 3]}
 & {a/\unit{\mW}} & {b/\unit{\kW}} \\
v & 0.00001 & 1000 \\
w & 0.002 & 200 \\
x & 0.000003 & 30000 \\
y & 0.00004 & 40
\end{tabular}
\end{table}
\end{document}

相关内容