Problems with numbers (result of calculations) alignment using siunitx package inside tabular...

How to avoid grep command finding commented out strings in the source file?

Is thermodynamics only applicable to systems in equilibrium?

System.QueryException: unexpected token: results

How do I tell my manager that his code review comment is wrong?

Is it appropriate to refer to God as "It"?

Shoteh in the gemara

Why was Germany not as successful as other Europeans in establishing overseas colonies?

Stark VS Thanos

A non-technological, repeating, visible object in the sky, holding its position in the sky for hours

Printing a string when grep does not get a match

CRT Oscilloscope - part of the plot is missing

Field Length Validation for Desktop Application which has maximum 1000 characters

Plagiarism in class. Could it be my fault?

Binary Numbers Magic Trick

What happened to Rhaegal?

Declining lunch invitation from new work because I will be fasting

Copying spell into spellbook time required, consecutive or disparate?

Method and way to highlight the validation message in the web page by using Selenium IDE

Any examples of headwear for races with animal ears?

Hang 20lb projector screen on hardieplank

How to creep the reader out with what seems like a normal person?

Is Cola "probably the best-known" Latin word in the world? If not, which might it be?

What word means "to make something obsolete"?

Write to EXCEL from SQL DB using VBA script



Problems with numbers (result of calculations) alignment using siunitx package inside tabular environment


siunitx: Alignment Problems with numbers in parenthesisTabular and grid typesettingProblems with siunitx package?siunitx tabular numbers with separated uncertaintyBasic S Column Alignment with siunitx packagephantomsection inside tabular: alignment problems`siunitx` interferes with `array` and `tabular environment`Problems loading siunitx package“Undefined control sequence” Regression table from StataTable using siunitx number alignment affecting rows without numbers













1















I'm having some problems when try align numbers, results from calculations, using siunitx package. That is my code.



documentclass{article}
usepackage{siunitx}
usepackage{fp}
usepackage{booktabs}

