我正在用 Latex 制作表格。我似乎无法弄清楚如何显示数字,以便它们采用1.23e-04
而不是 的形式1.23e-4
。这样指数就是 2 位数字。提前感谢您的帮助。
\documentclass[dvipsnames]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{amsthm}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage{bbm,mathtools}
\newcommand{\an}[1]{{\leavevmode\color{BrickRed}{{{#1}}}}}
\newcommand{\bs}[1]{\boldsymbol{#1}}
\newcommand{\R}{\mathbbm{R}}
\newtheorem*{lemma}{Lemma}
\newtheorem{theorem}{Theorem}
\newtheorem{definition}{Definition}
\usepackage{float}
\usepackage[backend=biber,style=numeric, maxnames=99, sorting=none]{biblatex}
\bibliography{refs}
\DeclareMathOperator*{\argmax}{\arg\!\max}
\newcommand{\Zstroke}{%
\text{\ooalign{\hidewidth\raisebox{0.2ex}{--}\hidewidth\cr$Z$\cr}}%
}
\usepackage{makecell}
\usepackage{subfig}
\usepackage{authblk}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{booktabs}
\usepackage[ group-separator={,} ]{siunitx}
\usepackage[referable]{threeparttablex}
\newcolumntype{L}{@{}l@{}} % a left column with no intercolumn space on either side
\newcommand{\mc}[1]{\multicolumn{1}{c}{#1}} % shorthand macro for column headings
\sisetup{
output-exponent-marker=\ensuremath{\mathrm{e}},
exponent-product={},
retain-explicit-plus,
input-open-uncertainty = ,
input-close-uncertainty = ,
table-align-text-pre = false,
table-align-text-post = false,
round-mode=places,
round-precision=2,
table-space-text-pre = (,
table-space-text-post = ),
}
\begin{document}
\begin{table}[ht]
\label{BetaTable}
\centering
\begin{threeparttable}
\begin{tabular}{
l
S[table-format =-1.2e-01]
S[table-format =-1.2e-01]
S[table-format =-1.2e-01]
S[table-format =-1.2e-01]
l
}
\toprule
%\multicolumn{5}{l}{Minimal Working Example} \\
\midrule
\multicolumn{1}{l}{$\beta$} & \mc{$L_{2w}$ Error}& \mc{$L_{2}$ Error}& \mc{$L_1$ Error}& \mc{$L_{\infty}$ Error} & \mc{\# Points}\\
\midrule
1&2.898533e-02&2.531649e-02&1.931025e-03&9.058511e-02&203\\ \hline 2&1.231133e-03&1.309571e-03&6.086069e-05&2.432587e-03&715\\ \hline 3&1.654175e-04&2.448292e-04&4.529361e-06&3.485143e-04&1289\\ \hline 10&7.326445e-12&4.236199e-11&4.243224e-14&6.256687e-11&4704\\ \hline 15&2.812056e-13&1.015514e-12&2.402226e-16&1.118734e-11&7038\\ \hline
\hline
\end{tabular}
\end{threeparttable}
\end{table}
\begin{footnotesize}
\printbibliography[heading=none]
\end{footnotesize}
\end{document}
答案1
我认为该siunitx
软件包目前不提供在数字的指数部分显示固定位数(例如 2)的选项。您可能需要联系该软件包的作者和维护者 Joseph Wright,并提出这样的功能请求。
无论如何,我还认为您的表格可以稍微精简一下,并赋予其更开放的“外观”,主要是通过省略大多数\hline
指令(并在适当的情况下使用\midrule
and \bottomrule
)。为标题材料提供更多的视觉结构也可能有益。
以下截图提供了前后对比。我希望你会同意“之后”的表格更容易理解。
\documentclass[dvipsnames]{article}
%%\usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage[T1]{fontenc} % <-- new
%%\usepackage{amsmath} % is loaded automatically by 'mathtools'
%%\usepackage{amsfonts} % better to load 'amssymb' (which, in turn, loads amsfonts)
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{amsthm}
\usepackage{xcolor}
\usepackage{tikz}
%%%\usepackage{xcolor} % don't load packages more than once
\usepackage{bbm,mathtools}
\newcommand{\an}[1]{{\leavevmode\color{BrickRed}{{{#1}}}}}
\newcommand{\bs}[1]{\boldsymbol{#1}}
\newcommand{\R}{\mathbbm{R}}
\newtheorem*{lemma}{Lemma}
\newtheorem{theorem}{Theorem}
\newtheorem{definition}{Definition}
\DeclareMathOperator*{\argmax}{\arg\!\max} % really? should it be "{\arg\,max}" ?
\newcommand{\Zstroke}{%
\text{\ooalign{\hidewidth\raisebox{0.2ex}{--}\hidewidth\cr$Z$\cr}}%
}
\usepackage{makecell}
\usepackage{subfig}
\usepackage{authblk}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{booktabs}
\usepackage[referable]{threeparttablex}
\newcolumntype{L}{@{}l@{}} % a left column with no intercolumn space
\newcommand{\mc}[1]{\multicolumn{1}{c}{#1}} % shorthand macro for column headings
\usepackage{siunitx}
\sisetup{
fixed-exponent = 2,
group-separator = {,} ,
output-exponent-marker = \ensuremath{\mathrm{e}},
exponent-product = {},
retain-explicit-plus ,
retain-zero-exponent ,
input-open-uncertainty = ,
input-close-uncertainty = ,
table-align-text-pre = false,
table-align-text-post = false,
round-mode = places,
round-precision = 2,
table-space-text-pre = (,
table-space-text-post = ),
}
\usepackage{hyperref} % load this package last
\begin{document}
%%% before %%%
\begin{table}[ht]
\label{BetaTable}
\centering
\begin{threeparttable}
\begin{tabular}{
l
S[table-format =-1.2e-01]
S[table-format =-1.2e-01]
S[table-format =-1.2e-01]
S[table-format =-1.2e-01]
l
}
\multicolumn{5}{@{}l}{\textcolor{red}{\texttt{before}}} \\[1ex]
\toprule
%\multicolumn{5}{l}{Minimal Working Example} \\
\midrule
\multicolumn{1}{l}{$\beta$} & \mc{$L_{2w}$ Error}& \mc{$L_{2}$ Error}& \mc{$L_1$ Error}& \mc{$L_{\infty}$ Error} & \mc{\# Points}\\
\midrule
1&2.898533e-02&2.531649e-02&1.931025e-03&9.058511e-02&203\\ \hline 2&1.231133e-03&1.309571e-03&6.086069e-05&2.432587e-03&715\\ \hline 3&1.654175e-04&2.448292e-04&4.529361e-06&3.485143e-04&1289\\ \hline 10&7.326445e-12&4.236199e-11&4.243224e-14&6.256687e-11&4704\\ \hline 15&2.812056e-13&1.015514e-12&2.402226e-16&1.118734e-11&7038\\ \hline
\hline
\end{tabular}
\end{threeparttable}
\end{table}
%%% after %%%
\begin{table}[ht]
\label{BetaTableRevised}
\sisetup{ table-space-text-pre = , table-space-text-post = , }
\centering
%\begin{threeparttable} % doesn't seem to be needed
\begin{tabular}{@{}
r
*{4}{S[table-format = 1.2e-02] }
S[table-format = 4.0]
@{}}
\multicolumn{5}{@{}l}{\textcolor{red}{\texttt{after}}} \\[1ex]
\toprule
{$\beta$} & \multicolumn{4}{c}{Errors} & {\# Points} \\
\cmidrule(lr){2-5}
& {$L_{2w}$}& {$L_{2}$}& {$L_1$}& {$L_{\infty}$} & \\
\midrule
1 &2.898533e-02&2.531649e-02&1.931025e-03&9.058511e-02& 203\\ %\hline
2 &1.231133e-03&1.309571e-03&6.086069e-05&2.432587e-03& 715\\ %\hline
3 &1.654175e-04&2.448292e-04&4.529361e-06&3.485143e-04&1289\\ %\hline
10&7.326445e-12&4.236199e-11&4.243224e-14&6.256687e-11&4704\\ %\hline
15&2.812056e-13&1.015514e-12&2.402226e-16&1.118734e-11&7038\\ %\hline
\bottomrule
\end{tabular}
%\end{threeparttable}
\end{table}
\end{document}