# Whitespaces in tabularx added after \extracolsep

I'm quite new to Tex, but I did some tutorials and I'm stuck now, after googling didn't help anymore.

My code:

\bgroup
\def\arraystretch{1.75}
\begin{tabularx}{\textwidth}{ | l | @{\extracolsep{\fill}} l | l | l | l | l |}
\hline
\textbf{col 1} &  & col 3 & col 4 & & col 6
\\
\hline
some stuff & & & & other stuff &
\\
\hline
text thats pretty & & & & important &
\\
\hline

\multicolumn{5}{r|}{combined } & \\ \cline{6-6}
\end{tabularx}
\egroup


My problem looks like this:

I don't know, how to fix it. I'm used to HTML's simplicity by using "width: 100%;" and then the columns auto-resize. How could I manage to get something similar in Tex?

• You're getting a paragraph indent. You need should place a \noindent before the first \bgroup. – A.Ellett Jul 13 '13 at 21:37
• Doesn't really change something. Neither using \noindent{} nor just \noindent – michaeln Jul 13 '13 at 21:41
• Sorry, I didn't mean that the \noindent would fix how the \cline works. The \cline is being effected by the extra space thrown in between the columns by \extracolsep{\fill} – A.Ellett Jul 13 '13 at 21:43
• l type columns don't resize. You need tabularx' X columns. (With X columns only @{\extracolsep{\fill}} won't have an effect but all columns will have the same width) – clemens Jul 13 '13 at 21:46
• HTML and typography are not the same thing. It's not in general desirable to stretch a table to cover the entire line width, but this much depends on the nature of the table. – egreg Jul 13 '13 at 21:49

You're using the tabularx environment but you're not including any expandable columns. So tabularx is trying to fill the table to the width of \textwidth but can't find any columns to expand.

The tabularx environment gives you the ability to create exapandable columns. They're marked by X in the column declaration. These column expand to fill up the available space provided by the specified width for the environment. The expanded columns are treated as a \parbox of the width expanded to.

So should pick a column that will be expandable:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{tabularx}
\pagestyle{empty}
\begin{document}
\noindent
\bgroup
\def\arraystretch{1.75}%
\begin{tabularx}{\textwidth}{ | l |  @{\extracolsep{\fill}}  l | l | l | l | X |}
\hline
\textbf{col 1}    &  & col 3 & col 4 &             & col 6    \\\hline
some stuff        &  &       &       & other stuff &          \\\hline
text thats pretty &  &       &       & important   &          \\\cline{6-6}

\multicolumn{5}{r|}{combined } &                              \\\cline{6-6}
\end{tabularx}
\egroup

\end{document}


You're not restricted to only one expandable column. You can specify as many as you want. For example,

\begin{tabularx}{\textwidth}{ | l |  @{\extracolsep{\fill}}  X | X | X | X | X |}


You'll want the \noindent in the front of the group to prevent any indentation of a paragraph you would be getting otherwise.

Per @egreg 's comment, the content of this table doesn't seem to warrant filling the entire width of the page. Something like the following seems like it should work decently for you:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{tabularx}
\pagestyle{empty}
\begin{document}

\noindent
\hspace*{\fill}
\bgroup
\def\arraystretch{1.75}%
\begin{tabular}{ | l |  l | l | l | l | l |}
\hline
\textbf{col 1}    &  & col 3 & col 4 &             & col 6    \\\hline
some stuff        &  &       &       & other stuff &          \\\hline
text thats pretty &  &       &       & important   &          \\\cline{6-6}

\multicolumn{5}{r|}{combined } &                              \\\cline{6-6}
\end{tabular}
\egroup
\hspace*{\fill}

\end{document}

• Works like a charm! – michaeln Jul 13 '13 at 21:53
• Terrific explanation! concise for so much information. – Thomas Devine Jul 13 '18 at 2:19