I created a table with the following code:
\begin{tabularx}{14cm}{|X|X|X|X|}
\hline
\multicolumn{4}{|c|}{\textbf{\cellcolor{gray!20}contentcontent}} \\
\hline
\multicolumn{4}{|p{\linewidth}|}{contentcontentcontentcontentcontentcontentcontentcontent} \\
\hline
\multicolumn{4}{|c|}{\textbf{\cellcolor{gray!20}contentcontent}} \\
\hline
\textbf{contentcontent:}& \footnotesize{contentcontent}& \textbf{contentcontent:} & \footnotesize{contentcontent}\\
\hline
\multicolumn{4}{|c|}{\textbf{\cellcolor{gray!20}contentcontent}} \\
\hline
\textbf{contentcontent:}& \footnotesize{contentcontent}& \textbf{contentcontent:} & \footnotesize{contentcontent}\\
\hline
\textbf{contentcontent:}& \footnotesize{contentcontent}& \textbf{contentcontent:} & \footnotesize{contentcontent}\\
\hline
\textbf{contentcontent:}& \footnotesize{contentcontent}& \textbf{contentcontent:} & \footnotesize{contentcontent}\\
\hline
\multicolumn{4}{|c|}{\textbf{\cellcolor{gray!20}contentcontent}} \\
\hline
\textbf{contentcontent:}& \footnotesize{contentcontent}& \textbf{contentcontent:} & \footnotesize{contentcontent}\\
\hline
\textbf{contentcontent:}& \multicolumn{3}{c|}{contentcontent}\\
\hline
\textbf{contentcontent:}& \footnotesize{contentcontent}& \textbf{contentcontent:} & \footnotesize{contentcontent}\\
\hline
\multicolumn{4}{|c|}{\textbf{\cellcolor{gray!20}contentcontent}} \\
\hline
\textbf{contentcontent 1:}& \multicolumn{3}{c|}{contentcontent}\\
\hline
\textbf{contentcontent 3:}& \multicolumn{3}{c|}{contentcontent}\\
\hline
\textbf{contentcontent 2:}& \multicolumn{3}{c|}{contentcontent}\\
\hline
\multicolumn{4}{|c|}{\textbf{\cellcolor{gray!20}contentcontent}} \\
\hline
\multicolumn{4}{|p{\linewidth}|}{contentcontent} \\
\hline
\multicolumn{4}{|l|}{\textbf{\cellcolor{gray!20}contentcontent}} \\
\hline
\end{tabularx}
And for some reason my h-line doesn't fill up fully on the right side.
What could be the issue? Thanks in advance.
Best Answer
The behavior you are noticing is due to your
\multicolumn
s likeIn all these cases replace
p{\linewidth}
withl
and the problem is solved.An example which doesn't work with your settings
Output
And this is how it should be (replacing
p{\linewidth}
withl
)Output:
Why your code doesn't work? Because your
tabularx
is14cm
wide and your\linewidth
is greater than that. The available space for ap
column spanning the wholetabularx
is14cm-2\tabcolsep-2\arrayrulewidth
, so if you want to use ap
column, it can not be greater than that length. If you want to use ap
column with the maximum length, usep{\dimexpr14cm-2\tabcolsep-2\arrayrulewidth\relax}
EDIT (in response to the OP's comment)
If you want automatical linebreaks in your table cells, this can not be done in
c
andl
columns.At this point, I suggest you to define
and replace all
c
columns withC{<width>}
columns and alll
columns withP{<width>}
columns, as in the following example: