我想为表格中的一组单元格添加边框。但不仅仅是单个单元格的边框,因为我觉得我可以将单元格内容放在 中fbox
。相反,我想要一个“合并”一些单元格的框架。嗯,我想我会尝试一些 ASCII 来展示我的意思:
---------------------------------------------------
Col 1 Col 2 Col 3 Col 4 Col 5 Col 6
---------------------------------------------------
bla bla bla bla bla bla
bla bla bla bla bla bla
+---------------------+
|ble ble ble| bla bla bla
+---------------------+
bla bla bla bla bla bla
我研究了 hhline 包,但很快意识到它与水平线有关。添加这两条垂直线似乎非常困难,它们只位于两个单元格之间,并不贯穿整个表格。我知道这\cline
可能用于绘制水平线,但我该如何绘制垂直线呢?(最好是看起来不错,形成一个框,而不仅仅是四条线之间有空格)
答案1
水平部分线条通过命令完成\cline
。对于垂直线条,您必须使用\multicolumn
命令指定新的列属性。
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{tabular}{*6{c}}\hline
Col 1 & Col 2 & Col 3 & Col 4 & Col 5 & Col 6 \\\hline
bla & bla & bla & bla & bla & bla \\
bla & bla & bla & bla & bla & bla \\ \cline{1-3}
\multicolumn{1}{|c}{ble} & ble & \multicolumn{1}{c|}{ble} & bla & bla & bla \\ \cline{1-3}
bla & bla & bla & bla & bla & bla \\ \hline
\end{tabular}
\end{document}
答案2
与。{NiceTabular}
nicematrix
\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}
\begin{document}
\begin{NiceTabular}{*6{c}}\toprule
Col 1 & Col 2 & Col 3 & Col 4 & Col 5 & Col 6 \\\midrule
bla & bla & bla & bla & bla & bla \\
bla & bla & bla & bla & bla & bla \\
\Block[draw,rounded-corners]{1-4}{}
ble & ble & ble & bla & bla & bla \\
bla & bla & bla & bla & bla & bla \\ \bottomrule
\end{NiceTabular}
\end{document}
如果您希望使用根据单元格内容进行调整的框架,这也是可行的,但您必须使用 TikZ 及其库fit
。
\documentclass{article}
\usepackage{nicematrix,tikz}
\usetikzlibrary{fit}
\usepackage{booktabs}
\begin{document}
\begin{NiceTabular}{*6{c}}\toprule
Col 1 & Col 2 & Col 3 & Col 4 & Col 5 & Col 6 \\\midrule
bla & bla & bla & bla & bla & bla \\
bla & bla & bla & bla & bla & bla \\
ble & ble & ble & bla & bla & bla \\
bla & bla & bla & bla & bla & bla \\ \bottomrule
\CodeAfter
\tikz \node [draw,inner sep=1pt,fit = (4-1) (4-3)] {} ;
\end{NiceTabular}
\end{document}