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 want to adjust the horizontal spacing between vertical lines and the cell content in a tabular table.

I could do it for each column with @{length}l@{length} (e. g. with \,), but there must be a more elegant way to do it globally for the whole table on the left and right side of each cell.

Example:

\documentclass[11pt, a4paper]{scrartcl}
\usepackage[margin=2.5cm]{geometry}
\usepackage{tabularx}
\begin{document}

\begin{tabular}{|p{2cm}*{4}{|@{\,}p{1.5cm}@{\,}}|@{}l@{}|}
\hline
1 & 2 & 3 & 4 & 5 & 6\\
\hline
word & word & more words & more and more words & longtext longtext longtext & verylongword \\
\hline
\end{tabular}
\end{document}
share|improve this question

2 Answers 2

up vote 18 down vote accepted

You just need to adjust the parameter \tabcolsep

\setlength{\tabcolsep}{.16667em}
\begin{tabular}{|p{2cm}*{4}{|p{1.5cm}}|l@{}|}
\hline
1 & 2 & 3 & 4 & 5 & 6\\
\hline
word & word & more words & more and more words & longtext longtext longtext & verylongword \\
\hline
\end{tabular}

You can use a group in order to keep the change local.

share|improve this answer

define a new columntype:

\newcolumntype{P}[1]{|@{\,}p{#1}@{\,}}

\begin{document}
\begin{tabular}{|p{2cm}*{4}{P{1.5cm}}|@{}l@{}|}
        
share|improve this answer
    
thank you, this is also an interesting approach. However tabcolsep is what was searching for, as it affects all columns. I'm sorry, maybe my MWE was misleading, as I used it to try several different settings to compare, but I definitely want the same horizontal spacing for all columns. –  Martin Sep 23 '11 at 9:41
    
I tried your new column type, but I get an error message "illegal parameter number in definition of" table. Might there be a typo in the newcolumntype, or a I doing something wrong? –  Martin Sep 23 '11 at 10:24
    
did you used it with package tabularx, it needs package array which is loaded by tabularx. However, I have no problem, using it with your example –  Herbert Sep 23 '11 at 10:30
    
yes, it works with my example. In my main document, there seems to be a problem. I'll see if I can find out what's wrong. –  Martin Sep 23 '11 at 11:39

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.