I notice that the space between each column of a table in LaTeX is not quite wide (at least for me). Is there any way to set this? I found the \hspace, but I don't get how to use this in the table.
5 Answers
The parameter to act on is \tabcolsep, whose value is usually 6pt. So
\setlength{\tabcolsep}{12pt}
will double the intercolumn space. The parameter stores half the space between columns: in LaTeX each column is preceded and followed by a horizontal space \tabcolsep wide.
- 1,121,712
-
1In my case
\tabcolsepis by default2ptbut this may be the\documentclass{revtex}. – Qbyte Oct 21 '20 at 19:30
You can add space by inserting @{\hskip whatever} between the column specifiers, as in
\begin{tabular}{l@{\hskip 1in}c@{\hskip 0.5in}c}
One&Two& Three\\
Four& Five& Six
\end{tabular}
Actually, you can add whatever you like between the columns in place of the usual intercolumn space, e.g.,
\begin{tabular}{l@{ or }c@{\hskip 0.5in}c}
One&Two& Three\\
Four& Five& Six
\end{tabular}
- 757,742
- 8,942
-
26Really interesting, thanks. For anyone else, if discovered:
\hskipdefines the horizontal space, it is not additional to any other measure. E.g.@{\hskip -0.1cm}produces a bad output (just test it). – henry Aug 05 '13 at 13:13 -
1
-
5Note that this overrides the default space setting, so
{l@{\hskip 0in}c}means no space between theland theccolumn. – einpoklum May 23 '18 at 15:30 -
4doesn't play nice with multicolumn for me, not sure what the issue is – fabian789 Apr 05 '19 at 14:02
-
Re: multicolumns: It seems like the multicolumn span includes the space, rather than having the space be outside the column. So it might look right if the multicolumn is left-aligned, but if center- or right-aligned then it won't be correctly aligned with the non-multi-columns. Would be nice to have a solution for this because I'm not sure of another way to control spacing between each column separately. – Neil Traft Mar 06 '23 at 15:35
If you need to adjust the spacing for just one table you could also add/remove some space before the table and restore previous value after it:
\addtolength{\tabcolsep}{-1pt}
\begin{tabular}{cc}
text & text
\end{tabular}
\addtolength{\tabcolsep}{1pt}
- 206,688
- 1,424
-
-
8
-
8If you need to adjust the spacing for just one table you could put your code into curly braces and the change will affect just the table that is inside { \setlength{\tabcolsep}{12pt} \begin{tabular}{cc} ..... } – Pietro C May 17 '18 at 11:59
You can adjust the length \tabcolsep, for example:
\documentclass{article}
\begin{document}
\centering
\begin{tabular}{cc}
text & text
\end{tabular}
\setlength{\tabcolsep}{3em}
\begin{tabular}{cc}
text & text
\end{tabular}
\end{document}
\tabcolsep is the space which is inserted before and after a column. Note, this means that the space between two columns is 2\tabcolsep.
- 231,401
-
@stefan How can I specify a particlular tabcolsep for only one column using pgfplotstabletypeset – Nicholas Hamilton Aug 26 '13 at 00:54
-
1@ADP It seems like this could be posted as a new question, since this question is not about one column only and not related to pgfplots. – Stefan Kottwitz Aug 26 '13 at 07:09
If you need a more natural and flexible way to adjust space between rows or columns in tables, you may try tabularray package. You can use colsep (also leftsep and rightsep) and rowsep (also abovesep and belowsep) options with tblr environment.
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
hlines, vlines,
rows = {rowsep=8pt},
columns = {colsep=8pt},
}
Alpha & Beta & Gamma & Delta \
Epsilon & Zeta & Eta & Theta \
Iota & Kappa & Lambda & Mu \
\end{tblr}
\bigskip
\begin{tblr}{
hlines, vlines,
row{1} = {abovesep=1pt,belowsep=10pt},
column{2} = {leftsep=1pt,rightsep=10pt},
}
Alpha & Beta & Gamma & Delta \
Epsilon & Zeta & Eta & Theta \
Iota & Kappa & Lambda & Mu \
\end{tblr}
\end{document}
- 10,932

\tabcolsepchanged everywhere, we can do\renewcommand{\tabcolsep}{0.15cm}– zfm Apr 24 '11 at 22:40\renewcommand{\tabcolsep}{...}is definitely wrong; the correct way is with\setlength. – egreg Apr 24 '11 at 22:55\tabcolsepwith\setlength. – egreg Apr 25 '11 at 09:38\renewcommandwith,\setlength, right? so in the beginning of the command, I should write\setlength{\tabcolsep}{...}, is that ok? – zfm Apr 25 '11 at 10:18\tabcolsepis not a command like\section: it's a parameter which has a value and changing its meaning with\renewcommandmight break a package trying to set its value with the correct method. – egreg Apr 25 '11 at 10:52