Alignment with a LaTeX hbox











up vote
3
down vote

favorite












Can someone please explain if it is possible to obtain centered text or right justified text within a TeX hbox? I am attempting to utilize some code I found here in order to transpose a LaTeX table.



Here is my code for reference. Note that I'm using the booktabs and array packages.



defMidrule{midrule[heavyrulewidth]}
newcountrowc

makeatletter
defttabular{%
~
hboxbgroup
let\cr
defrulea{ifnumrowc=@ne hrule height 1.3pt fi}
defruleb{
ifnumrowc=1hrule height 0pt else%
ifnumrowc=2hrule height 1.3pt else%
ifnumrowc=6hrule height heavyrulewidth
else hrule height lightrulewidthfififi}
valignbgroup
globalrowc@ne
rulea
hbox to 10cm{strut~~hfill##hfill}%
ruleb
&&%
globaladvancerowc@ne
hbox to 10cm{strut~~hfill##hfill}%
ruleb
cr}
defendttabular{%
crcregroupegroup}


I don't like the effect of "hbox to 1cm", though, as it hardcodes the width of the columns of my table. I've tried replacing with "hbox spread 1cm" or just "hbox", but in both cases the text in the columns is left justified. Is there any way to obtain center or right justified text without fixed-width columns?



Thanks in advance!



EDIT:



OK, here is a minimal working example:



documentclass{article}

usepackage{booktabs,array}

defMidrule{midrule[heavyrulewidth]}
newcountrowc

makeatletter
defttabular{%
~
hboxbgroup
let\cr
defrulea{ifnumrowc=@ne hrule height 1.3pt fi}
defruleb{
ifnumrowc=1hrule height 0pt else%
ifnumrowc=2hrule height 1.3pt else%
ifnumrowc=6hrule height heavyrulewidth
else hrule height lightrulewidthfififi}
valignbgroup
globalrowc@ne
rulea
hbox{strut~~hfill##hfill}%
ruleb
&&%
globaladvancerowc@ne
hbox{strut~~hfill##hfill}%
ruleb
cr}
defendttabular{%
crcregroupegroup}

begin{document}

begin{ttabular}
& Item & Very very very very very long item & Short item\
Price at Original & Location ($) & $3.95 & $9.95\
Price at New & Location ($) & $3.99 & $10.63 \
end{ttabular}

end{document}


This produces the following:



enter image description here



I believe the comments are correct and that is not a problem within my hbox's but rather that the hbox's themselves are sized appropriately and then being left aligned within each column. However, I'd still like to know how to generate a transposed table and have the columns of the final result be either centered or right-justified.



For anyone interested, the reason I want to do this is I'm using R markdown to generate the table. The entries of each column are given by the elements of an array, and the array's size may change from one generation of the table to another. So my R markdown code looks like this:



begin{ttabular}
& Item & Sexpr{paste(items, collapse=" & ")} \
Price at Original & Location ($) & Sexpr{paste(site1price, collapse=" & ")} \
Price at New & Location ($) & Sexpr{paste(site2price, collapse=" & ")} \
end{ttabular}


In the above, item, site1price, and site2price are R arrays.



Any help is appreciated!










share|improve this question




















  • 3




    a "normal" hbox (i.e. one without to) is always as wide as the content you put inside. Therefore, you have to give it a fixed width.
    – Lupino
    Nov 30 at 12:56










  • If you use hbox to 30mm {hss stuffhss} then stuff will be centered in an hbox of width 30mm. Similarly, hbox to 30mm {hss stuff} is right justified and hbox to 30mm {stuffhss} is left justified. I am not sure that it makes sense to center, left or right justify the contents of a box if you don't know the width by some mechanism since the width of hbox{stuff} is just enough to accommodate stuff.
    – Andrew
    Nov 30 at 13:04












  • @Andrew ... I understand what you are saying and I agree in the case in which I only have one row of hbox's, but the code I have can be used to construct a table with many rows of hbox's. So "stuff" in row1 may be much wider than "stuff" in row3, for example. The result is that each column of hbox's takes the largest width of any hbox in that column and therefore alignment makes sense.
    – NateA
    Nov 30 at 13:49










  • Can you provide a complete (yet short) working code, beginning with documentclass, to show the issue?
    – Steven B. Segletes
    Nov 30 at 14:23










  • @StevenB.Segletes ... I've added a working example, thanks!
    – NateA
    Nov 30 at 19:48















up vote
3
down vote

favorite












Can someone please explain if it is possible to obtain centered text or right justified text within a TeX hbox? I am attempting to utilize some code I found here in order to transpose a LaTeX table.



Here is my code for reference. Note that I'm using the booktabs and array packages.



defMidrule{midrule[heavyrulewidth]}
newcountrowc

makeatletter
defttabular{%
~
hboxbgroup
let\cr
defrulea{ifnumrowc=@ne hrule height 1.3pt fi}
defruleb{
ifnumrowc=1hrule height 0pt else%
ifnumrowc=2hrule height 1.3pt else%
ifnumrowc=6hrule height heavyrulewidth
else hrule height lightrulewidthfififi}
valignbgroup
globalrowc@ne
rulea
hbox to 10cm{strut~~hfill##hfill}%
ruleb
&&%
globaladvancerowc@ne
hbox to 10cm{strut~~hfill##hfill}%
ruleb
cr}
defendttabular{%
crcregroupegroup}


I don't like the effect of "hbox to 1cm", though, as it hardcodes the width of the columns of my table. I've tried replacing with "hbox spread 1cm" or just "hbox", but in both cases the text in the columns is left justified. Is there any way to obtain center or right justified text without fixed-width columns?



Thanks in advance!



EDIT:



OK, here is a minimal working example:



documentclass{article}

usepackage{booktabs,array}

defMidrule{midrule[heavyrulewidth]}
newcountrowc

makeatletter
defttabular{%
~
hboxbgroup
let\cr
defrulea{ifnumrowc=@ne hrule height 1.3pt fi}
defruleb{
ifnumrowc=1hrule height 0pt else%
ifnumrowc=2hrule height 1.3pt else%
ifnumrowc=6hrule height heavyrulewidth
else hrule height lightrulewidthfififi}
valignbgroup
globalrowc@ne
rulea
hbox{strut~~hfill##hfill}%
ruleb
&&%
globaladvancerowc@ne
hbox{strut~~hfill##hfill}%
ruleb
cr}
defendttabular{%
crcregroupegroup}

begin{document}

begin{ttabular}
& Item & Very very very very very long item & Short item\
Price at Original & Location ($) & $3.95 & $9.95\
Price at New & Location ($) & $3.99 & $10.63 \
end{ttabular}

end{document}


This produces the following:



enter image description here



I believe the comments are correct and that is not a problem within my hbox's but rather that the hbox's themselves are sized appropriately and then being left aligned within each column. However, I'd still like to know how to generate a transposed table and have the columns of the final result be either centered or right-justified.



For anyone interested, the reason I want to do this is I'm using R markdown to generate the table. The entries of each column are given by the elements of an array, and the array's size may change from one generation of the table to another. So my R markdown code looks like this:



begin{ttabular}
& Item & Sexpr{paste(items, collapse=" & ")} \
Price at Original & Location ($) & Sexpr{paste(site1price, collapse=" & ")} \
Price at New & Location ($) & Sexpr{paste(site2price, collapse=" & ")} \
end{ttabular}


In the above, item, site1price, and site2price are R arrays.



Any help is appreciated!










share|improve this question




















  • 3




    a "normal" hbox (i.e. one without to) is always as wide as the content you put inside. Therefore, you have to give it a fixed width.
    – Lupino
    Nov 30 at 12:56










  • If you use hbox to 30mm {hss stuffhss} then stuff will be centered in an hbox of width 30mm. Similarly, hbox to 30mm {hss stuff} is right justified and hbox to 30mm {stuffhss} is left justified. I am not sure that it makes sense to center, left or right justify the contents of a box if you don't know the width by some mechanism since the width of hbox{stuff} is just enough to accommodate stuff.
    – Andrew
    Nov 30 at 13:04












  • @Andrew ... I understand what you are saying and I agree in the case in which I only have one row of hbox's, but the code I have can be used to construct a table with many rows of hbox's. So "stuff" in row1 may be much wider than "stuff" in row3, for example. The result is that each column of hbox's takes the largest width of any hbox in that column and therefore alignment makes sense.
    – NateA
    Nov 30 at 13:49










  • Can you provide a complete (yet short) working code, beginning with documentclass, to show the issue?
    – Steven B. Segletes
    Nov 30 at 14:23










  • @StevenB.Segletes ... I've added a working example, thanks!
    – NateA
    Nov 30 at 19:48













up vote
3
down vote

favorite









up vote
3
down vote

favorite











Can someone please explain if it is possible to obtain centered text or right justified text within a TeX hbox? I am attempting to utilize some code I found here in order to transpose a LaTeX table.



Here is my code for reference. Note that I'm using the booktabs and array packages.



defMidrule{midrule[heavyrulewidth]}
newcountrowc

makeatletter
defttabular{%
~
hboxbgroup
let\cr
defrulea{ifnumrowc=@ne hrule height 1.3pt fi}
defruleb{
ifnumrowc=1hrule height 0pt else%
ifnumrowc=2hrule height 1.3pt else%
ifnumrowc=6hrule height heavyrulewidth
else hrule height lightrulewidthfififi}
valignbgroup
globalrowc@ne
rulea
hbox to 10cm{strut~~hfill##hfill}%
ruleb
&&%
globaladvancerowc@ne
hbox to 10cm{strut~~hfill##hfill}%
ruleb
cr}
defendttabular{%
crcregroupegroup}


I don't like the effect of "hbox to 1cm", though, as it hardcodes the width of the columns of my table. I've tried replacing with "hbox spread 1cm" or just "hbox", but in both cases the text in the columns is left justified. Is there any way to obtain center or right justified text without fixed-width columns?



Thanks in advance!



EDIT:



OK, here is a minimal working example:



documentclass{article}

usepackage{booktabs,array}

defMidrule{midrule[heavyrulewidth]}
newcountrowc

makeatletter
defttabular{%
~
hboxbgroup
let\cr
defrulea{ifnumrowc=@ne hrule height 1.3pt fi}
defruleb{
ifnumrowc=1hrule height 0pt else%
ifnumrowc=2hrule height 1.3pt else%
ifnumrowc=6hrule height heavyrulewidth
else hrule height lightrulewidthfififi}
valignbgroup
globalrowc@ne
rulea
hbox{strut~~hfill##hfill}%
ruleb
&&%
globaladvancerowc@ne
hbox{strut~~hfill##hfill}%
ruleb
cr}
defendttabular{%
crcregroupegroup}

begin{document}

begin{ttabular}
& Item & Very very very very very long item & Short item\
Price at Original & Location ($) & $3.95 & $9.95\
Price at New & Location ($) & $3.99 & $10.63 \
end{ttabular}

end{document}


This produces the following:



enter image description here



I believe the comments are correct and that is not a problem within my hbox's but rather that the hbox's themselves are sized appropriately and then being left aligned within each column. However, I'd still like to know how to generate a transposed table and have the columns of the final result be either centered or right-justified.



For anyone interested, the reason I want to do this is I'm using R markdown to generate the table. The entries of each column are given by the elements of an array, and the array's size may change from one generation of the table to another. So my R markdown code looks like this:



begin{ttabular}
& Item & Sexpr{paste(items, collapse=" & ")} \
Price at Original & Location ($) & Sexpr{paste(site1price, collapse=" & ")} \
Price at New & Location ($) & Sexpr{paste(site2price, collapse=" & ")} \
end{ttabular}


In the above, item, site1price, and site2price are R arrays.



Any help is appreciated!










share|improve this question















Can someone please explain if it is possible to obtain centered text or right justified text within a TeX hbox? I am attempting to utilize some code I found here in order to transpose a LaTeX table.



Here is my code for reference. Note that I'm using the booktabs and array packages.



defMidrule{midrule[heavyrulewidth]}
newcountrowc

makeatletter
defttabular{%
~
hboxbgroup
let\cr
defrulea{ifnumrowc=@ne hrule height 1.3pt fi}
defruleb{
ifnumrowc=1hrule height 0pt else%
ifnumrowc=2hrule height 1.3pt else%
ifnumrowc=6hrule height heavyrulewidth
else hrule height lightrulewidthfififi}
valignbgroup
globalrowc@ne
rulea
hbox to 10cm{strut~~hfill##hfill}%
ruleb
&&%
globaladvancerowc@ne
hbox to 10cm{strut~~hfill##hfill}%
ruleb
cr}
defendttabular{%
crcregroupegroup}


I don't like the effect of "hbox to 1cm", though, as it hardcodes the width of the columns of my table. I've tried replacing with "hbox spread 1cm" or just "hbox", but in both cases the text in the columns is left justified. Is there any way to obtain center or right justified text without fixed-width columns?



Thanks in advance!



EDIT:



OK, here is a minimal working example:



documentclass{article}

usepackage{booktabs,array}

defMidrule{midrule[heavyrulewidth]}
newcountrowc

makeatletter
defttabular{%
~
hboxbgroup
let\cr
defrulea{ifnumrowc=@ne hrule height 1.3pt fi}
defruleb{
ifnumrowc=1hrule height 0pt else%
ifnumrowc=2hrule height 1.3pt else%
ifnumrowc=6hrule height heavyrulewidth
else hrule height lightrulewidthfififi}
valignbgroup
globalrowc@ne
rulea
hbox{strut~~hfill##hfill}%
ruleb
&&%
globaladvancerowc@ne
hbox{strut~~hfill##hfill}%
ruleb
cr}
defendttabular{%
crcregroupegroup}

begin{document}

begin{ttabular}
& Item & Very very very very very long item & Short item\
Price at Original & Location ($) & $3.95 & $9.95\
Price at New & Location ($) & $3.99 & $10.63 \
end{ttabular}

end{document}


This produces the following:



enter image description here



I believe the comments are correct and that is not a problem within my hbox's but rather that the hbox's themselves are sized appropriately and then being left aligned within each column. However, I'd still like to know how to generate a transposed table and have the columns of the final result be either centered or right-justified.



For anyone interested, the reason I want to do this is I'm using R markdown to generate the table. The entries of each column are given by the elements of an array, and the array's size may change from one generation of the table to another. So my R markdown code looks like this:



begin{ttabular}
& Item & Sexpr{paste(items, collapse=" & ")} \
Price at Original & Location ($) & Sexpr{paste(site1price, collapse=" & ")} \
Price at New & Location ($) & Sexpr{paste(site2price, collapse=" & ")} \
end{ttabular}


In the above, item, site1price, and site2price are R arrays.



Any help is appreciated!







tables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 30 at 19:43

























asked Nov 30 at 12:52









NateA

183




183








  • 3




    a "normal" hbox (i.e. one without to) is always as wide as the content you put inside. Therefore, you have to give it a fixed width.
    – Lupino
    Nov 30 at 12:56










  • If you use hbox to 30mm {hss stuffhss} then stuff will be centered in an hbox of width 30mm. Similarly, hbox to 30mm {hss stuff} is right justified and hbox to 30mm {stuffhss} is left justified. I am not sure that it makes sense to center, left or right justify the contents of a box if you don't know the width by some mechanism since the width of hbox{stuff} is just enough to accommodate stuff.
    – Andrew
    Nov 30 at 13:04












  • @Andrew ... I understand what you are saying and I agree in the case in which I only have one row of hbox's, but the code I have can be used to construct a table with many rows of hbox's. So "stuff" in row1 may be much wider than "stuff" in row3, for example. The result is that each column of hbox's takes the largest width of any hbox in that column and therefore alignment makes sense.
    – NateA
    Nov 30 at 13:49










  • Can you provide a complete (yet short) working code, beginning with documentclass, to show the issue?
    – Steven B. Segletes
    Nov 30 at 14:23










  • @StevenB.Segletes ... I've added a working example, thanks!
    – NateA
    Nov 30 at 19:48














  • 3




    a "normal" hbox (i.e. one without to) is always as wide as the content you put inside. Therefore, you have to give it a fixed width.
    – Lupino
    Nov 30 at 12:56










  • If you use hbox to 30mm {hss stuffhss} then stuff will be centered in an hbox of width 30mm. Similarly, hbox to 30mm {hss stuff} is right justified and hbox to 30mm {stuffhss} is left justified. I am not sure that it makes sense to center, left or right justify the contents of a box if you don't know the width by some mechanism since the width of hbox{stuff} is just enough to accommodate stuff.
    – Andrew
    Nov 30 at 13:04












  • @Andrew ... I understand what you are saying and I agree in the case in which I only have one row of hbox's, but the code I have can be used to construct a table with many rows of hbox's. So "stuff" in row1 may be much wider than "stuff" in row3, for example. The result is that each column of hbox's takes the largest width of any hbox in that column and therefore alignment makes sense.
    – NateA
    Nov 30 at 13:49










  • Can you provide a complete (yet short) working code, beginning with documentclass, to show the issue?
    – Steven B. Segletes
    Nov 30 at 14:23










  • @StevenB.Segletes ... I've added a working example, thanks!
    – NateA
    Nov 30 at 19:48








3




3




a "normal" hbox (i.e. one without to) is always as wide as the content you put inside. Therefore, you have to give it a fixed width.
– Lupino
Nov 30 at 12:56




a "normal" hbox (i.e. one without to) is always as wide as the content you put inside. Therefore, you have to give it a fixed width.
– Lupino
Nov 30 at 12:56












If you use hbox to 30mm {hss stuffhss} then stuff will be centered in an hbox of width 30mm. Similarly, hbox to 30mm {hss stuff} is right justified and hbox to 30mm {stuffhss} is left justified. I am not sure that it makes sense to center, left or right justify the contents of a box if you don't know the width by some mechanism since the width of hbox{stuff} is just enough to accommodate stuff.
– Andrew
Nov 30 at 13:04






If you use hbox to 30mm {hss stuffhss} then stuff will be centered in an hbox of width 30mm. Similarly, hbox to 30mm {hss stuff} is right justified and hbox to 30mm {stuffhss} is left justified. I am not sure that it makes sense to center, left or right justify the contents of a box if you don't know the width by some mechanism since the width of hbox{stuff} is just enough to accommodate stuff.
– Andrew
Nov 30 at 13:04














@Andrew ... I understand what you are saying and I agree in the case in which I only have one row of hbox's, but the code I have can be used to construct a table with many rows of hbox's. So "stuff" in row1 may be much wider than "stuff" in row3, for example. The result is that each column of hbox's takes the largest width of any hbox in that column and therefore alignment makes sense.
– NateA
Nov 30 at 13:49




@Andrew ... I understand what you are saying and I agree in the case in which I only have one row of hbox's, but the code I have can be used to construct a table with many rows of hbox's. So "stuff" in row1 may be much wider than "stuff" in row3, for example. The result is that each column of hbox's takes the largest width of any hbox in that column and therefore alignment makes sense.
– NateA
Nov 30 at 13:49












Can you provide a complete (yet short) working code, beginning with documentclass, to show the issue?
– Steven B. Segletes
Nov 30 at 14:23




Can you provide a complete (yet short) working code, beginning with documentclass, to show the issue?
– Steven B. Segletes
Nov 30 at 14:23












@StevenB.Segletes ... I've added a working example, thanks!
– NateA
Nov 30 at 19:48




@StevenB.Segletes ... I've added a working example, thanks!
– NateA
Nov 30 at 19:48










2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










Center, left and right aligned "xxx":



documentclass{article}
begin{document}
hbox to 5cm{hfil xxx hfil}par
hbox to 5cm{hfil xxx}par
hbox to 5cm{xxx hfil}par
end{document}


But better:



documentclass{article}
begin{document}
makebox[5cm][c]{x x x}par
makebox[5cm][r]{x x x}par
makebox[5cm][l]{x x x}par
makebox[5cm][s]{x x x}par
end{document}





share|improve this answer






























    up vote
    0
    down vote













    I've accepted the answer above because it technically answered the question about alignment within an hbox, although it didn't really help me accomplish what I wanted to do.



    For anyone interested, I did find a rather ugly work around for my problem. Instead of using valign to build my transposed table from the arrays, I used minipages. This, of course, only worked because I knew the number of columns that I wanted and had a relatively good guess as to the approximate widths I wanted those columns to be. Here is the code I ended up with:



    begin{minipage}{.5textwidth}
    centering
    hrule height 1.3pt
    strut ~\
    strut Item\
    hrule height 1.3pt
    strut Sexpr{paste(items, collapse="\\strut \\\\ \\hrule ")}strut
    hrule height 1.3pt
    end{minipage}%
    begin{minipage}{.2textwidth}
    centering
    hrule height 1.3pt
    struthfill Price at Original\
    struthfill Location ($)\
    hrule height 1.3pt
    strut hfill Sexpr{paste(site1price, collapse="\\strut \\\\ \\hrule \\hfill")}strut
    hrule height 1.3pt
    end{minipage}%
    begin{minipage}{.2textwidth}
    centering
    hrule height 1.3pt
    struthfill Price at New\
    struthfill Location ($)\
    hrule height 1.3pt
    strut hfill Sexpr{paste(site2price, collapse="\\strut \\\\ \\hrule \\hfill")}strut
    hrule height 1.3pt
    end{minipage}


    This produces something like this:
    enter image description here






    share|improve this answer








    New contributor




    NateA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.


















    • Maybe is that I do not understand well... buto this to make a simple table with R outputs? Without the R code is hard to say, but I suspect that it will be a lot easier (1) In R construct the table as a simple matrix or data frame and the (2) print with xtable packable, where you could have control over the type of columns (and you could also use booktabs rules, with a more elegant look).
      – Fran
      Dec 1 at 13:18













    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',
    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%2f462558%2falignment-with-a-latex-hbox%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








    up vote
    1
    down vote



    accepted










    Center, left and right aligned "xxx":



    documentclass{article}
    begin{document}
    hbox to 5cm{hfil xxx hfil}par
    hbox to 5cm{hfil xxx}par
    hbox to 5cm{xxx hfil}par
    end{document}


    But better:



    documentclass{article}
    begin{document}
    makebox[5cm][c]{x x x}par
    makebox[5cm][r]{x x x}par
    makebox[5cm][l]{x x x}par
    makebox[5cm][s]{x x x}par
    end{document}





    share|improve this answer



























      up vote
      1
      down vote



      accepted










      Center, left and right aligned "xxx":



      documentclass{article}
      begin{document}
      hbox to 5cm{hfil xxx hfil}par
      hbox to 5cm{hfil xxx}par
      hbox to 5cm{xxx hfil}par
      end{document}


      But better:



      documentclass{article}
      begin{document}
      makebox[5cm][c]{x x x}par
      makebox[5cm][r]{x x x}par
      makebox[5cm][l]{x x x}par
      makebox[5cm][s]{x x x}par
      end{document}





      share|improve this answer

























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        Center, left and right aligned "xxx":



        documentclass{article}
        begin{document}
        hbox to 5cm{hfil xxx hfil}par
        hbox to 5cm{hfil xxx}par
        hbox to 5cm{xxx hfil}par
        end{document}


        But better:



        documentclass{article}
        begin{document}
        makebox[5cm][c]{x x x}par
        makebox[5cm][r]{x x x}par
        makebox[5cm][l]{x x x}par
        makebox[5cm][s]{x x x}par
        end{document}





        share|improve this answer














        Center, left and right aligned "xxx":



        documentclass{article}
        begin{document}
        hbox to 5cm{hfil xxx hfil}par
        hbox to 5cm{hfil xxx}par
        hbox to 5cm{xxx hfil}par
        end{document}


        But better:



        documentclass{article}
        begin{document}
        makebox[5cm][c]{x x x}par
        makebox[5cm][r]{x x x}par
        makebox[5cm][l]{x x x}par
        makebox[5cm][s]{x x x}par
        end{document}






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 30 at 16:26

























        answered Nov 30 at 16:18









        Fran

        50.3k6111174




        50.3k6111174






















            up vote
            0
            down vote













            I've accepted the answer above because it technically answered the question about alignment within an hbox, although it didn't really help me accomplish what I wanted to do.



            For anyone interested, I did find a rather ugly work around for my problem. Instead of using valign to build my transposed table from the arrays, I used minipages. This, of course, only worked because I knew the number of columns that I wanted and had a relatively good guess as to the approximate widths I wanted those columns to be. Here is the code I ended up with:



            begin{minipage}{.5textwidth}
            centering
            hrule height 1.3pt
            strut ~\
            strut Item\
            hrule height 1.3pt
            strut Sexpr{paste(items, collapse="\\strut \\\\ \\hrule ")}strut
            hrule height 1.3pt
            end{minipage}%
            begin{minipage}{.2textwidth}
            centering
            hrule height 1.3pt
            struthfill Price at Original\
            struthfill Location ($)\
            hrule height 1.3pt
            strut hfill Sexpr{paste(site1price, collapse="\\strut \\\\ \\hrule \\hfill")}strut
            hrule height 1.3pt
            end{minipage}%
            begin{minipage}{.2textwidth}
            centering
            hrule height 1.3pt
            struthfill Price at New\
            struthfill Location ($)\
            hrule height 1.3pt
            strut hfill Sexpr{paste(site2price, collapse="\\strut \\\\ \\hrule \\hfill")}strut
            hrule height 1.3pt
            end{minipage}


            This produces something like this:
            enter image description here






            share|improve this answer








            New contributor




            NateA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.


















            • Maybe is that I do not understand well... buto this to make a simple table with R outputs? Without the R code is hard to say, but I suspect that it will be a lot easier (1) In R construct the table as a simple matrix or data frame and the (2) print with xtable packable, where you could have control over the type of columns (and you could also use booktabs rules, with a more elegant look).
              – Fran
              Dec 1 at 13:18

















            up vote
            0
            down vote













            I've accepted the answer above because it technically answered the question about alignment within an hbox, although it didn't really help me accomplish what I wanted to do.



            For anyone interested, I did find a rather ugly work around for my problem. Instead of using valign to build my transposed table from the arrays, I used minipages. This, of course, only worked because I knew the number of columns that I wanted and had a relatively good guess as to the approximate widths I wanted those columns to be. Here is the code I ended up with:



            begin{minipage}{.5textwidth}
            centering
            hrule height 1.3pt
            strut ~\
            strut Item\
            hrule height 1.3pt
            strut Sexpr{paste(items, collapse="\\strut \\\\ \\hrule ")}strut
            hrule height 1.3pt
            end{minipage}%
            begin{minipage}{.2textwidth}
            centering
            hrule height 1.3pt
            struthfill Price at Original\
            struthfill Location ($)\
            hrule height 1.3pt
            strut hfill Sexpr{paste(site1price, collapse="\\strut \\\\ \\hrule \\hfill")}strut
            hrule height 1.3pt
            end{minipage}%
            begin{minipage}{.2textwidth}
            centering
            hrule height 1.3pt
            struthfill Price at New\
            struthfill Location ($)\
            hrule height 1.3pt
            strut hfill Sexpr{paste(site2price, collapse="\\strut \\\\ \\hrule \\hfill")}strut
            hrule height 1.3pt
            end{minipage}


            This produces something like this:
            enter image description here






            share|improve this answer








            New contributor




            NateA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.


















            • Maybe is that I do not understand well... buto this to make a simple table with R outputs? Without the R code is hard to say, but I suspect that it will be a lot easier (1) In R construct the table as a simple matrix or data frame and the (2) print with xtable packable, where you could have control over the type of columns (and you could also use booktabs rules, with a more elegant look).
              – Fran
              Dec 1 at 13:18















            up vote
            0
            down vote










            up vote
            0
            down vote









            I've accepted the answer above because it technically answered the question about alignment within an hbox, although it didn't really help me accomplish what I wanted to do.



            For anyone interested, I did find a rather ugly work around for my problem. Instead of using valign to build my transposed table from the arrays, I used minipages. This, of course, only worked because I knew the number of columns that I wanted and had a relatively good guess as to the approximate widths I wanted those columns to be. Here is the code I ended up with:



            begin{minipage}{.5textwidth}
            centering
            hrule height 1.3pt
            strut ~\
            strut Item\
            hrule height 1.3pt
            strut Sexpr{paste(items, collapse="\\strut \\\\ \\hrule ")}strut
            hrule height 1.3pt
            end{minipage}%
            begin{minipage}{.2textwidth}
            centering
            hrule height 1.3pt
            struthfill Price at Original\
            struthfill Location ($)\
            hrule height 1.3pt
            strut hfill Sexpr{paste(site1price, collapse="\\strut \\\\ \\hrule \\hfill")}strut
            hrule height 1.3pt
            end{minipage}%
            begin{minipage}{.2textwidth}
            centering
            hrule height 1.3pt
            struthfill Price at New\
            struthfill Location ($)\
            hrule height 1.3pt
            strut hfill Sexpr{paste(site2price, collapse="\\strut \\\\ \\hrule \\hfill")}strut
            hrule height 1.3pt
            end{minipage}


            This produces something like this:
            enter image description here






            share|improve this answer








            New contributor




            NateA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            I've accepted the answer above because it technically answered the question about alignment within an hbox, although it didn't really help me accomplish what I wanted to do.



            For anyone interested, I did find a rather ugly work around for my problem. Instead of using valign to build my transposed table from the arrays, I used minipages. This, of course, only worked because I knew the number of columns that I wanted and had a relatively good guess as to the approximate widths I wanted those columns to be. Here is the code I ended up with:



            begin{minipage}{.5textwidth}
            centering
            hrule height 1.3pt
            strut ~\
            strut Item\
            hrule height 1.3pt
            strut Sexpr{paste(items, collapse="\\strut \\\\ \\hrule ")}strut
            hrule height 1.3pt
            end{minipage}%
            begin{minipage}{.2textwidth}
            centering
            hrule height 1.3pt
            struthfill Price at Original\
            struthfill Location ($)\
            hrule height 1.3pt
            strut hfill Sexpr{paste(site1price, collapse="\\strut \\\\ \\hrule \\hfill")}strut
            hrule height 1.3pt
            end{minipage}%
            begin{minipage}{.2textwidth}
            centering
            hrule height 1.3pt
            struthfill Price at New\
            struthfill Location ($)\
            hrule height 1.3pt
            strut hfill Sexpr{paste(site2price, collapse="\\strut \\\\ \\hrule \\hfill")}strut
            hrule height 1.3pt
            end{minipage}


            This produces something like this:
            enter image description here







            share|improve this answer








            New contributor




            NateA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            share|improve this answer



            share|improve this answer






            New contributor




            NateA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            answered Dec 1 at 12:03









            NateA

            183




            183




            New contributor




            NateA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





            New contributor





            NateA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






            NateA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.












            • Maybe is that I do not understand well... buto this to make a simple table with R outputs? Without the R code is hard to say, but I suspect that it will be a lot easier (1) In R construct the table as a simple matrix or data frame and the (2) print with xtable packable, where you could have control over the type of columns (and you could also use booktabs rules, with a more elegant look).
              – Fran
              Dec 1 at 13:18




















            • Maybe is that I do not understand well... buto this to make a simple table with R outputs? Without the R code is hard to say, but I suspect that it will be a lot easier (1) In R construct the table as a simple matrix or data frame and the (2) print with xtable packable, where you could have control over the type of columns (and you could also use booktabs rules, with a more elegant look).
              – Fran
              Dec 1 at 13:18


















            Maybe is that I do not understand well... buto this to make a simple table with R outputs? Without the R code is hard to say, but I suspect that it will be a lot easier (1) In R construct the table as a simple matrix or data frame and the (2) print with xtable packable, where you could have control over the type of columns (and you could also use booktabs rules, with a more elegant look).
            – Fran
            Dec 1 at 13:18






            Maybe is that I do not understand well... buto this to make a simple table with R outputs? Without the R code is hard to say, but I suspect that it will be a lot easier (1) In R construct the table as a simple matrix or data frame and the (2) print with xtable packable, where you could have control over the type of columns (and you could also use booktabs rules, with a more elegant look).
            – Fran
            Dec 1 at 13:18




















            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%2f462558%2falignment-with-a-latex-hbox%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

            How to change which sound is reproduced for terminal bell?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Can I use Tabulator js library in my java Spring + Thymeleaf project?