Improving alignment of signed fractions in table












10















I would like to find a way to better align signed fractions in a table. Take the following example:



documentclass{article}
usepackage{amsmath}
usepackage{booktabs}

begin{document}

begin{table}
centering
begin{tabular}{rr} toprule
$alpha$ & $beta$ \ midrule
$-frac{9}{2}$ & $-frac{1}{6}$ \[0.8ex]
$-frac{7}{2}$ & $frac{1}{30}$ \[0.5ex]
bottomrule
end{tabular}
end{table}

end{document}


This gives:



enter image description here



I don't like the look of the second column, which I think would look better if 1/30 would be centrally aligned with 1/6. By playing around, I noticed that changing the type of the second column to c and adding a phantom{-} in front of 1/30, i.e.,



begin{table}
centering
begin{tabular}{rc} toprule
$alpha$ & $beta$ \ midrule
$-frac{9}{2}$ & $-frac{1}{6}$ \[0.8ex]
$-frac{7}{2}$ & $phantom{-}frac{1}{30}$ \[0.8ex]
bottomrule
end{tabular}
end{table}


I get what I think is a much better looking result:



enter image description here



This, however, requires that I manually add the phantom{-} command for every positive entry in my tables: I want to avoid this because the tables are large. So I have two questions:




  1. Is there a way in LaTeX or through a package which I can automate the addition of phantom{-}?

  2. Do you know of a better way to get the kind of alignment of fractions I'm looking for?










share|improve this question

























  • What should be done if an entire column consists of positive numbers?

    – Mico
    Dec 30 '18 at 14:09











  • Well, for positive numbers no change in alignment is necessary, so nothing needs to be done.

    – user1362373
    Dec 30 '18 at 14:11











  • You could put the negative signs into a separate column, or create a new command (+ ?) to handle phantom{-}.

    – John Kormylo
    Dec 30 '18 at 15:20






  • 2





    Adding phantom{-} is far less complicated than creating a macro for this, IMHO.

    – AboAmmar
    Dec 30 '18 at 15:54






  • 1





    the main problem here is that math fonts should have a minus sign as binary operator and a minus sign (shorter, more like an hyphen) for negative numbers; sadly the two are typeset the same and it is ugly (despite the fact nobody complains, but life is a path of solitude if you seek enlightenment)

    – user4686
    Dec 30 '18 at 22:17
















10















I would like to find a way to better align signed fractions in a table. Take the following example:



documentclass{article}
usepackage{amsmath}
usepackage{booktabs}

begin{document}

begin{table}
centering
begin{tabular}{rr} toprule
$alpha$ & $beta$ \ midrule
$-frac{9}{2}$ & $-frac{1}{6}$ \[0.8ex]
$-frac{7}{2}$ & $frac{1}{30}$ \[0.5ex]
bottomrule
end{tabular}
end{table}

end{document}


This gives:



enter image description here



I don't like the look of the second column, which I think would look better if 1/30 would be centrally aligned with 1/6. By playing around, I noticed that changing the type of the second column to c and adding a phantom{-} in front of 1/30, i.e.,



begin{table}
centering
begin{tabular}{rc} toprule
$alpha$ & $beta$ \ midrule
$-frac{9}{2}$ & $-frac{1}{6}$ \[0.8ex]
$-frac{7}{2}$ & $phantom{-}frac{1}{30}$ \[0.8ex]
bottomrule
end{tabular}
end{table}


I get what I think is a much better looking result:



enter image description here



This, however, requires that I manually add the phantom{-} command for every positive entry in my tables: I want to avoid this because the tables are large. So I have two questions:




  1. Is there a way in LaTeX or through a package which I can automate the addition of phantom{-}?

  2. Do you know of a better way to get the kind of alignment of fractions I'm looking for?










