我是 LaTeX 新手,目前正在撰写硕士论文。我正在尝试使用该包创建两个相互堆叠的子表subcaption
。
以下是代码:
The file was read into a dataframe and pivoted longer, using month, day and hour as indices, the grid points as `column` and the values as the `values` column. This turned a 8760 x 185 dataframe into a 1594320 x 5 dataframe, as shown in Table \ref{tab:ill_preproc}.
\begin{table}[h!]
\caption{Global caption}
\centering
\begin{subtable}[t]{0.5\linewidth}
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
Month & Day & Hour & Point 0 & Point 1 & Point ... & Point 182 \\ [0.5ex]
\hline
01 & 01 & 0.5 & ... & ... & ... & ... \\
01 & 01 & 1.5 & ... & ... & ... & ... \\
01 & 01 & 2.5 & ... & ... & ... & ... \\
01 & 01 & 3.5 & ... & ... & ... & ... \\
... & ... & ... & ... & ... & ... & ... \\
12 & 31 & 23.5 & ... & ... & ... & ... \\
\hline
\end{tabular}
\caption{Before pre-processing}
\label{tab:before_preproc}
\end{subtable}
\begin{subtable}[t]{0.5\linewidth} \centering
\begin{tabular}{|c|c|c|c|c|}
\hline
Month & Day & Hour & Point & Values\\ [0.5ex]
\hline
01 & 01 & 0.5 & 0 & ... \\
01 & 01 & 1.5 & 1 & ... \\
01 & 01 & 2.5 & 2 & ... \\
01 & 01 & 3.5 & 3 & ... \\
... & ... & ... & ... & ... \\
12 & 31 & 23.5 & 182 & ... \\
\hline
\end{tabular}
\caption{After pre-processing}
\label{tab:after_preproc}
\end{subtable}
\label{tab:my_label}
\end{table}
以下是我得到的结果:
现在,对于这个结果,有两点我不喜欢,并且想做出改变,其中有一点是“值得了解的”:
- 我该如何对齐子表,使每个子表的第一列不垂直对齐,而是子表相对于页面的垂直中心对称?为了更清楚起见,我希望第一个子表的“小时”列与第二个子表的“月份”列大致垂直对齐。
- 如何减少表格与上方文本之间的距离?
值得注意的是:有没有办法指定子表格与子标题之间以及子表格之间的垂直距离?
答案1
对于垂直对齐,请参见下面的答案;对于标题,请参见上面的评论
\documentclass{report}
\usepackage{float}
\usepackage{subcaption}
\begin{document}
\hrule % just to illustrate width of textblock
\begin{table}[H]
\begin{subtable}{1\linewidth}
\centering
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
Month & Day & Hour & Point 0 & Point 1 & Point ... & Point 182 \\ [0.5ex]
\hline
01 & 01 & 0.5 & ... & ... & ... & ... \\
01 & 01 & 1.5 & ... & ... & ... & ... \\
01 & 01 & 2.5 & ... & ... & ... & ... \\
01 & 01 & 3.5 & ... & ... & ... & ... \\
... & ... & ... & ... & ... & ... & ... \\
12 & 31 & 23.5 & ... & ... & ... & ... \\
\hline
\end{tabular}
\caption{SUBTBL1}
\vspace{0.5cm}
\begin{tabular}{|c|c|c|c|c|}
\hline
Month & Day & Hour & Point & Values\\ [0.5ex]
\hline
01 & 01 & 0.5 & 0 & ... \\
01 & 01 & 1.5 & 1 & ... \\
01 & 01 & 2.5 & 2 & ... \\
01 & 01 & 3.5 & 3 & ... \\
... & ... & ... & ... & ... \\
12 & 31 & 23.5 & 182 & ... \\
\hline
\end{tabular}
\caption{SUBTBL2}
\end{subtable}%
\caption{Overall table caption}
\end{table}
\end{document}
编辑——表格上方有文字
平均能量损失
\documentclass{report}
\usepackage{float}
\usepackage{subcaption}
\begin{document}
\hrule % just to illustrate width of textblock
The file was read into a dataframe and pivoted longer, using month, day and hour as indices, the grid points as `column` and the values as the `values` column. This turned a 8760 x 185 dataframe into a 1594320 x 5 dataframe, as shown in Table .
\begin{table}[h!]
\begin{subtable}{1\linewidth}
\centering
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
Month & Day & Hour & Point 0 & Point 1 & Point ... & Point 182 \\ [0.5ex]
\hline
01 & 01 & 0.5 & ... & ... & ... & ... \\
01 & 01 & 1.5 & ... & ... & ... & ... \\
01 & 01 & 2.5 & ... & ... & ... & ... \\
01 & 01 & 3.5 & ... & ... & ... & ... \\
... & ... & ... & ... & ... & ... & ... \\
12 & 31 & 23.5 & ... & ... & ... & ... \\
\hline
\end{tabular}
\caption{SUBTBL1}
\vspace{0.5cm}
\begin{tabular}{|c|c|c|c|c|}
\hline
Month & Day & Hour & Point & Values\\ [0.5ex]
\hline
01 & 01 & 0.5 & 0 & ... \\
01 & 01 & 1.5 & 1 & ... \\
01 & 01 & 2.5 & 2 & ... \\
01 & 01 & 3.5 & 3 & ... \\
... & ... & ... & ... & ... \\
12 & 31 & 23.5 & 182 & ... \\
\hline
\end{tabular}
\caption{SUBTBL2}
\end{subtable}%
\caption{Overall table caption}
\end{table}
\end{document}