我有以下代码,可并排创建三个表格。如何为每个表格分别添加不同的标题?
\begin{table}
\footnotesize
\begin{tabular}{|l|l|}
\hline
Service & Features \\
\hline
$S_{11}$ & $F_1$ \\
$S_{12}$ & $F_1$ \\
$S_{13}$ & $F_1$ \\
$S_{14}$ & $F_1$ \\
$S_{15}$ & $F_2$ \\
\hline
\end{tabular}
\hfill
\begin{tabular}{|l|l|}
\hline
Service & Features \\
\hline
$S_{21}$ & $F_3$ \\
$S_{22}$ & $F_3$ \\
$S_{23}$ & $F_3$ \\
$S_{24}$ & $F_3$ \\
$S_{25}$ & $F_4$ \\
\hline
\end{tabular}
\hfill
\begin{tabular}{|l|l|}
\hline
Service & Features \\
\hline
$S_{31}$ & $F_5$ \\
$S_{32}$ & $F_5$ \\
$S_{33}$ & $F_5$ \\
\hline
\end{tabular}
\caption{99 most frequent hashtags in the data set.}
\end{table}
答案1
我不太清楚您喜欢如何在表格中添加标题,因此下面是两个可能的示例:
第一个用于tabularx
在行中展开表格,第二个用于使用subtable
来自包的环境subcaption
:
\documentclass{article}
\usepackage{tabularx}
\usepackage{subcaption}
\begin{document}
\begin{table}[htb]
\begin{tabularx}{\linewidth}{*{3}{>{\centering\arraybackslash}X}}
\begin{tabular}[b]{|l|l|}
\hline
Service & Features \\
\hline
$S_{11}$ & $F_1$ \\
$S_{12}$ & $F_1$ \\
$S_{13}$ & $F_1$ \\
$S_{14}$ & $F_1$ \\
$S_{15}$ & $F_2$ \\
\hline
\end{tabular}
\caption{The first table}
&
\begin{tabular}[b]{|l|l|}
\hline
Service & Features \\
\hline
$S_{21}$ & $F_3$ \\
$S_{22}$ & $F_3$ \\
$S_{23}$ & $F_3$ \\
$S_{24}$ & $F_3$ \\
$S_{25}$ & $F_4$ \\
\hline
\end{tabular}
\caption{The second table}
&
\begin{tabular}[b]{|l|l|}
\hline
Service & Features \\
\hline
$S_{31}$ & $F_5$ \\
$S_{32}$ & $F_5$ \\
$S_{33}$ & $F_5$ \\
\hline
\end{tabular}
\caption{The third table}
\end{tabularx}
\end{table}
or
\begin{table}[htb]
\begin{subtable}[b]{0.3\linewidth}
\begin{tabular}{|l|l|}
\hline
Service & Features \\
\hline
$S_{11}$ & $F_1$ \\
$S_{12}$ & $F_1$ \\
$S_{13}$ & $F_1$ \\
$S_{14}$ & $F_1$ \\
$S_{15}$ & $F_2$ \\
\hline
\end{tabular}
\caption{The first table}
\end{subtable}
\hfill
\begin{subtable}[b]{0.3\linewidth}
\begin{tabular}[b]{|l|l|}
\hline
Service & Features \\
\hline
$S_{21}$ & $F_3$ \\
$S_{22}$ & $F_3$ \\
$S_{23}$ & $F_3$ \\
$S_{24}$ & $F_3$ \\
$S_{25}$ & $F_4$ \\
\hline
\end{tabular}
\caption{The second table}
\end{subtable}
\hfill
\begin{subtable}[b]{0.3\linewidth}
\begin{tabular}[b]{|l|l|}
\hline
Service & Features \\
\hline
$S_{31}$ & $F_5$ \\
$S_{32}$ & $F_5$ \\
$S_{33}$ & $F_5$ \\
\hline
\end{tabular}
\caption{The third table}
\end{subtable}
\caption{99 most frequent hashtags in the data set.}
\end{table}
\end{document}
答案2
借助 minipages 和软件包的帮助capt-of
:
\documentclass{article}
\usepackage{geometry}
\usepackage{capt-of}
\begin{document}
\noindent
\begin{minipage}[t]{0.25\textwidth}
\footnotesize
\begin{tabular}[t]{|l|l|}
\hline
Service & Features \\
\hline
$S_{11}$ & $F_1$ \\
$S_{12}$ & $F_1$ \\
$S_{13}$ & $F_1$ \\
$S_{14}$ & $F_1$ \\
$S_{15}$ & $F_2$ \\
\hline
\end{tabular}
\end{minipage}\hfill
\begin{minipage}[t]{0.25\textwidth}
\begin{tabular}[t]{|l|l|}
\hline
Service & Features \\
\hline
$S_{21}$ & $F_3$ \\
$S_{22}$ & $F_3$ \\
$S_{23}$ & $F_3$ \\
$S_{24}$ & $F_3$ \\
$S_{25}$ & $F_4$ \\
\hline
\end{tabular}
\end{minipage}\hfill
\begin{minipage}[t]{0.25\textwidth}
\begin{tabular}[t]{|l|l|}
\hline
Service & Features \\
\hline
$S_{31}$ & $F_5$ \\
$S_{32}$ & $F_5$ \\
$S_{33}$ & $F_5$ \\
\hline
\end{tabular}
\end{minipage}
\begin{minipage}[t]{0.25\textwidth}
\captionof{table}{Caption of first table}
\end{minipage}\hfill
\begin{minipage}[t]{0.25\textwidth}
\captionof{table}{Caption of second table}
\end{minipage}\hfill
\begin{minipage}[t]{0.25\textwidth}
\captionof{table}{Caption of third table}
\end{minipage}
\end{document}