对齐具有多种数据类型的表格

对齐具有多种数据类型的表格

我有以下数据表:

\begin{table}[h]
    \centering
    \begin{tabular}{l r l}
    \multicolumn{2}{l}{Example} & Value \\
    \midrule
    32 petabyte & \SI{32}{\peta\byte} & \SI{32E15}{\byte} \\
    166 terabecquerel & \SI{166}{\tera\becquerel} & \SI{166E12}{\becquerel} \\
    83 gigapascal & \SI{83}{\giga\pascal} & \SI{83E9}{\pascal} \\
    3.6 megajoule & \SI{3.6}{\mega\joule} & \SI{3.6E6}{\joule} \\
    10 kilowatt & \SI{10}{\kilo\watt} &  \SI{10E3}{\watt} \\
    \addlinespace
    100 milliamp & \SI{100}{\milli\amp} & \SI{100E-3}{\amp} \\
    50 microvolt & \SI{50}{\micro\volt} & \SI{50E-6}{\volt} \\
    1.02 nanosecond & \SI{1.02}{\nano\second} & \SI{1.02E-9}{\second} \\
    62 picometre & \SI{62}{\pico\metre} & \SI{62E-12}{\metre} \\
    4.7 femtogram & \SI{4.7}{\femto\gram} & \SI{4.7E-15}{\gram}
    \end{tabular}
    \caption{Examples of SI prefixes in use.}\label{tbl:prefixesexamples}
\end{table}

我希望第一列与数字和单位之间的空格对齐,第二表与数字和单位符号之间的空格对齐,第三表与 10 之前的乘法符号对齐。这可能吗?我尝试使用和列类型,但这并没有产生所需的结果。似乎至少部分问题是尾数有时包含小数点r@{...},有时不包含小数点。siunitxS

答案1

例如,可以将三列分成六列:

\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{siunitx}
\DeclareSIUnit\byte{B}
\DeclareSIUnit\amp{A}
\begin{document}
\begin{table}[h]
    \centering
    \caption{Examples of SI prefixes in use.}\label{tbl:prefixesexamples}
    \begin{tabular}{
      r@{ }l r@{ }l r@{$\,\times$}l}
    \multicolumn{4}{l}{Example} & \multicolumn{2}{l}{Value} \\
    \midrule
    32 & petabyte       & \num{32} & \si{\peta\byte}       & \num{32} & \SI{E15}{\byte} \\
    166 & terabecquerel & \num{166} & \si{\tera\becquerel} & \num{166} & \SI{E12}{\becquerel} \\
    83 & gigapascal     & \num{83} & \si{\giga\pascal}     & \num{83} & \SI{E9}{\pascal} \\
    3.6 & megajoule     & \num{3.6} & \si{\mega\joule}     & \num{3.6} & \SI{E6}{\joule} \\
    10 & kilowatt       & \num{10} & \si{\kilo\watt}       & \num{10} & \SI{E3}{\watt} \\
    \addlinespace
    100 & milliamp      & \num{100} & \si{\milli\amp}      & \num{100} & \SI{E-3}{\amp} \\
    50 & microvolt      & \num{50} & \si{\micro\volt}      & \num{50} & \SI{E-6}{\volt} \\
    1.02 & nanosecond   & \num{1.02} & \si{\nano\second}   & \num{1.02} & \SI{E-9}{\second} \\
    62 & picometre      & \num{62} & \si{\pico\metre}      & \num{62} & \SI{E-12}{\metre} \\
    4.7 & femtogram     & \num{4.7} & \si{\femto\gram}     & \num{4.7} & \SI{E-15}{\gram}
    \end{tabular}
\end{table}
\end{document}

结果

答案2

进行一些拉伸:

\documentclass{article}
\usepackage{siunitx,booktabs}

\DeclareSIUnit{\byte}{b}

\begin{document}

\begin{table}[htp]
\centering

\begin{tabular}{
  r
  @{ }% a space between the columns
  l
  r
  @{\,}% a thin space between the columns
  l
  r
  @{${}\times{}$}% \times between the columns
  l
}
\toprule
\multicolumn{2}{c}{Example} & \multicolumn{4}{c}{Value} \\
\midrule
  \num{32} & petabyte      &   \num{32} & \si{\peta\byte}      & \num{32}&\SI[parse-numbers=false]{10^{15}}{\byte} \\
 \num{166} & terabecquerel &  \num{166} & \si{\tera\becquerel} & \num{166}&\SI[parse-numbers=false]{10^{12}}{\becquerel} \\
  \num{83} & gigapascal    &   \num{83} & \si{\giga\pascal}    & \num{83}&\SI[parse-numbers=false]{10^{9}}{\pascal} \\
 \num{3.6} & megajoule     &  \num{3.6} & \si{\mega\joule}     & \num{3.6}&\SI[parse-numbers=false]{10^{6}}{\joule} \\
  \num{10} & kilowatt      &   \num{10} & \si{\kilo\watt}      &  \num{10}&\SI[parse-numbers=false]{10^{3}}{\watt} \\
\addlinespace
 \num{100} & milliamp      &  \num{100} & \si{\milli\ampere}   & \num{100}&\SI[parse-numbers=false]{10^{-3}}{\ampere} \\
  \num{50} & microvolt     &   \num{50} & \si{\micro\volt}     & \num{50}&\SI[parse-numbers=false]{10^{-6}}{\volt} \\
\num{1.02} & nanosecond    & \num{1.02} & \si{\nano\second}    & \num{1.02}&\SI[parse-numbers=false]{10^{-9}}{\second} \\
  \num{62} & picometre     &   \num{62} & \si{\pico\metre}     & \num{62}&\SI[parse-numbers=false]{10^{-12}}{\metre} \\
 \num{4.7} & femtogram     &  \num{4.7} & \si{\femto\gram}     & \num{4.7}&\SI[parse-numbers=false]{10^{-15}}{\gram}\\
\bottomrule
\end{tabular}

\caption{Examples of SI prefixes in use.}\label{tbl:prefixesexamples}

\end{table}

\end{document}

在此处输入图片描述

相关内容