# Adjust Array Column Width to Fill Page

I am trying to make use of the array environment (anything that operates similarly would suffice) that will automatically stretch the columns to be even-width and spread across the entire page. One example:

\documentclass[12pt]{article}
\usepackage{amsmath}
\renewcommand{\u}[1]{\underline{#1}}

\begin{document}
$\begin{array}{rrr} 5 & 5 & 5\\ \u{+4} &\u{+4} &\u{+4} \end{array}$
\end{document}


All that I know how to do at the moment is to insert a 'fake' column between each pair of columns and use \hspace*{##cm} to force the columns to spread out, but this gets a bit tedious if I have, say 7 columns on 13 rows that, for one reason or another, cannot all be a part of a single array environment.

Is there a semi-simple approach to this problem? I've been searching, but I haven't found anything that has seemed very helpful (it may be the case that I'm not familiar enough with the jargon to enter the best search phrases, too).

• Thank you! This is exactly what I have been looking for. Is there a way to redefine the tabular* environment so that it takes the form just written by default (default up to the number of columns, anyway)? That is, it seems like making several environments like this might get tiresome if the number of columns varies and the tried-and-true copy/paste technique fails. – Clayton Aug 1 '15 at 2:15
• @Mico: Thanks! (at)HarishKumar: The suggestion by Mico answered my question, I believe. One last thing regarding the structure of the document (although not important): is it possible to get the environment centered? This part seems more complicated to explain. Essentially, I just want the whitespace to be equal everywhere horizontally. – Clayton Aug 1 '15 at 2:23
• @Clayton - The tabular* method, when used with the @{\extracolsep{\fill}} device, will equalize the amounts of intercolumn whitespace, while the widths of the columns themselves will depend on what's in the columns. If, instead, you want the columns themselves to occupy equal widths, you should probably use a tabularx environment instead. – Mico Aug 1 '15 at 2:32
• @Mico: I'm not sure if you understood me; the intercolumn space is equal and therefore perfect! I'm also wanting the space from the edge of the page to be equal with the intercolumn space (if that makes sense). I don't care so much about the column width (unless that is a thing that becomes necessary to care about) as much as I do overall presentation, and equally spaced across the page looks slightly better in my opinion as opposed to offset to the right-hand side due to the right alignment. – Clayton Aug 1 '15 at 2:35

If I understand your requirements correctly, you want

• the numbers within each column to be decimal-aligned

• the columns themselves to be centered

• automatic adjustment to the column widths and/or the amounts of intercolumn whitespace so that the entire table takes up the width of the text block.

One way to achieve these objectives is to use a tabularx environment, load the dcolumn package to decimal-align the numbers, and use a modified (i.e., centered) form of the X column type to typeset the headers of each row.

\documentclass[12pt]{article}
\usepackage{tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\newcommand\mc[1]{\multicolumn{1}{Y}{#1}}

\usepackage{dcolumn}
\newcolumntype{d}[1]{D..{#1}} % "decimal-aligned" column type

\usepackage[normalem]{ulem} % for "safe underlining"
\renewcommand\u[1]{\uline{#1}}

\begin{document}
\hrule % just to illustrate width of text block
\smallskip\noindent
\begin{tabularx}{\linewidth}{ *{4}{d{2.0}} }

• @Clayton - Do check if changing the definition of the Z column type from \newcolumntype{Z}{>{\raggedleft\arraybackslash}X} to \newcolumntype{Z}{>{\centering\arraybackslash}X} does what you're looking to achieve. – Mico Aug 1 '15 at 2:48