0

I have the following code which creates three tables side by side. How do I add a different caption to each of them separately?

\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}
kauray
  • 259
  • you can find your answer here: https://tex.stackexchange.com/questions/15282/tabular-title-above-and-caption-below – Amin Heydari Alashti Apr 30 '19 at 06:19
  • @epcpu The formatting gets messed up using this – kauray Apr 30 '19 at 06:23
  • Related: https://tex.stackexchange.com/q/6850/134144 – leandriis Apr 30 '19 at 07:27
  • Your question seems badly named: what you are asking for is caption for individual tabular inside table. – Jhor Apr 30 '19 at 08:19
  • The answers prposed using mini pages do work. Nevertheless it seems over complicated. A more general and easy solution would be to load both the caption and subcaption packages (the latter loads the former) and use for each tabular the subtabke evironmemt (as provided by subcaption) ant the \captionof command in each subtable.Have a look at https://tex.stackexchange.com/q/383254/33514. – Jhor Apr 30 '19 at 08:26
  • The main problem is that \caption will use the entire width of the page unless restrained (by a minipage). – John Kormylo Apr 30 '19 at 13:42

2 Answers2

3

it is not clear (to me), how you like to have captions to your tables, so below are two possible examples:

enter image description here

in the first is used tabularx for spreading tables in line, in the second are used subtable environments from subcaption package:

\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}
Zarko
  • 296,517
1

With minipages and the help of the capt-of package:

\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}
leandriis
  • 62,593