[Tex/LaTex] Latex: obtain an empty row with central alignment

tables

I would like to have a table that looks like the image below.

\documentclass{article}
\begin{document}
    \begin{table*}
        \begin{tabular}{|l|l|l|l|l|l|l|} \hline 
            &\multicolumn{3}{c|}{A} &\multicolumn{3}{c|}{B} \\ \cline{2-7} 
          1 & a & b & c & d & e & f \\ \hline
          2 & g & h & i & j & k & l \\ \hline 
        \end{tabular}
    \end{table*}
\end{document}

However, I cannot obtain the table with an entire empty row, like the cold cache, written in its center. Is there some way to do so?

enter image description here

I also want the caption below the table.

Best Answer

In the following code, I've provided two ways of reproducing the table that you're after. The first table aims to produce things as you requested. You were on the right track with \multicolumn. Note that I've made the default cell alignment r rather than l, as it looks as if most of the cells are right-aligned in the image that you've posted. For those that are left-aligned (i.e., those things in the first column), I've used a \multicolumn{1}{l}{...} command to change the alignment of these particular cells.

Finally, I would strongly recommend against creating a table like the way that you have requested. In particular, I would recommend reading the booktabs documentation (particularly section 2) for some recommendations about good typographical practices for typesetting tables.

\documentclass{article}

\usepackage{booktabs} % used for prettier tables
\usepackage[justification=centering]{caption} % needed to center caption

\begin{document}

Table~\ref{fig:replication-as-requested} replicates the image as you've requested, but Table~\ref{fig:replication-as-recommended} replicates the image as I would recommend, based on considerations from the \verb|booktabs| documentation.

\begin{table}[htbp]
\centering
\caption{LUBM 1 Billion (time in seconds)}\label{fig:replication-as-requested}
\begin{tabular}{|r|r|r|r|r|r|r|r|}
    \hline
    & Q1 & Q2 & Q3 & Q4 & Q5 & Q6 & Geom.~Mean \\ \hline
    \multicolumn{8}{|c|}{Cold caches} \\ \hline
    \multicolumn{1}{|l|}{RDF-3X} & a & b & c & d & e & f & g  \\ \hline
    \multicolumn{1}{|l|}{MonetDB} & a & b & c & d & e & f & g \\ \hline
    \multicolumn{1}{|l|}{TripleBit} & a & b & c & d & e & f & g \\ \hline
    \multicolumn{8}{|c|}{Warm caches} \\ \hline
    \multicolumn{1}{|l|}{RDF-3X} & a & b & c & d & e & f & g  \\ \hline
    \multicolumn{1}{|l|}{MonetDB} & a & b & c & d & e & f & g \\ \hline
    \multicolumn{1}{|l|}{TripleBit} & a & b & c & d & e & f & g \\ \hline
\end{tabular}
\end{table}

\begin{table}[htbp]
\centering
\caption{LUBM 1 Billion (time in seconds)}\label{fig:replication-as-recommended}
\begin{tabular}{rrrrrrrr}
    \toprule
    & Q1 & Q2 & Q3 & Q4 & Q5 & Q6 & Geom.~Mean \\ \midrule
    \multicolumn{8}{c}{Cold caches} \\ \midrule
    \multicolumn{1}{l}{RDF-3X} & a & b & c & d & e & f & g  \\
    \multicolumn{1}{l}{MonetDB} & a & b & c & d & e & f & g \\
    \multicolumn{1}{l}{TripleBit} & a & b & c & d & e & f & g \\ \midrule
    \multicolumn{8}{c}{Warm caches} \\ \midrule
    \multicolumn{1}{l}{RDF-3X} & a & b & c & d & e & f & g  \\
    \multicolumn{1}{l}{MonetDB} & a & b & c & d & e & f & g \\
    \multicolumn{1}{l}{TripleBit} & a & b & c & d & e & f & g \\ \bottomrule
\end{tabular}
\end{table}

\end{document}

enter image description here