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
\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:
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:
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 replacingwith
or, more succinctly, by replacing
c
in the second argument of the applicable\multicolumn
instruction withWhat'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 than2\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 thebabel
package with the optionczech
, I further suggest you run the instruction\shorthandoff{-}
-- just inside thecenter
environment -- in order to enable\hhline
with single horizontal rules.