share|improve this question

























  • What should be done if an entire column consists of positive numbers?

    – Mico
    Dec 30 '18 at 14:09











  • Well, for positive numbers no change in alignment is necessary, so nothing needs to be done.

    – user1362373
    Dec 30 '18 at 14:11











  • You could put the negative signs into a separate column, or create a new command (+ ?) to handle phantom{-}.

    – John Kormylo
    Dec 30 '18 at 15:20






  • 2





    Adding phantom{-} is far less complicated than creating a macro for this, IMHO.

    – AboAmmar
    Dec 30 '18 at 15:54






  • 1





    the main problem here is that math fonts should have a minus sign as binary operator and a minus sign (shorter, more like an hyphen) for negative numbers; sadly the two are typeset the same and it is ugly (despite the fact nobody complains, but life is a path of solitude if you seek enlightenment)

    – user4686
    Dec 30 '18 at 22:17














10












10








10


1






I would like to find a way to better align signed fractions in a table. Take the following example:



documentclass{article}
usepackage{amsmath}
usepackage{booktabs}

begin{document}

begin{table}
centering
begin{tabular}{rr} toprule
$alpha$ & $beta$ \ midrule
$-frac{9}{2}$ & $-frac{1}{6}$ \[0.8ex]
$-frac{7}{2}$ & $frac{1}{30}$ \[0.5ex]
bottomrule
end{tabular}
end{table}

end{document}


This gives:



enter image description here



I don't like the look of the second column, which I think would look better if 1/30 would be centrally aligned with 1/6. By playing around, I noticed that changing the type of the second column to c and adding a phantom{-} in front of 1/30, i.e.,



begin{table}
centering
begin{tabular}{rc} toprule
$alpha$ & $beta$ \ midrule
$-frac{9}{2}$ & $-frac{1}{6}$ \[0.8ex]
$-frac{7}{2}$ & $phantom{-}frac{1}{30}$ \[0.8ex]
bottomrule
end{tabular}
end{table}


I get what I think is a much better looking result:



enter image description here



This, however, requires that I manually add the phantom{-} command for every positive entry in my tables: I want to avoid this because the tables are large. So I have two questions:




  1. Is there a way in LaTeX or through a package which I can automate the addition of phantom{-}?

  2. Do you know of a better way to get the kind of alignment of fractions I'm looking for?










share|improve this question
















I would like to find a way to better align signed fractions in a table. Take the following example:



documentclass{article}
usepackage{amsmath}
usepackage{booktabs}

begin{document}

begin{table}
centering
begin{tabular}{rr} toprule
$alpha$ & $beta$ \ midrule
$-frac{9}{2}$ & $-frac{1}{6}$ \[0.8ex]
$-frac{7}{2}$ & $frac{1}{30}$ \[0.5ex]
bottomrule
end{tabular}
end{table}

end{document}


This gives:



enter image description here



I don't like the look of the second column, which I think would look better if 1/30 would be centrally aligned with 1/6. By playing around, I noticed that changing the type of the second column to c and adding a phantom{-} in front of 1/30, i.e.,



begin{table}
centering
begin{tabular}{rc} toprule
$alpha$ & $beta$ \ midrule
$-frac{9}{2}$ & $-frac{1}{6}$ \[0.8ex]
$-frac{7}{2}$ & $phantom{-}frac{1}{30}$ \[0.8ex]
bottomrule
end{tabular}
end{table}


I get what I think is a much better looking result:



enter image description here



This, however, requires that I manually add the phantom{-} command for every positive entry in my tables: I want to avoid this because the tables are large. So I have two questions:




  1. Is there a way in LaTeX or through a package which I can automate the addition of phantom{-}?

  2. Do you know of a better way to get the kind of alignment of fractions I'm looking for?







tables math-mode formatting vertical-alignment amsmath






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 30 '18 at 12:41









user36296

1




1










asked Dec 30 '18 at 11:34









user1362373user1362373

1,0181128




