Tabularx – column width multicolumn

multicolumntabularx

I'm trying to create a table using tabularx environment and I need to use multiple columns to reproduce the original Word template table. On the first picture is how the table should look and below is my first try to reproduce it supposed layout

\documentclass[a4paper, 11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[czech]{babel}
\usepackage[margin=2cm]{geometry}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}
\sf
\noindent
\bgroup
\def\arraystretch{1.5}
\begin{center}
    \begin{tabularx}{\textwidth}{||C|C|C|C||}
        \hline \hline
        \multicolumn{4}{||c||}{{\large Ústav technologie stavebních dílců, FAST, VUT v Brně}}\\ [2mm]
        
        \multicolumn{4}{||c||}{{\huge \bfseries BJA006 Technologie betonu - laboratoře}}\\[2mm]
        
        \hline
        \large {\bfseries Číslo protokolu:} &\multicolumn{2}{|c|}{\large {\bfseries Název protokolu:}}  & \large {\bfseries Studijní skupina:} \\[2mm]
        
        \LARGE 1&\multicolumn{2}{|c|}{\LARGE Technologické zkoušky kameniva}  & \LARGE B3M1 \\[2mm]
        
        \hline
        
        \multicolumn{2}{||c|}{{\large \bfseries Vypracovala:}}  & \large {\bfseries Datum:} & \large {\bfseries Kontrolovala:}\\[2mm]
        
        \multicolumn{2}{||c|}{\LARGE XXX BBB} & \LARGE 10.10.2023 & \LARGE XXX BBB \\[2mm]
         
        \hline \hline
    \end{tabularx}
\end{center}
\egroup

\end{document}  

This code has resulted in this:
First try

As you can see, vertical lines are not aligned as they should be.
So I added empty line at the end of the table and got this:

Second try

So I tried using multicolumns also for singlecolumns and I got the original table. But using multicolumns is too complicated. So any suggestions where am I making a mistake? I don't belive there is such a bug in tex. The final code is here:

\documentclass[a4paper, 11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[czech]{babel}
\usepackage[margin=2cm]{geometry}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}
\sf
\noindent
\bgroup
\def\arraystretch{1.5}
\begin{center}
    \begin{tabularx}{\textwidth}{CCCC}
        \hline \hline
        \multicolumn{4}{||c||}{{\large Ústav technologie stavebních dílců, FAST, VUT v Brně}}\\ [2mm]
        
        \multicolumn{4}{||c||}{{\huge \bfseries BJA006 Technologie betonu - laboratoře}}\\[2mm]
        
        \hline
        \multicolumn{1}{||c}{\large {\bfseries Číslo protokolu:}}   &\multicolumn{2}{|c|}{\large {\bfseries Název protokolu:}}  & \multicolumn{1}{c||}{\large {\bfseries Studijní skupina:}} \\[2mm]
        
        \multicolumn{1}{||c}{\LARGE 1}&\multicolumn{2}{|c|}{\LARGE Technologické zkoušky kameniva}  & \multicolumn{1}{c||}{\LARGE B3M1} \\[2mm]
        
        \hline
        
        \multicolumn{2}{||c|}{{\large \bfseries Vypracovala:}}  &\multicolumn{1}{c|}{\large {\bfseries Datum:}} & \multicolumn{1}{c||}{\large {\bfseries Kontrolovala:}}\\[2mm]
        
        \multicolumn{2}{||c|}{\LARGE XXX BBB} & \multicolumn{1}{c|}{\LARGE 10.10.2023} & \multicolumn{1}{c||}{\LARGE XXX BBB} \\[2mm]
         
        \hline \hline
        &&&\\
    \end{tabularx}
\end{center}
\egroup

\end{document}

Best Answer

The issue is that while you define the table to have four columns with automatic, i.e., residually determined, widths, you currently don't provide enough information for LaTeX to be able to determine some of the combined column widths -- those with column type c. Specifically, the calculation of the width of the two bottom-left cell cannot be performed properly. To fix this, you should provide an explicit width calculation yourself, e.g., by replacing

\multicolumn{2}{||c|}{{\large \bfseries Vypracovala:}}

with

\multicolumn{2}{||>{\hsize=\dimexpr2\hsize+2\tabcolsep+1\arrayrulewidth\relax}C|}{%
   \large\bfseries Vypracovala:}

or, more succinctly, by replacing c in the second argument of the applicable \multicolumn instruction with

>{\hsize=\dimexpr2\hsize+2\tabcolsep+1\arrayrulewidth\relax}C

What's going on? Note that while the default width of a C-type column is given by the parameter \hsize, we're resetting the width to a bit more than 2\hsize -- specifically, 2\hsize+2\tabcolsep+1\arrayrulewidth.


Addendum: If you absolutely must draw double-vertical and double-horizontal lines around the table, I suggest you do so with the help of the hhline package and its \hhline macro. And, since you're using the babel package with the option czech, I further suggest you run the instruction \shorthandoff{-} -- just inside the center environment -- in order to enable \hhline with single horizontal rules.

enter image description here

\documentclass[a4paper, 11pt]{article}
\usepackage[T1]{fontenc} % <-- new
%\usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage[czech]{babel}
\usepackage[margin=2cm]{geometry}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage{hhline} % cf. https://www.ctan.org/pkg/hhline

\begin{document}

\begin{center}

\shorthandoff{-} % cf. https://tex.stackexchange.com/a/105935/5001

\def\arraystretch{1.5}
\sffamily

\begin{tabularx}{\textwidth}{|| C|C|C|C ||}
%\hline \hline
\hhline{|t:====:t|} % <-- new

\multicolumn{4}{||c||}{{\large Ústav technologie stavebních dílců, FAST, VUT v Brně}} \\ [2mm]
\multicolumn{4}{||c||}{{\huge\bfseries BJA006 Technologie betonu - laboratoře}} \\[2mm]
        
%\hline
\hhline{||----||} % <-- new

  \large\bfseries Číslo protokolu 
& \multicolumn{2}{|c|}{\large\bfseries Název protokolu}  & \large\bfseries Studijní skupina \\[2mm]
        
  \LARGE 1
& \multicolumn{2}{|c|}{\LARGE Technologické zkoušky kameniva}  
& \LARGE B3M1 \\[2mm]
        
%\hline
\hhline{||----||} % <-- new
        
\multicolumn{2}{||>{\hsize=\dimexpr2\hsize+2\tabcolsep+1\arrayrulewidth\relax}C|}{\large\bfseries Vypracovala}  
& \large\bfseries Datum 
& \large\bfseries Kontrolovala \\[2mm]
        
\multicolumn{2}{||c|}{\LARGE XXX BBB} 
& \LARGE 10.10.2023 
& \LARGE XXX BBB \\[2mm]
         
%\hline\hline
\hhline{|b:====:b|}  % <-- new

\end{tabularx}

\end{center}

\end{document}
Related Question