2

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?

1 Answers1

2

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.

Werner
  • 603,163
  • Very good. Your first suggestion using \extracolsep{\fill} is closer to what I really want. This command sets the space between all pairs (of adjacent) columns. Is there a way to set different values between different pairs (of adjacent) columns? – Tyson Williams Oct 01 '14 at 21:32
  • @TysonWilliams: You could still use @{\hspace{<len>}} to inserts a specific <len> between columns. However, when using \@extracolsep{\fill} and @{\hspace{<len>} both will be used. – Werner Oct 01 '14 at 23:29
  • But @{\hspace{\fill}} doesn't work. Why not? – Tyson Williams Oct 02 '14 at 02:30
  • @TysonWilliams: I don't really know... – Werner Oct 02 '14 at 02:49
  • Ah, I figure out a good workaround. As stated here, "An \extracolsep{wd} command in an @-expression causes an extra space of width wd to appear to the left of all subsequent columns, until countermanded by another \extracolsep command." Thus, multiple uses of \extracolsep{wd} with varied wd parameters achieves my desired behavior. – Tyson Williams Oct 02 '14 at 14:13