我正在尝试创建一个如下所示的表格。我不确定为什么我的代码会将“样本 ID”列设置为与“成分”列一样宽,即使它们在行中有不同的设置multicolumn{}{this}{}
。有没有更简单的方法可以控制宽度,还是我太盲目以至于看不到我在某个地方犯的错误?
\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}
更新:由于需要进行细微调整,代码已更新。还上传了一张新图片来显示问题。我想让单元格 (2,2) 换行,但似乎不允许\underline
该操作?有什么建议吗?
答案1
编辑:
像这样(考虑到你下面的答案的评论)?
它是通过使用tabularx
表格环境、宏\thead
和包以及适当选择列类型获得的。对于第二列单元格中的下划线文本,使用来自包的(不能换行)来代替,该包\makegapedcells
可以在单元格中断开文本。对于具有度量的值,我建议使用包:makcell
\ul{...}
\underbar{...}
soul
\siunitx
\documentclass{article}
\usepackage{geometry}
\usepackage{makecell, tabularx}
\renewcommand\theadfont{\normalsize\bfseries}
\renewcommand\theadgape{}
\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
\thead{Solution} & \thead{Sample ID}
& \thead{Composition} & \thead{Init} \\
\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}