TransWikia.com

How to make make numbers in the 1e-01 format instead of 1e-1

TeX - LaTeX Asked by Math4Life on April 18, 2021

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]{{leavevmodecolor{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{hidewidthraisebox{0.2ex}{--}hidewidthcr$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}

One Answer

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]{{leavevmodecolor{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{hidewidthraisebox{0.2ex}{--}hidewidthcr$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}

Answered by Mico on April 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP