How to center the middle of a table to be in the center of the page?












4















I'd like to have the vertical rule in my {r|l} table to be horizontally aligned in the center of the page.



So far, I've only managed to do



begin{center}
begin{tabular}{r|l}
short & long long long \
short & long long long \
short & long long \
short & long long long\
end{tabular}
end{center}

begin{center}
begin{tabular}{r|l}
long long & short
end{tabular}
end{center}


which yields Output



How can I center the vertical lines of my tables to be in the center of the page?










share|improve this question























  • I'd like to have them both aligned such that the vertical line is in the middle of pagewidth

    – Stephan
    Jan 15 at 4:56
















4















I'd like to have the vertical rule in my {r|l} table to be horizontally aligned in the center of the page.



So far, I've only managed to do



begin{center}
begin{tabular}{r|l}
short & long long long \
short & long long long \
short & long long \
short & long long long\
end{tabular}
end{center}

begin{center}
begin{tabular}{r|l}
long long & short
end{tabular}
end{center}


which yields Output



How can I center the vertical lines of my tables to be in the center of the page?










share|improve this question























  • I'd like to have them both aligned such that the vertical line is in the middle of pagewidth

    – Stephan
    Jan 15 at 4:56














4












4








4


0






I'd like to have the vertical rule in my {r|l} table to be horizontally aligned in the center of the page.



So far, I've only managed to do



begin{center}
begin{tabular}{r|l}
short & long long long \
short & long long long \
short & long long \
short & long long long\
end{tabular}
end{center}

begin{center}
begin{tabular}{r|l}
long long & short
end{tabular}
end{center}


which yields Output



How can I center the vertical lines of my tables to be in the center of the page?










share|improve this question














I'd like to have the vertical rule in my {r|l} table to be horizontally aligned in the center of the page.



So far, I've only managed to do



begin{center}
begin{tabular}{r|l}
short & long long long \
short & long long long \
short & long long \
short & long long long\
end{tabular}
end{center}

begin{center}
begin{tabular}{r|l}
long long & short
end{tabular}
end{center}


which yields Output



How can I center the vertical lines of my tables to be in the center of the page?







tables horizontal-alignment






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 15 at 4:27









StephanStephan

1234




1234













  • I'd like to have them both aligned such that the vertical line is in the middle of pagewidth

    – Stephan
    Jan 15 at 4:56



















  • I'd like to have them both aligned such that the vertical line is in the middle of pagewidth

    – Stephan
    Jan 15 at 4:56

















I'd like to have them both aligned such that the vertical line is in the middle of pagewidth

– Stephan
Jan 15 at 4:56





I'd like to have them both aligned such that the vertical line is in the middle of pagewidth

– Stephan
Jan 15 at 4:56










2 Answers
2






active

oldest

votes


















5














You may need to define new column type (thanks @lockstep in his answer)



documentclass{article}
usepackage{array}

newcolumntype{L}[1]{>{raggedrightletnewline\arraybackslashhspace{0pt}}m{#1}}
newcolumntype{C}[1]{>{centeringletnewline\arraybackslashhspace{0pt}}m{#1}}
newcolumntype{R}[1]{>{raggedleftletnewline\arraybackslashhspace{0pt}}m{#1}}

begin{document}

begin{tabular}{ R{0.465textwidth} | L{0.465textwidth}}
short & long long long \
short & long long long \
short & long long \
short & long long long\
end{tabular}

begin{tabular}{ R{0.465textwidth} | L{0.465textwidth}}
long long & short
end{tabular}

end{document}


which gives



enter image description here






share|improve this answer


























  • That's exactly it, thank you! One question though: why is raggedleft used in the right-aligned column?

    – Stephan
    Jan 15 at 4:58






  • 2





    The command raggedleft pushes all text to the right of the line or column, keeping the left side text margin ragged. // ...One more minor correction to my answer: 0.49textwidth gives an "Overfull hbox (10.59pt too wide)". This is due to the column separator and the adjacent spaces on either side. So, you will have to allot somewhat less width to the columns to really center the column-separator. In my example, 0.465 worked best (editing accordingly).

    – Partha D.
    Jan 15 at 6:16











  • The answer from @CarLaTeX is definitely the more (probably the most) scientific and general solution.

    – Partha D.
    Jan 15 at 7:46













  • One could measure the distance from the sides to the column divider using tikzmarks, but the given solution is easier.

    – John Kormylo
    Jan 15 at 15:16



















6














You could give a fixed length to the columns of the tables.



If you want the columns to occupy all the space possible in the half of the line, you have to calculate their column width in this way, in order to not have an overfull hbox:
.5linewidth (half line)
-2tabsep (minus the two spaces before and after the text column)
-.5arrayrulewidth (minus half of the width of the vertical bar).



In my MWE I use the calc package, without it you can write setlength{myhalfpage}{dimexpr .5linewidth-2tabcolsep-.5arrayrulewidth} to get the same result.



You can use lockstep's definitions with this length.



documentclass{article}
usepackage{array}
usepackage{calc}
newlength{myhalfpage}
setlength{myhalfpage}{.5linewidth-2tabcolsep-.5arrayrulewidth}
newcolumntype{L}{>{raggedrightletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}
newcolumntype{C}{>{centeringletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}
newcolumntype{R}{>{raggedleftletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}

begin{document}

begin{center}
begin{tabular}{R|L}
short & long long long \
short & long long long \
short & long long \
short & long long long\
end{tabular}
end{center}
begin{center}
begin{tabular}{R|L}
long long & short
end{tabular}
end{center}
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%2f470181%2fhow-to-center-the-middle-of-a-table-to-be-in-the-center-of-the-page%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









    5














    You may need to define new column type (thanks @lockstep in his answer)



    documentclass{article}
    usepackage{array}

    newcolumntype{L}[1]{>{raggedrightletnewline\arraybackslashhspace{0pt}}m{#1}}
    newcolumntype{C}[1]{>{centeringletnewline\arraybackslashhspace{0pt}}m{#1}}
    newcolumntype{R}[1]{>{raggedleftletnewline\arraybackslashhspace{0pt}}m{#1}}

    begin{document}

    begin{tabular}{ R{0.465textwidth} | L{0.465textwidth}}
    short & long long long \
    short & long long long \
    short & long long \
    short & long long long\
    end{tabular}

    begin{tabular}{ R{0.465textwidth} | L{0.465textwidth}}
    long long & short
    end{tabular}

    end{document}


    which gives



    enter image description here






    share|improve this answer


























    • That's exactly it, thank you! One question though: why is raggedleft used in the right-aligned column?

      – Stephan
      Jan 15 at 4:58






    • 2





      The command raggedleft pushes all text to the right of the line or column, keeping the left side text margin ragged. // ...One more minor correction to my answer: 0.49textwidth gives an "Overfull hbox (10.59pt too wide)". This is due to the column separator and the adjacent spaces on either side. So, you will have to allot somewhat less width to the columns to really center the column-separator. In my example, 0.465 worked best (editing accordingly).

      – Partha D.
      Jan 15 at 6:16











    • The answer from @CarLaTeX is definitely the more (probably the most) scientific and general solution.

      – Partha D.
      Jan 15 at 7:46













    • One could measure the distance from the sides to the column divider using tikzmarks, but the given solution is easier.

      – John Kormylo
      Jan 15 at 15:16
















    5














    You may need to define new column type (thanks @lockstep in his answer)



    documentclass{article}
    usepackage{array}

    newcolumntype{L}[1]{>{raggedrightletnewline\arraybackslashhspace{0pt}}m{#1}}
    newcolumntype{C}[1]{>{centeringletnewline\arraybackslashhspace{0pt}}m{#1}}
    newcolumntype{R}[1]{>{raggedleftletnewline\arraybackslashhspace{0pt}}m{#1}}

    begin{document}

    begin{tabular}{ R{0.465textwidth} | L{0.465textwidth}}
    short & long long long \
    short & long long long \
    short & long long \
    short & long long long\
    end{tabular}

    begin{tabular}{ R{0.465textwidth} | L{0.465textwidth}}
    long long & short
    end{tabular}

    end{document}


    which gives



    enter image description here






    share|improve this answer


























    • That's exactly it, thank you! One question though: why is raggedleft used in the right-aligned column?

      – Stephan
      Jan 15 at 4:58






    • 2





      The command raggedleft pushes all text to the right of the line or column, keeping the left side text margin ragged. // ...One more minor correction to my answer: 0.49textwidth gives an "Overfull hbox (10.59pt too wide)". This is due to the column separator and the adjacent spaces on either side. So, you will have to allot somewhat less width to the columns to really center the column-separator. In my example, 0.465 worked best (editing accordingly).

      – Partha D.
      Jan 15 at 6:16











    • The answer from @CarLaTeX is definitely the more (probably the most) scientific and general solution.

      – Partha D.
      Jan 15 at 7:46













    • One could measure the distance from the sides to the column divider using tikzmarks, but the given solution is easier.

      – John Kormylo
      Jan 15 at 15:16














    5












    5








    5







    You may need to define new column type (thanks @lockstep in his answer)



    documentclass{article}
    usepackage{array}

    newcolumntype{L}[1]{>{raggedrightletnewline\arraybackslashhspace{0pt}}m{#1}}
    newcolumntype{C}[1]{>{centeringletnewline\arraybackslashhspace{0pt}}m{#1}}
    newcolumntype{R}[1]{>{raggedleftletnewline\arraybackslashhspace{0pt}}m{#1}}

    begin{document}

    begin{tabular}{ R{0.465textwidth} | L{0.465textwidth}}
    short & long long long \
    short & long long long \
    short & long long \
    short & long long long\
    end{tabular}

    begin{tabular}{ R{0.465textwidth} | L{0.465textwidth}}
    long long & short
    end{tabular}

    end{document}


    which gives



    enter image description here






    share|improve this answer















    You may need to define new column type (thanks @lockstep in his answer)



    documentclass{article}
    usepackage{array}

    newcolumntype{L}[1]{>{raggedrightletnewline\arraybackslashhspace{0pt}}m{#1}}
    newcolumntype{C}[1]{>{centeringletnewline\arraybackslashhspace{0pt}}m{#1}}
    newcolumntype{R}[1]{>{raggedleftletnewline\arraybackslashhspace{0pt}}m{#1}}

    begin{document}

    begin{tabular}{ R{0.465textwidth} | L{0.465textwidth}}
    short & long long long \
    short & long long long \
    short & long long \
    short & long long long\
    end{tabular}

    begin{tabular}{ R{0.465textwidth} | L{0.465textwidth}}
    long long & short
    end{tabular}

    end{document}


    which gives



    enter image description here







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 15 at 6:18

























    answered Jan 15 at 4:51









    Partha D.Partha D.

    1,10218




    1,10218













    • That's exactly it, thank you! One question though: why is raggedleft used in the right-aligned column?

      – Stephan
      Jan 15 at 4:58






    • 2





      The command raggedleft pushes all text to the right of the line or column, keeping the left side text margin ragged. // ...One more minor correction to my answer: 0.49textwidth gives an "Overfull hbox (10.59pt too wide)". This is due to the column separator and the adjacent spaces on either side. So, you will have to allot somewhat less width to the columns to really center the column-separator. In my example, 0.465 worked best (editing accordingly).

      – Partha D.
      Jan 15 at 6:16











    • The answer from @CarLaTeX is definitely the more (probably the most) scientific and general solution.

      – Partha D.
      Jan 15 at 7:46













    • One could measure the distance from the sides to the column divider using tikzmarks, but the given solution is easier.

      – John Kormylo
      Jan 15 at 15:16



















    • That's exactly it, thank you! One question though: why is raggedleft used in the right-aligned column?

      – Stephan
      Jan 15 at 4:58






    • 2





      The command raggedleft pushes all text to the right of the line or column, keeping the left side text margin ragged. // ...One more minor correction to my answer: 0.49textwidth gives an "Overfull hbox (10.59pt too wide)". This is due to the column separator and the adjacent spaces on either side. So, you will have to allot somewhat less width to the columns to really center the column-separator. In my example, 0.465 worked best (editing accordingly).

      – Partha D.
      Jan 15 at 6:16











    • The answer from @CarLaTeX is definitely the more (probably the most) scientific and general solution.

      – Partha D.
      Jan 15 at 7:46













    • One could measure the distance from the sides to the column divider using tikzmarks, but the given solution is easier.

      – John Kormylo
      Jan 15 at 15:16

















    That's exactly it, thank you! One question though: why is raggedleft used in the right-aligned column?

    – Stephan
    Jan 15 at 4:58





    That's exactly it, thank you! One question though: why is raggedleft used in the right-aligned column?

    – Stephan
    Jan 15 at 4:58




    2




    2





    The command raggedleft pushes all text to the right of the line or column, keeping the left side text margin ragged. // ...One more minor correction to my answer: 0.49textwidth gives an "Overfull hbox (10.59pt too wide)". This is due to the column separator and the adjacent spaces on either side. So, you will have to allot somewhat less width to the columns to really center the column-separator. In my example, 0.465 worked best (editing accordingly).

    – Partha D.
    Jan 15 at 6:16





    The command raggedleft pushes all text to the right of the line or column, keeping the left side text margin ragged. // ...One more minor correction to my answer: 0.49textwidth gives an "Overfull hbox (10.59pt too wide)". This is due to the column separator and the adjacent spaces on either side. So, you will have to allot somewhat less width to the columns to really center the column-separator. In my example, 0.465 worked best (editing accordingly).

    – Partha D.
    Jan 15 at 6:16













    The answer from @CarLaTeX is definitely the more (probably the most) scientific and general solution.

    – Partha D.
    Jan 15 at 7:46







    The answer from @CarLaTeX is definitely the more (probably the most) scientific and general solution.

    – Partha D.
    Jan 15 at 7:46















    One could measure the distance from the sides to the column divider using tikzmarks, but the given solution is easier.

    – John Kormylo
    Jan 15 at 15:16





    One could measure the distance from the sides to the column divider using tikzmarks, but the given solution is easier.

    – John Kormylo
    Jan 15 at 15:16











    6














    You could give a fixed length to the columns of the tables.



    If you want the columns to occupy all the space possible in the half of the line, you have to calculate their column width in this way, in order to not have an overfull hbox:
    .5linewidth (half line)
    -2tabsep (minus the two spaces before and after the text column)
    -.5arrayrulewidth (minus half of the width of the vertical bar).



    In my MWE I use the calc package, without it you can write setlength{myhalfpage}{dimexpr .5linewidth-2tabcolsep-.5arrayrulewidth} to get the same result.



    You can use lockstep's definitions with this length.



    documentclass{article}
    usepackage{array}
    usepackage{calc}
    newlength{myhalfpage}
    setlength{myhalfpage}{.5linewidth-2tabcolsep-.5arrayrulewidth}
    newcolumntype{L}{>{raggedrightletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}
    newcolumntype{C}{>{centeringletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}
    newcolumntype{R}{>{raggedleftletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}

    begin{document}

    begin{center}
    begin{tabular}{R|L}
    short & long long long \
    short & long long long \
    short & long long \
    short & long long long\
    end{tabular}
    end{center}
    begin{center}
    begin{tabular}{R|L}
    long long & short
    end{tabular}
    end{center}
    end{document}


    enter image description here






    share|improve this answer






























      6














      You could give a fixed length to the columns of the tables.



      If you want the columns to occupy all the space possible in the half of the line, you have to calculate their column width in this way, in order to not have an overfull hbox:
      .5linewidth (half line)
      -2tabsep (minus the two spaces before and after the text column)
      -.5arrayrulewidth (minus half of the width of the vertical bar).



      In my MWE I use the calc package, without it you can write setlength{myhalfpage}{dimexpr .5linewidth-2tabcolsep-.5arrayrulewidth} to get the same result.



      You can use lockstep's definitions with this length.



      documentclass{article}
      usepackage{array}
      usepackage{calc}
      newlength{myhalfpage}
      setlength{myhalfpage}{.5linewidth-2tabcolsep-.5arrayrulewidth}
      newcolumntype{L}{>{raggedrightletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}
      newcolumntype{C}{>{centeringletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}
      newcolumntype{R}{>{raggedleftletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}

      begin{document}

      begin{center}
      begin{tabular}{R|L}
      short & long long long \
      short & long long long \
      short & long long \
      short & long long long\
      end{tabular}
      end{center}
      begin{center}
      begin{tabular}{R|L}
      long long & short
      end{tabular}
      end{center}
      end{document}


      enter image description here






      share|improve this answer




























        6












        6








        6







        You could give a fixed length to the columns of the tables.



        If you want the columns to occupy all the space possible in the half of the line, you have to calculate their column width in this way, in order to not have an overfull hbox:
        .5linewidth (half line)
        -2tabsep (minus the two spaces before and after the text column)
        -.5arrayrulewidth (minus half of the width of the vertical bar).



        In my MWE I use the calc package, without it you can write setlength{myhalfpage}{dimexpr .5linewidth-2tabcolsep-.5arrayrulewidth} to get the same result.



        You can use lockstep's definitions with this length.



        documentclass{article}
        usepackage{array}
        usepackage{calc}
        newlength{myhalfpage}
        setlength{myhalfpage}{.5linewidth-2tabcolsep-.5arrayrulewidth}
        newcolumntype{L}{>{raggedrightletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}
        newcolumntype{C}{>{centeringletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}
        newcolumntype{R}{>{raggedleftletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}

        begin{document}

        begin{center}
        begin{tabular}{R|L}
        short & long long long \
        short & long long long \
        short & long long \
        short & long long long\
        end{tabular}
        end{center}
        begin{center}
        begin{tabular}{R|L}
        long long & short
        end{tabular}
        end{center}
        end{document}


        enter image description here






        share|improve this answer















        You could give a fixed length to the columns of the tables.



        If you want the columns to occupy all the space possible in the half of the line, you have to calculate their column width in this way, in order to not have an overfull hbox:
        .5linewidth (half line)
        -2tabsep (minus the two spaces before and after the text column)
        -.5arrayrulewidth (minus half of the width of the vertical bar).



        In my MWE I use the calc package, without it you can write setlength{myhalfpage}{dimexpr .5linewidth-2tabcolsep-.5arrayrulewidth} to get the same result.



        You can use lockstep's definitions with this length.



        documentclass{article}
        usepackage{array}
        usepackage{calc}
        newlength{myhalfpage}
        setlength{myhalfpage}{.5linewidth-2tabcolsep-.5arrayrulewidth}
        newcolumntype{L}{>{raggedrightletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}
        newcolumntype{C}{>{centeringletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}
        newcolumntype{R}{>{raggedleftletnewline\arraybackslashhspace{0pt}}m{myhalfpage}}

        begin{document}

        begin{center}
        begin{tabular}{R|L}
        short & long long long \
        short & long long long \
        short & long long \
        short & long long long\
        end{tabular}
        end{center}
        begin{center}
        begin{tabular}{R|L}
        long long & short
        end{tabular}
        end{center}
        end{document}


        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 15 at 7:28

























        answered Jan 15 at 4:50









        CarLaTeXCarLaTeX

        31.7k451133




        31.7k451133






























            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%2f470181%2fhow-to-center-the-middle-of-a-table-to-be-in-the-center-of-the-page%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

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith