
我想要一張如下圖的表格。
\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}
但是,我無法取得具有整個空白行的表,例如冷緩存,寫在其中心。有什麼辦法可以做到這一點嗎?
我還想要表格下方的標題。
答案1
在下面的程式碼中,我提供了兩種重現您想要的表的方法。第一個表旨在按照您的要求生產產品。你走在正確的軌道上\multicolumn
。請注意,我已經設定了預設的單元格對齊方式,r
而不是l
,因為看起來大多數單元格在您發布的圖像中都是右對齊的。對於那些左對齊的(IE,第一列中的那些內容),我使用了一個\multicolumn{1}{l}{...}
命令來更改這些特定單元格的對齊方式。
最後,我強烈建議不要按照您要求的方式建立表格。我特別建議閱讀booktabs
文件(特別是第 2 節)有關排版表格的良好排版實踐的一些建議。
\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}
答案2
我將您的(非工作範例)擴展到 MWE,其中我考慮並添加了 Johannes_B 的建議評論。對於桌子的設計我同意他的觀點。可能的 MWE 是:
\documentclass{article}
\begin{document}
\begin{table}\centering
\begin{tabular}{*{7}{|l}|}
\hline
& \multicolumn{3}{c|}{A}
&\multicolumn{3}{c|}{B} \\
\hline
1 & a & b & c & d & e & f \\
\hline
\multicolumn{7}{|c|}{cold cashes} \\
\hline
2 & g & h & i & j & k & l \\
\hline
\end{tabular}
\caption{My very important table}
\end{table}
\end{document}
我希望上面的例子對你有幫助。
答案3
另一種嘗試,接近您展示的圖像。
\documentclass[]{article}
\usepackage[papersize={18cm,8cm}]{geometry} % change this line in actual case.
\usepackage{multirow}
\begin{document}
\begin{table}\centering
\begin{tabular}{*{8}{|c}|}
\hline
& Q1 & Q2 & Q3 & Q4 & Q5 & Q6 & \multirow{2}{*}{Geom. Mean}\\ \cline{1-7}
\#Results &10 &10&0&8&2528&4.39997& \\ \hline
\multicolumn{8}{|c|}{Cold cashes} \\ \hline
RDF-3X & &&&&&& \\ \hline
MonetDB & &&&&&& \\ \hline
TripleBit & &&&&&& \\ \hline
\multicolumn{8}{|c|}{Warm cashes} \\ \hline
RDF-3X & &&&&&& \\ \hline
MonetDB & &&&&&& \\ \hline
TripleBit & 0.0002 &0.0002&7.5977&0.0009&27.2772&36.5613& 0.0805 \\ \hline
\end{tabular}
\caption{LUBMI 1 Billion (time in seconds)}
\end{table}
\end{document}