Improving alignment of signed fractions in table












9














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
    2 hours ago










  • Well, for positive numbers no change in alignment is necessary, so nothing needs to be done.
    – user1362373
    2 hours ago










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










  • Adding phantom{-} is far less complicated than creating a macro for this, IMHO.
    – AboAmmar
    1 hour ago
















9














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
    2 hours ago










  • Well, for positive numbers no change in alignment is necessary, so nothing needs to be done.
    – user1362373
    2 hours ago










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










  • Adding phantom{-} is far less complicated than creating a macro for this, IMHO.
    – AboAmmar
    1 hour ago














9












9








9


0





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 4 hours ago









samcarter

85.7k794275




85.7k794275










asked 5 hours ago









user1362373

9381027




9381027












  • What should be done if an entire column consists of positive numbers?
    – Mico
    2 hours ago










  • Well, for positive numbers no change in alignment is necessary, so nothing needs to be done.
    – user1362373
    2 hours ago










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










  • Adding phantom{-} is far less complicated than creating a macro for this, IMHO.
    – AboAmmar
    1 hour ago


















  • What should be done if an entire column consists of positive numbers?
    – Mico
    2 hours ago










  • Well, for positive numbers no change in alignment is necessary, so nothing needs to be done.
    – user1362373
    2 hours ago










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










  • Adding phantom{-} is far less complicated than creating a macro for this, IMHO.
    – AboAmmar
    1 hour ago
















What should be done if an entire column consists of positive numbers?
– Mico
2 hours ago




What should be done if an entire column consists of positive numbers?
– Mico
2 hours ago












Well, for positive numbers no change in alignment is necessary, so nothing needs to be done.
– user1362373
2 hours ago




Well, for positive numbers no change in alignment is necessary, so nothing needs to be done.
– user1362373
2 hours ago












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




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












Adding phantom{-} is far less complicated than creating a macro for this, IMHO.
– AboAmmar
1 hour ago




Adding phantom{-} is far less complicated than creating a macro for this, IMHO.
– AboAmmar
1 hour ago










1 Answer
1






active

oldest

votes


















6














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









    6














    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


























      6














      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
























        6












        6








        6






        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 1 hour ago









        egreg

        708k8618823163




        708k8618823163






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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

            Morgemoulin

            Scott Moir

            Souastre