我试图合并表格的前三行,但无法完成。示例如下。
\documentclass{article}
\usepackage[dvipsnames,table]{xcolor}
\usepackage{array}
\usepackage{environ}
\usepackage{tikz}
\usepackage{caption}
\newsavebox{\tablebox}
\definecolor{tablecolor}{named}{cyan}
\NewEnviron{rndtable}[1]{%
\addtolength{\extrarowheight}{1ex}%
\rowcolors{2}{tablecolor!20}{tablecolor!40}%
\sffamily%
\newcommand{\header}[1]{%
\multicolumn{1}{c}{%
\cellcolor{tablecolor}\color{white}\bfseries##1}}
\savebox{\tablebox}{%
\begin{tabular}{#1}%
\BODY%
\end{tabular}}%
\begin{tikzpicture}
\clip[rounded corners=1ex] (0,-\dp\tablebox) -- (\wd\tablebox,-\dp\tablebox) -- (\wd\tablebox,\ht\tablebox) -- (0,\ht\tablebox) -- cycle;
\node at (0,-\dp\tablebox) [anchor=south west,inner sep=0pt]{\usebox{\tablebox}};
\draw[tablecolor,very thick,rounded corners=1ex] (0,-\dp\tablebox) -- (\wd\tablebox,-\dp\tablebox) -- (\wd\tablebox,\ht\tablebox) -- (0,\ht\tablebox) -- cycle;
\end{tikzpicture}
}
\begin{document}
\noindent
\begin{center}
\captionof{table}{Caption}
\footnotesize{
\begin{rndtable}{lp{3cm}p{5cm} ll} %
\header{C} &
\header{V} &
\header{T} &
\header{F} &
\textbf{A} & C & G & A\\
\textbf{B} & B & M & A\\
\textbf{B} & E & 1B & I \\
\textbf{I} & M & N & A \\
\textbf{M} & E & 12 & I \\
\textbf{N} & E & NA & NA \\
\textbf{P} & I & P & An \\
\textbf{S} & B & C & A \\
\multicolumn{4}{l} {\footnotesize \textcolor{red} {Source: Central banks
\end{rndtable}}
\end{center}
\end{document}
答案1
我不清楚“合并前三行”是什么意思,但这个例子可以修复和改进几个问题,例如:
- 花括号不匹配/错误匹配,例如“中央银行”后面缺少两个右括号。
\\
标题行后缺失。- 仅使用四列,但指定了五列。
- 剪辑可能应该适用于表格,而不是边框线。
- 水平居中的标题看起来有点奇怪,因此我将其更改为与其余列一样左对齐。
- 可以使用 定义矩形形状的路径
rectangle
。因此,只需要指定两对坐标,即左下角和右上角。
例子:
\documentclass{article}
\usepackage[dvipsnames,table]{xcolor}
\usepackage{array}
\usepackage{environ}
\usepackage{tikz}
\usepackage{caption}
\newsavebox{\tablebox}
\definecolor{tablecolor}{named}{cyan}
\NewEnviron{rndtable}[1]{%
\addtolength{\extrarowheight}{1ex}%
\rowcolors{2}{tablecolor!20}{tablecolor!40}%
\sffamily
\newcommand{\header}[1]{%
\multicolumn{1}{l}{%
\cellcolor{tablecolor}%
\color{white}%
\bfseries##1%
}%
}%
\savebox{\tablebox}{%
\begin{tabular}{#1}%
\BODY
\end{tabular}%
}%
\begin{tikzpicture}
\begin{scope}
\clip[rounded corners=1ex]
(0,-\dp\tablebox) rectangle (\wd\tablebox,\ht\tablebox);
\node at (0,-\dp\tablebox) [anchor=south west,inner sep=0pt]
{\usebox{\tablebox}};
\end{scope}
\draw[tablecolor,very thick,rounded corners=1ex]
(0,-\dp\tablebox) rectangle (\wd\tablebox,\ht\tablebox);
\end{tikzpicture}%
}
\begin{document}
\begin{center}
\captionof{table}{Caption}
\footnotesize
\begin{rndtable}{lp{3cm}p{5cm} l} %
\header{C} &
\header{V} &
\header{T} &
\header{F} \\
\textbf{A} & C & G & A\\
\textbf{B} & B & M & A\\
\textbf{B} & E & 1B & I \\
\textbf{I} & M & N & A \\
\textbf{M} & E & 12 & I \\
\textbf{N} & E & NA & NA \\
\textbf{P} & I & P & An \\
\textbf{S} & B & C & A \\
\multicolumn{4}{l} {\footnotesize \textcolor{red} {Source: Central banks}}
\end{rndtable}
\end{center}
\end{document}