% #1: decimal places (default=2), #2: value
newcommand*{KelvinToCelsius}[2][2]{%
FPevaltempKtoC{round((#2-273.15):#1)}%
num{tempKtoC}%
}

begin{document}
begin{tabular}{S S}
toprule
si{kelvin} & si{celsius} \
midrule
10.3 & {KelvinToCelsius{10.3}} \
200.34 & {KelvinToCelsius{200.34}} \
500.26 & {KelvinToCelsius{500.26}} \
1200.5 & {KelvinToCelsius[1]{1200.5}}\
12345 & {KelvinToCelsius[0]{12345}} \
bottomrule
end{tabular}
end{document}


Which produces:



output image



Note that the numbers in second column don't be align.



How to solve this?










share|improve this question























  • Maybe section 7.2 "Expanding content in tables" of the siunitx manual can help you.

    – leandriis
    2 hours ago











  • You need something expandable, use the xfp package instead of fp and avoid optional arguments.

    – Ulrike Fischer
    2 hours ago
















1















I'm having some problems when try align numbers, results from calculations, using siunitx package. That is my code.



documentclass{article}
usepackage{siunitx}
usepackage{fp}
usepackage{booktabs}

% #1: decimal places (default=2), #2: value
newcommand*{KelvinToCelsius}[2][2]{%
FPevaltempKtoC{round((#2-273.15):#1)}%
num{tempKtoC}%
}

begin{document}
begin{tabular}{S S}
toprule
si{kelvin} & si{celsius} \
midrule
10.3 & {KelvinToCelsius{10.3}} \
200.34 & {KelvinToCelsius{200.34}} \
500.26 & {KelvinToCelsius{500.26}} \
1200.5 & {KelvinToCelsius[1]{1200.5}}\
12345 & {KelvinToCelsius[0]{12345}} \
bottomrule
end{tabular}
end{document}


Which produces:



output image



Note that the numbers in second column don't be align.



How to solve this?










share|improve this question























  • Maybe section 7.2 "Expanding content in tables" of the siunitx manual can help you.

    – leandriis
    2 hours ago











  • You need something expandable, use the xfp package instead of fp and avoid optional arguments.

    – Ulrike Fischer
    2 hours ago














1












1








1








I'm having some problems when try align numbers, results from calculations, using siunitx package. That is my code.



documentclass{article}
usepackage{siunitx}
usepackage{fp}
usepackage{booktabs}

% #1: decimal places (default=2), #2: value
newcommand*{KelvinToCelsius}[2][2]{%
FPevaltempKtoC{round((#2-273.15):#1)}%
num{tempKtoC}%
}

begin{document}
begin{tabular}{S S}
toprule
si{kelvin} & si{celsius} \
midrule
10.3 & {KelvinToCelsius{10.3}} \
200.34 & {KelvinToCelsius{200.34}} \
500.26 & {KelvinToCelsius{500.26}} \
1200.5 & {KelvinToCelsius[1]{1200.5}}\
12345 & {KelvinToCelsius[0]{12345}} \
bottomrule
end{tabular}
end{document}


Which produces:



output image



Note that the numbers in second column don't be align.



How to solve this?










share|improve this question














I'm having some problems when try align numbers, results from calculations, using siunitx package. That is my code.



documentclass{article}
usepackage{siunitx}
usepackage{fp}
usepackage{booktabs}

% #1: decimal places (default=2), #2: value
newcommand*{KelvinToCelsius}[2][2]{%
FPevaltempKtoC{round((#2-273.15):#1)}%
num{tempKtoC}%
}

begin{document}
begin{tabular}{S S}
toprule
si{kelvin} & si{celsius} \
midrule
10.3 & {KelvinToCelsius{10.3}} \
200.34 & {KelvinToCelsius{200.34}} \
500.26 & {KelvinToCelsius{500.26}} \
1200.5 & {KelvinToCelsius[1]{1200.5}}\
12345 & {KelvinToCelsius[0]{12345}} \
bottomrule
end{tabular}
end{document}


Which produces:



output image



Note that the numbers in second column don't be align.



How to solve this?







tables siunitx






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 3 hours ago









GRSousaJrGRSousaJr

3257




3257













  • Maybe section 7.2 "Expanding content in tables" of the siunitx manual can help you.

    – leandriis
    2 hours ago











  • You need something expandable, use the xfp package instead of fp and avoid optional arguments.

    – Ulrike Fischer
    2 hours ago



















  • Maybe section 7.2 "Expanding content in tables" of the siunitx manual can help you.

    – leandriis
    2 hours ago











  • You need something expandable, use the xfp package instead of fp and avoid optional arguments.

    – Ulrike Fischer
    2 hours ago

















Maybe section 7.2 "Expanding content in tables" of the siunitx manual can help you.

– leandriis
2 hours ago





Maybe section 7.2 "Expanding content in tables" of the siunitx manual can help you.

– leandriis
2 hours ago













You need something expandable, use the xfp package instead of fp and avoid optional arguments.

– Ulrike Fischer
2 hours ago





You need something expandable, use the xfp package instead of fp and avoid optional arguments.

– Ulrike Fischer
2 hours ago










2 Answers
2






active

oldest

votes


















2














Use the full power of expl3; the KelvinToCelsius command must be expandable and you can have it even with an optional argument.



Using fpeval frees you from fp.



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

% #1: decimal places (default=2), #2: value
NewExpandableDocumentCommand{KelvinToCelsius}{O{2}m}{%
fpeval{round(#2-273.15,#1)}%
}

begin{document}

begin{tabular}{
S[table-format=5.2]
S[table-format=5.2]
}
toprule
{si{kelvin}} & {si{celsius}} \
midrule
10.3 & KelvinToCelsius{10.3} \
200.34 & KelvinToCelsius{200.34} \
500.26 & KelvinToCelsius{500.26} \
1200.5 & KelvinToCelsius[1]{1200.5}\
12345 & KelvinToCelsius[0]{12345} \
bottomrule
end{tabular}

end{document}


enter image description here






share|improve this answer































    1














    The commands must be expandable so that siunitx sees "pure numbers". Better use the xfp package for the calculations and avoid optional arguments.



    documentclass{article}
    usepackage{siunitx}
    usepackage{xfp}
    usepackage{booktabs}

    % #1: decimal places (default=2), #2: value
    newcommand*{KelvinToCelsius}[1]{% no optional argument
    fpeval{round((#1-273.15)/2,2)}%
    }

    begin{document}
    begin{tabular}{S S}
    toprule
    si{kelvin} & si{celsius} \
    midrule
    10.3 & KelvinToCelsius{10.3} \
    200.34 & KelvinToCelsius{200.34} \
    500.26 & KelvinToCelsius{500.26} \
    %1200.5 & {KelvinToCelsius[1]{1200.5}}\
    %12345 & {KelvinToCelsius[0]{12345}} \
    bottomrule
    end{tabular}
    end{document}


    enter image description here






    share|improve this answer
























    • Why no optional argument? ;-)

      – egreg
      2 hours ago











    • @egreg because I was too lazy to check if it would work with xparse.

      – Ulrike Fischer
      2 hours ago












    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "85"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f488277%2fproblems-with-numbers-result-of-calculations-alignment-using-siunitx-package-i%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Use the full power of expl3; the KelvinToCelsius command must be expandable and you can have it even with an optional argument.



    Using fpeval frees you from fp.



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

    % #1: decimal places (default=2), #2: value
    NewExpandableDocumentCommand{KelvinToCelsius}{O{2}m}{%
    fpeval{round(#2-273.15,#1)}%
    }

    begin{document}

    begin{tabular}{
    S[table-format=5.2]
    S[table-format=5.2]
    }
    toprule
    {si{kelvin}} & {si{celsius}} \
    midrule
    10.3 & KelvinToCelsius{10.3} \
    200.34 & KelvinToCelsius{200.34} \
    500.26 & KelvinToCelsius{500.26} \
    1200.5 & KelvinToCelsius[1]{1200.5}\
    12345 & KelvinToCelsius[0]{12345} \
    bottomrule
    end{tabular}

    end{document}


    enter image description here






    share|improve this answer




























      2














      Use the full power of expl3; the KelvinToCelsius command must be expandable and you can have it even with an optional argument.



      Using fpeval frees you from fp.



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

      % #1: decimal places (default=2), #2: value
      NewExpandableDocumentCommand{KelvinToCelsius}{O{2}m}{%
      fpeval{round(#2-273.15,#1)}%
      }

      begin{document}

      begin{tabular}{
      S[table-format=5.2]
      S[table-format=5.2]
      }
      toprule
      {si{kelvin}} & {si{celsius}} \
      midrule
      10.3 & KelvinToCelsius{10.3} \
      200.34 & KelvinToCelsius{200.34} \
      500.26 & KelvinToCelsius{500.26} \
      1200.5 & KelvinToCelsius[1]{1200.5}\
      12345 & KelvinToCelsius[0]{12345} \
      bottomrule
      end{tabular}

      end{document}


      enter image description here






      share|improve this answer


























        2












        2








        2







        Use the full power of expl3; the KelvinToCelsius command must be expandable and you can have it even with an optional argument.



        Using fpeval frees you from fp.



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

        % #1: decimal places (default=2), #2: value
        NewExpandableDocumentCommand{KelvinToCelsius}{O{2}m}{%
        fpeval{round(#2-273.15,#1)}%
        }

        begin{document}

        begin{tabular}{
        S[table-format=5.2]
        S[table-format=5.2]
        }
        toprule
        {si{kelvin}} & {si{celsius}} \
        midrule
        10.3 & KelvinToCelsius{10.3} \
        200.34 & KelvinToCelsius{200.34} \
        500.26 & KelvinToCelsius{500.26} \
        1200.5 & KelvinToCelsius[1]{1200.5}\
        12345 & KelvinToCelsius[0]{12345} \
        bottomrule
        end{tabular}

        end{document}


        enter image description here






        share|improve this answer













        Use the full power of expl3; the KelvinToCelsius command must be expandable and you can have it even with an optional argument.



        Using fpeval frees you from fp.



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

        % #1: decimal places (default=2), #2: value
        NewExpandableDocumentCommand{KelvinToCelsius}{O{2}m}{%
        fpeval{round(#2-273.15,#1)}%
        }

        begin{document}

        begin{tabular}{
        S[table-format=5.2]
        S[table-format=5.2]
        }
        toprule
        {si{kelvin}} & {si{celsius}} \
        midrule
        10.3 & KelvinToCelsius{10.3} \
        200.34 & KelvinToCelsius{200.34} \
        500.26 & KelvinToCelsius{500.26} \
        1200.5 & KelvinToCelsius[1]{1200.5}\
        12345 & KelvinToCelsius[0]{12345} \
        bottomrule
        end{tabular}

        end{document}


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        egregegreg

        738k8919393269




        738k8919393269























            1














            The commands must be expandable so that siunitx sees "pure numbers". Better use the xfp package for the calculations and avoid optional arguments.



            documentclass{article}
            usepackage{siunitx}
            usepackage{xfp}
            usepackage{booktabs}

            % #1: decimal places (default=2), #2: value
            newcommand*{KelvinToCelsius}[1]{% no optional argument
            fpeval{round((#1-273.15)/2,2)}%
            }

            begin{document}
            begin{tabular}{S S}
            toprule
            si{kelvin} & si{celsius} \
            midrule
            10.3 & KelvinToCelsius{10.3} \
            200.34 & KelvinToCelsius{200.34} \
            500.26 & KelvinToCelsius{500.26} \
            %1200.5 & {KelvinToCelsius[1]{1200.5}}\
            %12345 & {KelvinToCelsius[0]{12345}} \
            bottomrule
            end{tabular}
            end{document}


            enter image description here






            share|improve this answer
























            • Why no optional argument? ;-)

              – egreg
              2 hours ago











            • @egreg because I was too lazy to check if it would work with xparse.

              – Ulrike Fischer
              2 hours ago
















            1














            The commands must be expandable so that siunitx sees "pure numbers". Better use the xfp package for the calculations and avoid optional arguments.



            documentclass{article}
            usepackage{siunitx}
            usepackage{xfp}
            usepackage{booktabs}

            % #1: decimal places (default=2), #2: value
            newcommand*{KelvinToCelsius}[1]{% no optional argument
            fpeval{round((#1-273.15)/2,2)}%
            }

            begin{document}
            begin{tabular}{S S}
            toprule
            si{kelvin} & si{celsius} \
            midrule
            10.3 & KelvinToCelsius{10.3} \
            200.34 & KelvinToCelsius{200.34} \
            500.26 & KelvinToCelsius{500.26} \
            %1200.5 & {KelvinToCelsius[1]{1200.5}}\
            %12345 & {KelvinToCelsius[0]{12345}} \
            bottomrule
            end{tabular}
            end{document}


            enter image description here






            share|improve this answer
























            • Why no optional argument? ;-)

              – egreg
              2 hours ago











            • @egreg because I was too lazy to check if it would work with xparse.

              – Ulrike Fischer
              2 hours ago














            1












            1








            1







            The commands must be expandable so that siunitx sees "pure numbers". Better use the xfp package for the calculations and avoid optional arguments.



            documentclass{article}
            usepackage{siunitx}
            usepackage{xfp}
            usepackage{booktabs}

            % #1: decimal places (default=2), #2: value
            newcommand*{KelvinToCelsius}[1]{% no optional argument
            fpeval{round((#1-273.15)/2,2)}%
            }

            begin{document}
            begin{tabular}{S S}
            toprule
            si{kelvin} & si{celsius} \
            midrule
            10.3 & KelvinToCelsius{10.3} \
            200.34 & KelvinToCelsius{200.34} \
            500.26 & KelvinToCelsius{500.26} \
            %1200.5 & {KelvinToCelsius[1]{1200.5}}\
            %12345 & {KelvinToCelsius[0]{12345}} \
            bottomrule
            end{tabular}
            end{document}


            enter image description here






            share|improve this answer













            The commands must be expandable so that siunitx sees "pure numbers". Better use the xfp package for the calculations and avoid optional arguments.



            documentclass{article}
            usepackage{siunitx}
            usepackage{xfp}
            usepackage{booktabs}

            % #1: decimal places (default=2), #2: value
            newcommand*{KelvinToCelsius}[1]{% no optional argument
            fpeval{round((#1-273.15)/2,2)}%
            }

            begin{document}
            begin{tabular}{S S}
            toprule
            si{kelvin} & si{celsius} \
            midrule
            10.3 & KelvinToCelsius{10.3} \
            200.34 & KelvinToCelsius{200.34} \
            500.26 & KelvinToCelsius{500.26} \
            %1200.5 & {KelvinToCelsius[1]{1200.5}}\
            %12345 & {KelvinToCelsius[0]{12345}} \
            bottomrule
            end{tabular}
            end{document}


            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 hours ago









            Ulrike FischerUlrike Fischer

            202k9310695




            202k9310695













            • Why no optional argument? ;-)

              – egreg
              2 hours ago











            • @egreg because I was too lazy to check if it would work with xparse.

              – Ulrike Fischer
              2 hours ago



















            • Why no optional argument? ;-)

              – egreg
              2 hours ago











            • @egreg because I was too lazy to check if it would work with xparse.

              – Ulrike Fischer
              2 hours ago

















            Why no optional argument? ;-)

            – egreg
            2 hours ago





            Why no optional argument? ;-)

            – egreg
            2 hours ago













            @egreg because I was too lazy to check if it would work with xparse.

            – Ulrike Fischer
            2 hours ago





            @egreg because I was too lazy to check if it would work with xparse.

            – Ulrike Fischer
            2 hours ago


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f488277%2fproblems-with-numbers-result-of-calculations-alignment-using-siunitx-package-i%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Gersau Kjelder | Navigasjonsmeny46°59′0″N 8°31′0″E46°59′0″N...

            Nässjö kommun Tettstader | Kjelder | NavigasjonsmenyeVIAFISNIGeoNamesMusicBrainz (area)

            Kvitkval Innhaldsliste Taksonomi og utvikling | Utsjånad og levevis | Utbreiing | Åtferd |...