1,0181128













  • What should be done if an entire column consists of positive numbers?

    – Mico
    Dec 30 '18 at 14:09











  • Well, for positive numbers no change in alignment is necessary, so nothing needs to be done.

    – user1362373
    Dec 30 '18 at 14:11











  • You could put the negative signs into a separate column, or create a new command (+ ?) to handle phantom{-}.

    – John Kormylo
    Dec 30 '18 at 15:20






  • 2





    Adding phantom{-} is far less complicated than creating a macro for this, IMHO.

    – AboAmmar
    Dec 30 '18 at 15:54






  • 1





    the main problem here is that math fonts should have a minus sign as binary operator and a minus sign (shorter, more like an hyphen) for negative numbers; sadly the two are typeset the same and it is ugly (despite the fact nobody complains, but life is a path of solitude if you seek enlightenment)

    – user4686
    Dec 30 '18 at 22:17



















  • What should be done if an entire column consists of positive numbers?

    – Mico
    Dec 30 '18 at 14:09











  • Well, for positive numbers no change in alignment is necessary, so nothing needs to be done.

    – user1362373
    Dec 30 '18 at 14:11











  • You could put the negative signs into a separate column, or create a new command (+ ?) to handle phantom{-}.

    – John Kormylo
    Dec 30 '18 at 15:20






  • 2





    Adding phantom{-} is far less complicated than creating a macro for this, IMHO.

    – AboAmmar
    Dec 30 '18 at 15:54






  • 1





    the main problem here is that math fonts should have a minus sign as binary operator and a minus sign (shorter, more like an hyphen) for negative numbers; sadly the two are typeset the same and it is ugly (despite the fact nobody complains, but life is a path of solitude if you seek enlightenment)

    – user4686
    Dec 30 '18 at 22:17

















What should be done if an entire column consists of positive numbers?

– Mico
Dec 30 '18 at 14:09





What should be done if an entire column consists of positive numbers?

– Mico
Dec 30 '18 at 14:09













Well, for positive numbers no change in alignment is necessary, so nothing needs to be done.

– user1362373
Dec 30 '18 at 14:11





Well, for positive numbers no change in alignment is necessary, so nothing needs to be done.

– user1362373
Dec 30 '18 at 14:11













You could put the negative signs into a separate column, or create a new command (+ ?) to handle phantom{-}.

– John Kormylo
Dec 30 '18 at 15:20





You could put the negative signs into a separate column, or create a new command (+ ?) to handle phantom{-}.

– John Kormylo
Dec 30 '18 at 15:20




2




2





Adding phantom{-} is far less complicated than creating a macro for this, IMHO.

– AboAmmar
Dec 30 '18 at 15:54





Adding phantom{-} is far less complicated than creating a macro for this, IMHO.

– AboAmmar
Dec 30 '18 at 15:54




1




1





the main problem here is that math fonts should have a minus sign as binary operator and a minus sign (shorter, more like an hyphen) for negative numbers; sadly the two are typeset the same and it is ugly (despite the fact nobody complains, but life is a path of solitude if you seek enlightenment)

– user4686
Dec 30 '18 at 22:17





the main problem here is that math fonts should have a minus sign as binary operator and a minus sign (shorter, more like an hyphen) for negative numbers; sadly the two are typeset the same and it is ugly (despite the fact nobody complains, but life is a path of solitude if you seek enlightenment)

– user4686
Dec 30 '18 at 22:17










1 Answer
1






active

oldest

votes


















10














I don't think there's anything wrong with standard center alignment. Consider the case where you have -1/6 and -1/30: if you center align the fractions, the minus signs will be off.



I can offer a new column type for the columns with negative entries.



documentclass{article}
usepackage{amsmath,mathtools}
usepackage{booktabs,array,calc}

