I have a couple of custom environments that I want to be able to use \hfill to right align the last column (similar to what {align} environment does with equation labels}. I attempted to use \hfill but that seems to be ignored within an align*, and tabular environments.

In the case of the tabular, or array like environment (with possibly a large number of columns), I have been adding \multicolumn{5}{r}{} for the case where the last 5 columns are unused to skip over them (and adjusting appropriately depending on the number of columns). This mostly works, but I have to count how many columns have been used, and if I decide to remove a column I have to adjust this. It would be preferable to not have to do that, and instead use \hfill to fill up the rest of the line and add the last column.

So, my question is there an easy way to use \hfill in an environment like tabular, to either get to the lat column, or preferably to the right hand side of the page.

2 Answers 2


You can use tabular*, with an \extracolsep{\fill} to move the last column to the right margin, as in:



Here's some text. Here's some text. Here's some text. Here's some
text. Here's some text. Here's some text. Here's some text. Here's
some text. Here's some text. Here's some text. Here's some
text. Here's some text.
    One& Two& Three& Number 1\\
    Four& Five& Six& Number 2


That gives you:enter image description here

(If you don't want it flush with the left margin, you can add an \hskip to that initial @{}.)

  • This is great. Now I just need to be able to determine how many columns to skip. So what I really want is to be able to add the following lines to the table and get the Number aligned on the right: Seven& Eight \MagicMacro{Number 3}\` and Ten \MagicMacro{Number 4}` which basically need to be an appropriate \multicolumn command to get me to the last column, but without having to manually count the columns. Apr 26, 2011 at 4:57

You can have a look at the tabbing environment to obtain the same effect. Define a command \tabright that will fill up the rest of the line


One                      \>\tabright{Number 1}\\
One \>Two                \>\tabright{Number 2}\\
One \>Two \>Three        \>\tabright{Number 3}\\
One \>Two \>Three \>Four \>\tabright{Number 4}\\

The output is then enter image description here

Note that this is a very usefull macro. If you change the line \makebox[\tdima][r]{#1} to \parbox[t]{\tdima}{#1\ifhmode\strut\fi} you have paragraph box that fills up the rest of the tabs to the right margin.

  • Yes, this is what I am looking for, but one that works in a tabular environment. Apr 26, 2011 at 7:29
  • @Peter Grill: I do not think you will get one that automatically counts the number of columns in a tabular. Maybe in a plain TeX table setup. Why the strict requirement for a tabular?
    – Danie Els
    Apr 26, 2011 at 7:48
  • Not stuck on tabular, just that it is mostly math that I want to align and have been using many of the features from the {array} package to define column formats. Tabbing seems to be more text oriented. The custom environments that I have set up will be used many times with a large number of align points, and I'd prefer not to have to count how many columns I have used so far, and add adequate number of alignment characters. Thanks for your help though. Apr 26, 2011 at 8:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .