53

I have a table as shown below.

\documentclass{article}
\usepackage{graphicx}
\newcommand*\rot{\rotatebox{90}}

\begin{document}

\begin{table}[!ht]
  \centering
    \begin{tabular}{| c | c | c |}
        \hline
        1 & 2  &  3\\ \hline
        \rot{\textbf{1st column}} & \rot{\textbf{2nd column}} & \rot{\textbf{3rd column}} \\ \hline
    \end{tabular}
\end{table}

\end{document}

I would like the width of columns by reducing the padding. I have tried

\begin{tabular}{| p{0.1cm} | c | c |}

However, it only removes the white space in the right-hand side of the first column and leave the white space intact in the left-hand side of it.

Javad
  • 763
  • 2
  • 7
  • 8
  • 6
    \setlength\tabcolsep{x pt}. The default value is 6 pt (which makes a total of 12pt between two consecutive cells). – Bernard Sep 14 '14 at 11:12

2 Answers2

76

To change the amount of vertical whitespace that LaTeX inserts to the left and right of every column, change the length parameter \tabcolsep. Its default value is 6pt; change it via either \setlength or \addtolength. In the example below, the second table features a value of 1.5pt for \tabcolsep.

enter image description here

\documentclass{article}
\usepackage{graphicx}
\newcommand*\rot[1]{\rotatebox{90}{#1}}
\begin{document}
\begin{table}[!ht]
  \centering
    \begin{tabular}{| c | c | c |}
        \hline
        1 & 2  &  3\\ \hline
        \rot{\textbf{1st column}} & \rot{\textbf{2nd column\ }} & \rot{\textbf{3rd column}} \\ \hline
    \end{tabular}
\qquad  % get some separation between the two tabulars
\setlength\tabcolsep{1.5pt} % default value: 6pt
    \begin{tabular}{| c | c | c |}
        \hline
        1 & 2  &  3\\ \hline
        \rot{\textbf{1st column}} & \rot{\textbf{2nd column\ }} & \rot{\textbf{3rd column}} \\ \hline
    \end{tabular}
\end{table}
\end{document}
Mico
  • 506,678
  • 2
    How can I adjust the separation of just some columns? – Veridian Apr 13 '16 at 23:44
  • 1
    @Veridian - Insert @{\hspace{<desired separation>} in the desired location. E.g., write \begin{tabular}{c@{\hspace{3em}c} instead of just \begin{tabular}{cc}. – Mico Apr 14 '16 at 05:14
  • 3
    I think @MIco has a typo in that comment: It should be \begin{tabular}{c@{\hspace{3em}}c}, with one addition }. – Karalga Dec 14 '17 at 11:05
20

Is this what you looking for?

enter image description here

\documentclass{article}
\usepackage{graphicx}
\newcommand*\rot{\rotatebox{90}}

\begin{document} \begin{table}[!ht] \centering \begin{tabular}{|@{\hskip3pt}c@{\hskip3pt}| c |@{\hskip3pt}c@{\hskip3pt}|} \hline 1 & 2 & 3\ \hline \rot{\textbf{1st column}} & \rot{\textbf{2nd column}} & \rot{\textbf{3rd column}} \ \hline \end{tabular} \end{table} \end{document}

The @{} in place of insertion set \tabcolsep distance to zero. If you like to have in this place different space between adjacent columns, than you can locally determine it with @{<distance>} where you select <width> according to your wish.

Addendum Today, when the tabularray package (version 2021P) is available, one may consider the following solution:

\documentclass{article}
\usepackage{rotating}
\usepackage{makecell}
\usepackage{tabularray}

\begin{document} \begin{table}[!ht] \centering \setlength\rotheadsize{6em} \begin{tblr}{hlines, vlines, colspec = {ccc}, % colsep = 6pt, % <--- default tabcolsep row{2} = {cmd=\rotcell,font=\bfseries, rowsep=0pt} } 1 & 2 & 3 \ 1st column & 2nd column & 3rd column \ \end{tblr} \qquad \begin{tblr}{hlines, vlines, colspec = {ccc}, colsep = 2pt, % <--- tabcolsep row{2} = {cmd=\rotcell,font=\bfseries, rowsep=0pt} } 1 & 2 & 3 \ 1st column & 2nd column & 3rd column \ \end{tblr} \qquad \begin{tblr}{hlines, vlines, colspec = {ccc}, colsep = 0pt, % <--- tabcolsep row{2} = {cmd=\rotcell,font=\bfseries, rowsep=0pt} } 1 & 2 & 3 \ 1st column & 2nd column & 3rd column \ \end{tblr} \end{table} \end{document}

enter image description here

Zarko
  • 296,517