newcolumntype{n}{@{hspace{dimexprfontcharwdtextfont2 0+arraycolsep}}c}
newcommand{?}{mathllap{-}}
newcommand{mcn}[1]{%
multicolumn{1}{c}{kern-fontcharwdtextfont2 0 #1}%
}

begin{document}

begin{table}
centering

$begin{array}{nnc}
toprule
mcn{alpha} & mcn{beta} & gamma \
midrule
?frac{9}{2} & ?frac{1}{6} & 2 \[0.8ex]
?frac{7}{2} & frac{1}{30} & 3 \[0.5ex]
bottomrule
end{array}$

end{table}

end{document}


enter image description here






share|improve this answer
























    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%2f467894%2fimproving-alignment-of-signed-fractions-in-table%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    10














    I don't think there's anything wrong with standard center alignment. Consider the case where you have -1/6 and -1/30: if you center align the fractions, the minus signs will be off.



    I can offer a new column type for the columns with negative entries.



    documentclass{article}
    usepackage{amsmath,mathtools}
    usepackage{booktabs,array,calc}

    newcolumntype{n}{@{hspace{dimexprfontcharwdtextfont2 0+arraycolsep}}c}
    newcommand{?}{mathllap{-}}
    newcommand{mcn}[1]{%
    multicolumn{1}{c}{kern-fontcharwdtextfont2 0 #1}%
    }

    begin{document}

    begin{table}
    centering

    $begin{array}{nnc}
    toprule
    mcn{alpha} & mcn{beta} & gamma \
    midrule
    ?frac{9}{2} & ?frac{1}{6} & 2 \[0.8ex]
    ?frac{7}{2} & frac{1}{30} & 3 \[0.5ex]
    bottomrule
    end{array}$

    end{table}

    end{document}


    enter image description here






    share|improve this answer




























      10














      I don't think there's anything wrong with standard center alignment. Consider the case where you have -1/6 and -1/30: if you center align the fractions, the minus signs will be off.



      I can offer a new column type for the columns with negative entries.



      documentclass{article}
      usepackage{amsmath,mathtools}
      usepackage{booktabs,array,calc}

      newcolumntype{n}{@{hspace{dimexprfontcharwdtextfont2 0+arraycolsep}}c}
      newcommand{?}{mathllap{-}}
      newcommand{mcn}[1]{%
      multicolumn{1}{c}{kern-fontcharwdtextfont2 0 #1}%
      }

      begin{document}

      begin{table}
      centering

      $begin{array}{nnc}
      toprule
      mcn{alpha} & mcn{beta} & gamma \
      midrule
      ?frac{9}{2} & ?frac{1}{6} & 2 \[0.8ex]
      ?frac{7}{2} & frac{1}{30} & 3 \[0.5ex]
      bottomrule
      end{array}$

      end{table}

      end{document}


      enter image description here






      share|improve this answer


























        10












        10








        10







        I don't think there's anything wrong with standard center alignment. Consider the case where you have -1/6 and -1/30: if you center align the fractions, the minus signs will be off.



        I can offer a new column type for the columns with negative entries.



        documentclass{article}
        usepackage{amsmath,mathtools}
        usepackage{booktabs,array,calc}

        newcolumntype{n}{@{hspace{dimexprfontcharwdtextfont2 0+arraycolsep}}c}
        newcommand{?}{mathllap{-}}
        newcommand{mcn}[1]{%
        multicolumn{1}{c}{kern-fontcharwdtextfont2 0 #1}%
        }

        begin{document}

        begin{table}
        centering

        $begin{array}{nnc}
        toprule
        mcn{alpha} & mcn{beta} & gamma \
        midrule
        ?frac{9}{2} & ?frac{1}{6} & 2 \[0.8ex]
        ?frac{7}{2} & frac{1}{30} & 3 \[0.5ex]
        bottomrule
        end{array}$

        end{table}

        end{document}


        enter image description here






        share|improve this answer













        I don't think there's anything wrong with standard center alignment. Consider the case where you have -1/6 and -1/30: if you center align the fractions, the minus signs will be off.



        I can offer a new column type for the columns with negative entries.



        documentclass{article}
        usepackage{amsmath,mathtools}
        usepackage{booktabs,array,calc}

        newcolumntype{n}{@{hspace{dimexprfontcharwdtextfont2 0+arraycolsep}}c}
        newcommand{?}{mathllap{-}}
        newcommand{mcn}[1]{%
        multicolumn{1}{c}{kern-fontcharwdtextfont2 0 #1}%
        }

        begin{document}

        begin{table}
        centering

        $begin{array}{nnc}
        toprule
        mcn{alpha} & mcn{beta} & gamma \
        midrule
        ?frac{9}{2} & ?frac{1}{6} & 2 \[0.8ex]
        ?frac{7}{2} & frac{1}{30} & 3 \[0.5ex]
        bottomrule
        end{array}$

        end{table}

        end{document}


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 30 '18 at 15:58









        egregegreg

        736k8919353261




        736k8919353261






























            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%2f467894%2fimproving-alignment-of-signed-fractions-in-table%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

            Bundesstraße 106

            Le Mesnil-Réaume

            Ida-Boy-Ed-Garten