Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using a tabular* with rubber spacing to fill the complete width of the page. This works fine, except that when I use \cline, the line is not complete. It seems that \cline does not cover the spacing. I'm using pdflatex. Below you will find a code example. Any ideas on how to fix this?

 \usepackage{array} % for defining a new column type
 \usepackage{varwidth} %for the varwidth minipage environment
 %...
 \newcolumntype{M}{>{\begin{varwidth}{6cm}}l<{\end{varwidth}}} %M is for Maximal column
 %...
 \begin{tabular*}{15.5cm}{@{\extracolsep{\fill}} | M | r | r | r | r |}
   \hline
   \bf Omschrijving & \bf Hoeveelheid & \bf Prijs & \bf SubTotaal & \bf BTW\\
   \hline
   Armband 2 & 1 & 256.00 & 256.00 & 19.00\% \\
   \hline
   \multicolumn{3}{c |}{} & SubTotaal & 256.00\\
   \multicolumn{3}{c |}{} & BTW (19.0) & 48.64\\
   \multicolumn{3}{c |}{}  & \bf Totaal & \bf 304.64\\
   \cline{4-5}
\end{tabular*}
share|improve this question

3 Answers 3

up vote 6 down vote accepted

That's caused by \extracolsep{\fill} which produces the space that \cline doesn't fill. You could verify that by removing @{\extracolsep{\fill}}.

Besides removing that rubber length, you could repair it by

  • inserting another one such as

\begin{tabular*}{15.5cm}{@{\extracolsep{\fill}}| M | r | r |@{\extracolsep{0pt}}r | r |}

  • or by using a width-fitting tabular environment which adjust the columns width instead of the column separation: tabularx. This would be my choice.

Further I strongly recommend to omit all these vertical lines which obstruct the reading. Good tables don't need to be grids! Have a look at the booktabs package and its documentation. I would use perhaps a top line, a seperation line below the header and a bottom line, but no vertical line at all. Compare tables in good books, you're able to typeset fine tables too.

share|improve this answer
    
I actually tried using "@{\extracolsep{0pt}" but that did not work. Was I doing something wrong? Did this work for you? However, I strongly second the "tabularx" and "booktabs" suggestions. Those are my preferred packages anyday. –  Jimi Oke Dec 10 '10 at 2:38
    
@Jimi: It worked for me, I tested it. In your comment, a closing brace is missing. Could this be the reason? Otherwise I could post a minimal working example. –  Stefan Kottwitz Dec 10 '10 at 12:36
    
This works, but it also removes the spacing. The longest text is against the left line. I guess this is logical as @{\extracolsep{0pt}} removes the spacing. I will look into tabularx for a better solution. –  Stephan Dec 10 '10 at 17:31
    
@Stephan: spacing could be done within the column, by \makebox or \hspace for instance. But tabularx is better because that already adjusts column inner width. –  Stefan Kottwitz Dec 10 '10 at 17:35
    
I had the closing brace but my problem was I placed @{\extracolsep{0pt}} in the wrong column. Thanks. –  Jimi Oke Dec 10 '10 at 19:15

This isn't really an answer, but I would like to say that the from a bit of fiddling around it would seem that \extracolsep doesn't play very nicely with \cline regardless of the rubberlength

 \begin{tabular}{|@{\extracolsep{1cm}}{l}@{\extracolsep{1cm}}|r|c|@{\extracolsep{0cm}}}
\cline{1-3} 
 one&two&three\\
 \cline{2-3}
 one&two&three\\
 \cline{1-2}
 one&two&three\\
 \cline{2-2}
  one&two&three\\
 \cline{3-3}
\end{tabular}

results in alt text

There are a few things that are wrong:

  • Why is the first column so squished?
  • Why isn't there space added to the right and left of every column?
  • Why are the clines not going all the way to the verticals?

I know that this is not an answer...and I apologize, if people think that I should repost this as a question, I'd happily do that. Just to appease the gods, I've marked this answer CW so that people can convert the question into a real answer, as I think that there are issues here that are very relevant to the original question.

share|improve this answer
    
\extracolsep affects subsequent columns but will not insert space before the first column. Leslie Lamport wrote this in his book "A Document Preparation System" which is kind of a reference manual. However, for the first column a @{\hspace{1cm} would work. –  Stefan Kottwitz Dec 10 '10 at 12:50

As mentioned before (without example), this is provided by the tabularx package. More specifically, it provides the X column specifier that stretches that specific column as needed to fill the width of the table. Common usage has the format:

\usepackage{tabularx}% http://ctan.org/pkg/tabularx
...
\begin{tabularx}{<width>}{..X..X..}
  ...
\end{tabularx}

Here is your minimal example:

\documentclass{article}
%\usepackage{array}% http://ctan.org/pkg/array
\usepackage[margin=1cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}
%\newcolumntype{M}{>{\begin{varwidth}{6cm}}l<{\end{varwidth}}} %M is for Maximal column

\noindent%
\begin{tabularx}{\linewidth}{| p{6cm} | X | X | X | X |}
  \hline
  \textbf{Omschrijving} & \textbf{Hoeveelheid} & \textbf{Prijs} & \textbf{SubTotaal} & \textbf{BTW} \\
  \hline
  Armband 2 & 1 & 256.00 & 256.00 & 19.00\% \\
  \hline
  \multicolumn{3}{c |}{} & SubTotaal & 256.00 \\
  \multicolumn{3}{c |}{} & BTW (19.0) & 48.64 \\
  \multicolumn{3}{c |}{} & \textbf{Totaal} & \textbf{304.64} \\
  \cline{4-5}
\end{tabularx}
\end{document}

Tabularx example

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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