I have a problem with creating a full-width table with multicolumn.
The code is:
\documentclass[]{article}
\usepackage{longtable,booktabs}
\usepackage{geometry}
\geometry{
a4paper,
left=20mm,
right=20mm,
top=20mm,
bottom=20mm
}
\usepackage{ltablex}
\usepackage{calc}
\usepackage[dvipsnames,table]{xcolor}
\usepackage{lipsum}
\definecolor{header-color}{HTML}{C0C0C0}
\definecolor{color-reserved}{HTML}{E0E0E0}
\definecolor{color1}{HTML}{F0F0F0}
\definecolor{color2}{HTML}{FFFFFF}
\begin{document}
\begin{tabularx}{\linewidth}%
{% col 1
|p{\widthof{Bit(s)}}|%
% col 2
p{\widthof{FIELD1\_NAME}}|%
% col 3
p{\widthof{Permissions}}|%
% col 4
p{\widthof{Reset Value}}|%
% col 5
X|
}
\hline
\rowcolor{header-color}
\rowcolor{header-color}{\bf Bit(s)} & {\bf Field Name} & {\bf Permissions} & {\bf Reset Value} & {\bf Attributes} \\
\hline
\hline
\endfirsthead
\hline
\rowcolor{header-color}{\bf Bit(s)} & {\bf Field Name} & {\bf Permissions} & {\bf Reset Value} & {\bf Attributes} \\
\hline
\hline
\endhead
\rowcolor{color-reserved}0 & Reserved & -- & -- & \\\hline
\rowcolor{color2}
1 & FIELD1\_NAME & RW & 0x0 & \\\hline
\rowcolor{color2}
& \multicolumn{4}{p{\hsize}|}{
\lipsum[1-2]
} \\\hline
\end{tabularx}
\end{document}
Unfortunately, it is not what I expected.
- The "Permission" column width is not wide enough
- There is an additional space on the right side which should not be there.
My expectations were that X will stretch the right column to the text width (as defined in the table configuration).
I intend to do create this table from the script and I can't set columns' sizes as constants.


\bffor bold text. Go for\bfseriesinstead. (See also: “Correct” way to bold/italicize text?) – leandriis Mar 22 '20 at 11:05\bfseriesinto yourwidthofcommands:p{\widthof{\bfseries Permissions}}. – leandriis Mar 22 '20 at 11:07ltype columns? Do you need automatic linebreaks in column 1-4? If not,lwill do just fine. – leandriis Mar 22 '20 at 11:08}` instead to avoid the text overflowing into the margin.
– leandriis Mar 22 '20 at 11:11