我正在处理@David Carlisle 为我修复的有关此主题的表格:格式化表格中的 pbox 以使文本分布整齐表格的文本如下:
\documentclass[a4paper]{article}
\usepackage{array}
\setlength\extrarowheight{2pt}
\begin{document}
\newcommand\pb[1]{%
\begin{tabular}{@{}l@{}}#1\end{tabular}}
\begin{table}[htp]
\begin{tabular}{|l|l|l|l|l|}
\hline
\multicolumn{2}{|l|}{SOME TEXT HERE} & \multicolumn{3}{l|}{Big title that takes the whole page} \\ \hline
\multicolumn{2}{|l|}{MORE TEXT} & number & number & number \\ \hline
\multicolumn{2}{|l|}{ANOTHER TEXT} & number & number & number \\ \hline
some title here & value &\pb{12341 538768 \\ 23423 22}& \pb{12341 538768 \\ 23423 22} & \pb{12341 538768 \\ 23423 22} \\ \hline
\multicolumn{2}{|l|}{ANOTHER TEXT} & number & number & number \\ \hline
some title here & value & \pb{12341 538768 \\ 23423 228}& \pb{12341 538768 \\ 23423 22} & \pb{12341 538768 \\ 23423 22} \\ \hline
\multicolumn{2}{|l|}{ANOTHER TEXT} & number & number & number \\ \hline
some title here & value l & \pb{12341 538768 \\ 23423 22}& \pb{12341 538768 \\ 23423 22} & \pb{12341 538768 \\ 23423 22} \\ \hline
\end{tabular}
\caption{There should be proper caption.}
\end{table}
\end{document}
我现在想做的是让它更具可读性。为了做到这一点,我想让一些线条比其他线条更粗。问题是我希望表格内的线条粗细可以改变,这有点难以实现。以下是表格的示例:
有什么简单的方法可以实现这一点吗?
答案1
这是一个解决方案,使用来自的\Xhline
和\Xcline
命令makecell
:
\documentclass[a4paper]{article}
\usepackage{array}
\usepackage{makecell}
\renewcommand\cellalign{lc}
\setcellgapes{3pt}
\makegapedcells
\newcommand\thickvrule[1][2pt]{\vrule width #1}
\begin{document}
\begin{table}[htp]
\begin{tabular}{!{\thickvrule}l|l!{\thickvrule}*{2}{l|}l!{\thickvrule}}\Xhline{2pt}
\multicolumn{2}{!{\thickvrule}l!{\thickvrule}}{SOME TEXT HERE} & \multicolumn{3}{l!{\thickvrule}}{Big title that takes the whole page} \\ \hline
\multicolumn{2}{!{\thickvrule}l!{\thickvrule}}{MORE TEXT} & number & number & number \\ \hline
\multicolumn{2}{!{\thickvrule}l!{\thickvrule}}{ANOTHER TEXT} & number & number & number \\ \Xcline{1-2}{1.2pt}\Xcline{3-5}{2pt}
some title here & value &\makecell{12341 538768 \\ 23423 22}& \makecell{12341 538768 \\ 23423 22} & \makecell{12341 538768 \\ 23423 22} \\
\Xcline{1-2}{1.2pt}\Xcline{3-5}{2pt}
\multicolumn{2}{!{\thickvrule}l!{\thickvrule}}{ANOTHER TEXT} & number & number & number \\ \Xcline{1-2}{1.2pt}\Xcline{3-5}{2pt}
some title here & value & \makecell{12341 538768 \\ 23423 228}& \makecell{12341 538768 \\ 23423 22} & \makecell{12341 538768 \\ 23423 22} \\ \Xcline{1-2}{1.2pt}\Xcline{3-5}{2pt}
\multicolumn{2}{!{\thickvrule}l!{\thickvrule}}{ANOTHER TEXT} & number & number & number \\ \Xcline{1-2}{1.2pt}\Xcline{3-5}{2pt}
some title here & value l & \makecell{12341 538768 \\ 23423 22}& \makecell{12341 538768 \\ 23423 22} & \makecell{12341 538768 \\ 23423 22} \\ \Xhline{2pt}
\end{tabular}
\caption{There should be proper caption.}
\end{table}
\end{document}
答案2
您可以使用 来实现这一点{NiceTabular}
。nicematrix
在该环境中,键hvlines
会绘制 中除 之外的所有规则\multicolumn
。此外,nicematrix
还会在数组的单元格、行和列下创建 PGF/Tikz 节点。因此,您可以使用 Tikz 添加任何您想要的规则。在下面的代码中,我在构建表格后使用 Tikz 绘制了粗规则。
\documentclass[a4paper]{article}
\usepackage{array}
\usepackage{makecell}
\renewcommand\cellalign{lc}
\usepackage{nicematrix}
\NiceMatrixOptions{cell-space-limits=2pt}
\usepackage{tikz}
\begin{document}
\begin{table}[htp]
\begin{NiceTabular}{lllll}[hvlines]
\multicolumn{2}{l}{SOME TEXT HERE} & \multicolumn{3}{l}{Big title that takes the whole page} \\
\multicolumn{2}{l}{MORE TEXT} & number & number & number \\
\multicolumn{2}{l}{ANOTHER TEXT} & number & number & number \\
some title here & value &\makecell{12341 538768 \\ 23423 22}& \makecell{12341 538768 \\ 23423 22} & \makecell{12341 538768 \\ 23423 22} \\
\multicolumn{2}{l}{ANOTHER TEXT} & number & number & number \\
some title here & value & \makecell{12341 538768 \\ 23423 228}& \makecell{12341 538768 \\ 23423 22} & \makecell{12341 538768 \\ 23423 22} \\
\multicolumn{2}{l}{ANOTHER TEXT} & number & number & number \\
some title here & value l & \makecell{12341 538768 \\ 23423 22}& \makecell{12341 538768 \\ 23423 22} &
\makecell{12341 538768 \\ 23423 22} \\
\CodeAfter
\tikz \draw [very thick]
(1-|1) rectangle (9-|6)
(1-|3) -- (9-|3)
(4-|3) -- (4-|6)
(5-|3) -- (5-|6)
(6-|3) -- (6-|6)
(7-|3) -- (7-|6)
(8-|3) -- (8-|6) ;
\end{NiceTabular}
\caption{There should be proper caption.}
\end{table}