如何在 Latex 中合并表格单元格
我有这张桌子
\begin{table*}[htbp]
\caption{Test Table}
\begin{center}
\begin{tabular}{|c|c|c|}
\hline
\textbf{\thead{Type}} & \textbf{\thead{Category}} & \textbf{{Name}}\\
\hline
Apple&IT&Nancy\\
\hline
Apple&Business&Mike\\
\hline
Apple&IT&Ali\\
\hline
Microsoft&Marketing&Linda\\
\hline
Microsoft&IT&Sam\\
\hline
Google&Marketing&Eduard\\
\hline
Google&Business&John\\
\hline
\end{tabular}
\label{graph_1}
\end{center}
\end{table*}
我想在第一列中加入相似的值
所以它看起来是这样的。
答案1
与\multirow
和\multicolumn
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table*}[htbp]
\caption{Test Table}
\label{tab:my-table}
\begin{center}
\begin{tabular}{|c|c|c|}
\hline
\textbf{Type }& \textbf{Category} & \textbf{Name} \\ \hline
\multirow{3}{*}{Apple} & IT & Nancy \\ \cline{2-3}
& Business & Mike \\ \cline{2-3}
& IT & Ali \\ \hline
\multirow{2}{*}{Microsoft} & Marketing & Linda \\ \cline{2-3}
& IT & Sam \\ \hline
\multirow{2}{*}{Google} & Marketing & Eduard \\ \cline{2-3}
& Business & John \\ \hline
\end{tabular}
\end{center}
\end{table*}
\end{document}
答案2
使用,您{NiceTabular}
可以nicematrix
使用命令合并单元格\Block
,然后您可以使用键绘制所有规则hvlines
(规则不会在块中绘制)。
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{table*}[htbp]
\caption{Test Table}
\label{tab:my-table}
\centering
\begin{NiceTabular}{ccc}[hvlines]
\textbf{Type }& \textbf{Category} & \textbf{Name} \\
\Block{3-1}{Apple} & IT & Nancy \\
& Business & Mike \\
& IT & Ali \\
\Block{2-1}{Microsoft} & Marketing & Linda \\
& IT & Sam \\
\Block{2-1}{Google} & Marketing & Eduard \\
& Business & John \\
\end{NiceTabular}
\end{table*}
\end{document}
答案3
\documentclass{article}
\usepackage{makecell, multirow, booktabs}
\usepackage[labelfont=bf]{caption}
\begin{document}
\begin{table*}[htbp]
\caption{Test Table}
\begin{center}
\begin{tabular}{ccc}
\toprule
\textbf{\thead{Type}} & \textbf{\thead{Category}} & \textbf{{Name}}\\
\hline
\multirow{3.7}{*}{Apple}&IT&Nancy\\
\cmidrule{2-3}
&Business&Mike\\
\cmidrule{2-3}
&IT&Ali\\
\midrule
\multirow{2.5}{*}{Microsoft}&Marketing&Linda\\
\cmidrule{2-3}
&IT&Sam\\
\midrule
\multirow{2.5}{*}{Google}&Marketing&Eduard\\
\cmidrule{2-3}
&Business&John\\
\bottomrule
\end{tabular}
\label{graph_1}
\end{center}
\end{table*}
\end{document}
答案4
太长了,无法发表评论...
对 @js bibra 答案进行了微小但重要的修改。区别在于:
- 环境
center
被\centering
命令替换 - 在列标题中被删除
\textbf{...}
,只使用\thead
指令。因为它在序言中定义了字体\renewcommand\theadfont{\small\bfseries}
- 对于水平规则,使用
booktabs
包中定义的规则。规则仅在以下类型组之间使用:
\documentclass{article}
\usepackage{booktabs,makecell, multirow, booktabs}
\renewcommand\theadfont{\small\bfseries}
\usepackage[skip=1ex,
font=small, labelfont=bf]{caption}
\begin{document}
\begin{table}[htbp]
\caption{Test Table}
\label{tab:my-table}
\centering
\begin{tabular}{lll}
\toprule
\thead{Type} & \thead{Category} & \thead{Name} \\ \midrule
\multirow{3}{*}{Apple} & IT & Nancy \\
& Business & Mike \\
& IT & Ali \\ \midrule
\multirow{2}{*}{Microsoft} & Marketing & Linda \\
& IT & Sam \\ \midrule
\multirow{2}{*}{Google} & Marketing & Eduard \\
& Business & John \\
\bottomrule
\end{tabular}
\end{table}
\end{document}