我想知道如何合并表格中第一列的三行连续行。我还需要帮助对齐表格的标题。
\documentclass[preview]{standalone}
\usepackage[dvipsnames,table]{xcolor}
\usepackage{array}
\usepackage{environ}
\usepackage{tikz}
\usepackage{caption}
\newsavebox{\tablebox}
\definecolor{tablecolor}{named}{gray}
\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}{Your caption here}
\begin{rndtable}{l p{2.5cm}}
\header{Name} &
\header{\parbox[t]{2cm}{Experience in Number of Years}} \\
Ahmad & 7 Years \\
Nadeem & 2 Years at UAF\\
Nadeem & 1 Years at NTU\\
Nadeem & 3 Years at GCU\\
\end{rndtable}
\end{center}
\end{document}
答案1
这是一个肮脏的解决方案,会产生肮脏的结果;)
\documentclass[preview,border=5pt]{standalone}
\usepackage[dvipsnames,table]{xcolor}
\usepackage{array,multirow}
\usepackage{environ}
\usepackage{tikz}
\usepackage{caption}
\newcolumntype{C}[1]{>{\raggedright\arraybackslash}m{#1}}
\newsavebox{\tablebox}
\definecolor{tablecolor}{named}{gray}
\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}{Your caption here}
\begin{rndtable}{l p{2.5cm}}
\header{Name} &
\multicolumn{1}{C{2.5cm}}{\cellcolor{tablecolor}\textcolor{white}{\bfseries Experience in Number of Years}} \\
\cellcolor{tablecolor!40} & 7 Years \\
\cellcolor{tablecolor!40} & 2 Years at UAF\\
\cellcolor{tablecolor!40}\multirow{-3}{*}{\parbox{1.5cm}{Ahmad Nadeem Nadeem}} & 1 Years at NTU\\
Nadeem & 3 Years at GCU\\
\end{rndtable}
\end{center}
\end{document}