1

I'd like to stretch below tabular to a width of 15 cm width which is wider than the original table.

\documentclass{article}
\usepackage[landscape]{geometry}
\begin{document}

\begin{tabular}{|l|r|r|r|r|r|r|r|r|r|r|r|r|}
\hline
& Jan & Feb & Mar & Apr & May & Jun & Jul & Aug & Sep & Oct & Nov & Dec\\
\hline
2016 & 2.5 & 1.3 &  &  &  &  &  &  &  &  &  &\\
\hline
2015 & & 0.6 & 5.2 & 8.5 & 0.3 & 1.4 & 0.5 & 3.9 & 7.1 & 2.4 & 2.3 & -999.9\\
\hline
\end{tabular}

\end{document}

enter image description here

I use the tabu environment as shown below. While this produces a table with desired width, long cells now contain a line break (see cell for Dec 2015).

\documentclass{article}
\usepackage{tabu}
\usepackage[landscape]{geometry}
\begin{document}

\begin{tabu} to 15cm {|X[l]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|X[r]|}
\hline
& Jan & Feb & Mar & Apr & May & Jun & Jul & Aug & Sep & Oct & Nov & Dec\\
\hline
2016 & 2.5 & 1.3 &  &  &  &  &  &  &  &  &  &\\
\hline
2015 & & 0.6 & 5.2 & 8.5 & 0.3 & 1.4 & 0.5 & 3.9 & 7.1 & 2.4 & 2.3 & -999.9\\
\hline
\end{tabu}

\end{document}

enter image description here

How can I stretch the table to fill the available width without breaking cell content in two lines?

2

A comment up front: If a font size of 10pt (or larger) is in use, then the contents of the table won't fit if it's only 15 cm wide. I suggest you increase its width, say to \textwidth.

I suggest you use a tabularx environment instead of the basic tabular environment, and use a modified (viz., ragged-left) version of the X column type for columns 2 thru 13.

Separately, you may also want to consider giving the table a more "open" look, by omitting all vertical lines and having fewer, but well-spaced, horizontal lines. The second table in the following screenshot illustrates such an open look, achieved with the help of the line-drawing macros of the booktabs package.

enter image description here

\documentclass{article}
\usepackage[landscape]{geometry}
\usepackage{tabularx,booktabs}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\begin{document}
\setlength\parindent{0pt} % just for this example

With lots of horizontal and vertical lines:

\smallskip
\begin{tabularx}{\textwidth}{|l|*{12}{R|}}
\hline
& Jan & Feb & Mar & Apr & May & Jun & Jul & Aug & Sep & Oct & Nov & Dec\\
\hline
2016 & 2.5 & 1.3 &  &  &  &  &  &  &  &  &  &\\
\hline
2015 & & 0.6 & 5.2 & 8.5 & 0.3 & 1.4 & 0.5 & 3.9 & 7.1 & 2.4 & 2.3 & $-999.9$\\
\hline
\end{tabularx}

\bigskip\bigskip
With \emph{no} vertical lines and fewer, but well-spaced, horizontal lines:

\smallskip
\begin{tabularx}{\textwidth}{l*{12}{R}}
\toprule
& Jan & Feb & Mar & Apr & May & Jun & Jul & Aug & Sep & Oct & Nov & Dec\\
\midrule
2016 & 2.5 & 1.3 &  &  &  &  &  &  &  &  &  &\\
2015 & & 0.6 & 5.2 & 8.5 & 0.3 & 1.4 & 0.5 & 3.9 & 7.1 & 2.4 & 2.3 & $-999.9$\\
\bottomrule
\end{tabularx}

\end{document}
  • you should mentioned in answer, that you use full text width of page (and not only 15cm) and by this avoid to the OP problem ... Use of tabularx is better than use of (not maintained) tabu. – Zarko Feb 2 '16 at 14:29
  • 1
    @zarko - If the table is supposed to be 15cm wide and a 10pt (or larger) font size is in use, the final "-999.9" won't fit in the allocated cell. I'll make this more explicit in my write-up. – Mico Feb 2 '16 at 14:35
  • @Mico The same table fits into a tabular of less than 15cm width using the same font size. Why will the table not fit into a tabu or tabularx which is wider than the original table? – lukas Feb 2 '16 at 14:40
  • 1
    @lukas - The table "fits" in a tabular environment because the columns aren't equally wide. If you want the twelve data columns to have equal widths -- a reasonable thing, in my view... -- and stick with the original width of 15 cm, you'd have to reduce the amount of intercolumn whitespace by about 50% to get the table to "fit", virtually guaranteeing a collision of the material in the final two columns. – Mico Feb 2 '16 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.