5

I am making a table in Latex. I cannot seem to figure out how to have the numbers show so that they are of the form 1.23e-04 instead of 1.23e-4. So that the exponents are 2 digits. Thanks for your help in advance.

enter image description here

\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 Answer 1

3

I don't think that the siunitx package currently provides an option to display a fixed number of digits (say, 2) in the exponent component of a number. You may want to contact Joseph Wright, the author and maintainer of the package, and make such a feature request.

Anyway, I also think that your table could stand to be streamlined a bit and be given a more open "look", mainly by omitting most of the \hline directives (and using \midrule and \bottomrule where appropriate). Providing a bit more visual structure to the header material might also be beneficial.

The following screenshot provides a before/after comparison. I hope you will agree that the "after" table is more easily approachable.

enter image description here

\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}
2
  • Thank you for the suggestion. I will see about reaching out to ask about it. Do you know of a way to make certain numbers have two exponent digits manually by chance? Thanks. :)
    – Math4Life
    Commented Mar 19, 2021 at 19:38
  • @Math4Life - I'm afraid I don't know how make \num display a fixed number of digits in the exponent.
    – Mico
    Commented Mar 19, 2021 at 23:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .