[Tex/LaTex] How to fully justify tabular columns

spacingtables

I would like a tabular environment with fully justified columns. I my best guess of how to make this happen is to use a tabularx environment (so the tabular knows how wide to be) and then put \hilll (for some appropriate repetition of the letter l) between all adjacent columns. However, that didn't work. See the MWE below.

\documentclass{article}
\usepackage{tabularx}
\begin{document}
Text before. Text before. Text before. Text before. Text before. Text before. Text before.

\begin{tabularx}{\textwidth}{l@{\hfill}c@{\hfill}r}
 On the LEFT & In the middle & On the RIGHT
\end{tabularx}

Text between. Text between. Text between. Text between. Text between. Text between. Text between.

\def\magicNumber{50pt}
\begin{tabularx}{\textwidth}{lcr}
 On the LEFT & \hspace*{\magicNumber} In the middle \hspace*{\magicNumber} & On the RIGHT
\end{tabularx}

Text after. Text after. Text after. Text after. Text after. Text after. Text after. Text after.
\end{document}

enter image description here

The first tabularx environment is my failed attempt. The second tabularx environment is typeset (approximately) correct but is a hack using magic numbers.

Question:

How can one properly use infinite glues (like \hfill) to specify the space between tabularx columns? More generally, how can one obtain a tabular environment with fully justified columns?

Best Answer

tabularx only works when you use an X-column. What you're interested in is probably setting \extracolsep{\fill}, as suggested in Column and row padding in tables:

enter image description here

\documentclass{article}
\begin{document}
Text before. Text before. Text before. Text before. Text before. Text before. Text before.

\noindent
\begin{tabular*}{\linewidth}{@{}@{\extracolsep{\fill}}lcr@{}}
  On the LEFT & In the MIDDLE & On the RIGHT
\end{tabular*}

Text after. Text after. Text after. Text after. Text after. Text after. Text after. Text after.

\noindent
\begin{tabular*}{\linewidth}{@{}@{\extracolsep{\fill}}lcr@{}}
  On the LEFT & In the very MIDDLE & On the RIGHT
\end{tabular*}

\end{document}

Note that the above doesn't represent "fully justified" columns. For that you could use

enter image description here

\documentclass{article}
\usepackage{tabularx}
\begin{document}
Text before. Text before. Text before. Text before. Text before. Text before. Text before.

\noindent
\begin{tabularx}{\linewidth}{@{}XXX@{}}
  On the LEFT & In the MIDDLE & On the RIGHT
\end{tabularx}

Text after. Text after. Text after. Text after. Text after. Text after. Text after. Text after.

\end{document}

If needed, you can modify the justification for the columns using the array package.

Related Question