# Automatic line break inside multicolumn table

I'm trying to create a table as shown below. I'm not sure why my code makes the "Sample ID" column as wide as the "Composition" column even though they have a different setting in the multicolumn{}{this}{} line. Is there a way to control the width in an easier way or am I just too blind to see the mistake I made somewhere?

\begin{tabular}{|p{1.5cm}|p{3.5cm}|p{6cm}|p{1cm}|}
\multicolumn{2}{p{5cm}}{\textbf{Date:}} & \multicolumn{1}{c}{\textbf{Donor ID:}} & \multicolumn{1}{p{1cm}}{} \\
\multicolumn{2}{p{5cm}}{\textbf{ }} &
\multicolumn{2}{p{7cm}}{\textbf{ }}\\
\multicolumn{2}{p{5cm}}{\textbf{Serial index:}} & \multicolumn{2}{p{7cm}}{\textbf{ }} \\
\multicolumn{2}{p{5cm}}{\textbf{ }} &
\multicolumn{2}{p{7cm}}{\textbf{ }}\\
\hline
\textbf{Solution} & \textbf{Sample ID} & \textbf{Composition} &
\textbf{Init} \\ \hline
1 & \underbar{WB - Human Whole Blood} & \multicolumn{1}{|p{6cm}|}{The WB is gently mixed in the vacutainer and poured into a plastic beaker before it is collected in an appropriate sized syringe} &  \\ \hline
2 & \underbar{Ref WB} & \multicolumn{1}{|p{6cm}|}{Approx. 1 mL HWB is collected for reference measurements on the flow cytometer and an ABL90} & \\ \hline
\end{tabular}


Update: The code is updated due to a fine adjustment that was necessary. A new image is uploaded as well to show the problem. I want cell (2,2) to wrap the text, but i doesn't seem like \underline allows that operation? any suggestions?

• why have you got any \multicolumn here at all in the body of the table??, there are no spanning entries) – David Carlisle Feb 13 '19 at 11:25
• I've tried several things and i just thought that i could control the width more precisely with multicolumn. I just found out that it wasn't capable of wrapping the underlined text in cell (2,2). I just worked around that and wrote the name in two underlines. Prob not the best solution, but works for my purpose :) – gjorbf Feb 13 '19 at 11:29

edit:

like this (considering your comment below answer)?

it is obtained by use of tabularx table environment, macros \thead and \makegapedcells from makcell package and appropriate selection of columns type. for underlined text in second column's cells is used \ul{...} instead of \underbar{...} (which not enable to break lines) from package soul which enales to brak text in cells. for values with measure i suggest to use \siunitx package:

\documentclass{article}
\usepackage{geometry}
\usepackage{makecell, tabularx}
\setcellgapes{3pt}
\newcommand\mcl[1]{\multicolumn{2}{l}{\textbf{#1}}}
\usepackage{soul}    % <---
\usepackage{siunitx} % <---

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begin{table}[htb]
\makegapedcells
\begin{tabularx}{\linewidth}{|c|l|X|c|}
\mcl{Date:}         &   \mcl{Donor ID:}                             \\[2ex]
\mcl{Serial index:} &   \mcl{}                                      \\[2ex]
\hline
\hline
1   & \ul{WB - Human Whole Blood} % <---
& The WB is gently mixed in the vacutainer and poured into a plastic beaker before it is collected in an appropriate sized syringe
&                                       \\
\hline
2   & \ul{Ref WB}
& Approx. \SI{1}{mL} HWB is collected for reference measurements on the flow cytometer and an ABL90
&                                       \\
\hline
3   & \ul{WB - Human Whole Blood and more stuff}
& Approx. \SI{1}{mL} % <---
HWB is collected for reference measurements on the flow cytometer and an ABL90
&                                       \\
\hline
\end{tabularx}
\end{table}
\end{document}

• Thank you so much for your answer. This is more or less exactly what I wanted. – gjorbf Feb 13 '19 at 19:29
• I think the solution you suggest is neater, but I kinda still have a problem when the string "WB - Human Whole Blood" gets longer, e.g. "WB - Human Whole Blood and more stuff". This will just compress the Composition column. Are you experiencing something similar? It should just wrap the text automatically. – gjorbf Feb 13 '19 at 20:03
• than you should allowed to break cells' contents n this column. this is possible with use \ul{...}˙ macro from soul package. see edited answer. – Zarko Feb 13 '19 at 20:18