# Actual table column width is unequal with set number

I want to create a table with fixed column lengths like this:

\documentclass[a4paper,12pt]{article}

\begin{document}

\begin{tabular}{|p{1cm}|p{2cm}|p{3cm}|}
\hline
1 cm  & 2 cm  & 3 cm  \\
\hline
\end{tabular}

Table with actual widths

\begin{tabular}{|p{0.56cm}|p{1.56cm}|p{2.56cm}|}
\hline
1 cm  & 2 cm  & 3 cm  \\
\hline
\end{tabular}

\end{document}


But column lengths are not the exact number, that I set. So I found the shift to make column with lengths, that I want.

Why this is happening and how I can automate the process of getting right value?

• The argument of the p columns specifies the textwidth inside the cells, not the total width with padding around the text. – user36296 Jan 18 at 15:02
• If you just for fun remove all other spaces \begin{tabular}{|@{}p{1cm}@{}|@{}p{2cm}@{}|@{}p{3cm}@{}|} you can see the effect – user36296 Jan 18 at 15:04

\documentclass[a4paper,12pt]{article}

\begin{document}

\setlength\arrayrulewidth{2pt}
\begin{tabular}{|p{\dimexpr1cm-2\tabcolsep}
|p{\dimexpr2cm-2\tabcolsep}
|p{\dimexpr3cm-2\tabcolsep}|}
\hline
1 cm  & 2 cm  & 3 cm  \\
\hline
\end{tabular}

\rule{6cm}{2pt}
\end{document}


make absolute width of cells as you like to have. rule is comparison of the table width.

Almost the same as @Zarko's answer, except reducing the (fine) length of the line separating columns... and a introducing a customized macro:

\documentclass[a4paper,12pt]{article}
\usepackage{array, calc}

\newlength{\lw}
\setlength{\lw}{2\tabcolsep+\arrayrulewidth}

\begin{document}

\begin{tabular}{| p{1cm-\lw} | p{2cm-\lw} | p{3cm-\lw} |}
\hline
1 cm  & 2 cm  & 3 cm  \\
\hline
\end{tabular}
Table with actual widths
\begin{tabular}{|p{0.56cm}|p{1.56cm}|p{2.56cm}|}
\hline
1 cm  & 2 cm  & 3 cm  \\
\hline
\end{tabular}

\end{document}


producing :