我有两个表格,我想把它们放在同一行,以两列模式显示。但是当我使用下面的代码时,它们都没有对齐,表格无法完全显示。我该怎么办?谢谢!
\begin{table*}[t]
\begin{minipage}[t]{0.4\linewidth}
\begin{center}
\begin{tabular}[t]{|c|c|c|}
\hline
data load nums & W & L \\ \hline
p1 (k/ms) & $3.000*10^8$ &$3.000*10^8$ \\ \hline
p2 (k/ms) &$3.000*10^8$ & $3.000*10^8$ \\ \hline
p3 (k/ms) & $3.000*10^8$ & $3.000*10^8$ \\ \hline
Total (k/ms) & $3.000*10^8$ &$3.000*10^8$ \\ \hline
\end{tabular}
\caption{Process.}
\label{table:formatting}
\end{center}
\end{minipage}\hfill
\begin{minipage}[t]{0.6\linewidth}
\begin{center}
\begin{tabular}[t]{|c|c|c|c|c|c|c|}
\hline
& \textbf{\begin{tabular}[c]{@{}c@{}}p1 TB\\ Alg.1\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}sender \& pcc \\ Alg.1\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}sender only \\ Alg.1\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}p2 TB\\ Alg.2\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}sender \& pcc \\ Alg.2\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}sender only \\ Alg.2\end{tabular}} \\ \hline
\textbf{L1D} & 0.041\% & 0.111\% & 0.111\% & 0.111\% & 0.111\% & 0.111\% \\ \hline
\textbf{L2} & 3.586\% & 0.111\% & 0.111\% & 0.111\% & 0.111\% & 0.111\% \\ \hline
\textbf{LLC} & 34.379\% & 0.111\% & 0.111\% & 0.111\% & 0.111\% & 0.111\% \\ \hline
\end{tabular}
\caption{ Algorithm 1.}
\label{table:formatting}
\end{center}
\end{minipage}%
\end{table*}
答案1
floatrow
使用和的可能性makecell
(并且caption
在标题和表格之间留出适当的间距):
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{caption}
\usepackage{makecell}
\renewcommand{\theadfont}{\small\bfseries}
\usepackage[valign=t,heightadjust=all]{floatrow}
\begin{document}
\begin{table}
\centering\setlength{\tabcolsep}{3pt}
\begin{floatrow}[2]
\ttabbox[\FBwidth]{\caption{Process.}%
\label{table:formatting}
}{ \begin{tabular}[t]{|c|c|c|}
\hline
\makecell{data load\\ nums} & W & L \\ \hline
\makecell{p1\\ (k/ms)} & $3.000*10^8$ &$3.000*10^8$ \\ \hline
\makecell{p2\\ (k/ms)} &$3.000*10^8$ & $3.000*10^8$ \\ \hline
\makecell{p3 \\(k/ms)} & $3.000*10^8$ & $3.000*10^8$ \\ \hline
\makecell{Total \\(k/ms)} & $3.000*10^8$ &$3.000*10^8$ \\ \hline
\end{tabular}}
\ttabbox[\FBwidth]{\caption{ Algorithm 1.}
\label{table:formatting1}}%
{\begin{tabular}[t]{|c|c|c|c|c|c|c|}
\hline
& \thead{p1 TB\\ Alg.1 \\(\%)} & \thead{sender\\ \& pcc \\ Alg.1 \\(\%)} & \thead{sender\\ only \\ Alg.1\\ (\%)} & \thead{p2 TB\\ Alg.2\\ (\%)} & \thead{sender \\\& pcc \\ Alg.2\\ (\%)} & \thead{sender\\ only \\ Alg.2\\ (\%)} \\ \hline
\thead{L1D} & 0.041 & 0.111 & 0.111 & 0.111 & 0.111 & 0.111 \\ \hline
\thead{L2} & 3.586 & 0.111 & 0.111 & 0.111 & 0.111 & 0.111 \\ \hline
\thead{LLC} & 34.379 & 0.111 & 0.111 & 0.111 & 0.111 & 0.111 \\ \hline
\end{tabular}}
\end{floatrow}
\end{table}
\end{document}
答案2
由于 documentclass、margins 和 font size 都是未知的,因此以下三个建议是基于假设的:
\documentclass[10pt,twocolumn]{article}
\usepackage{makecell}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{lipsum} % Just for dummy text. Do not use in actual document.
\begin{document}
\lipsum
\begin{table*}
\centering
\begin{tabular}[t]{|c|c|c|c|c|c|c|}
\hline
& \textbf{\begin{tabular}[c]{@{}c@{}}p1 TB\\ Alg.1\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}sender \& pcc \\ Alg.1\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}sender only \\ Alg.1\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}p2 TB\\ Alg.2\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}sender \& pcc \\ Alg.2\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}sender only \\ Alg.2\end{tabular}} \\ \hline
\textbf{L1D} & 0.041\% & 0.111\% & 0.111\% & 0.111\% & 0.111\% & 0.111\% \\ \hline
\textbf{L2} & 3.586\% & 0.111\% & 0.111\% & 0.111\% & 0.111\% & 0.111\% \\ \hline
\textbf{LLC} & 34.379\% & 0.111\% & 0.111\% & 0.111\% & 0.111\% & 0.111\% \\ \hline
\end{tabular}
\caption{ Algorithm 1.}
\label{table:formatting}
\end{table*}
\begin{table}
\centering
\begin{tabular}[t]{|c|c|c|}
\hline
data load nums & W & L \\ \hline
p1 (k/ms) & $3.000*10^8$ &$3.000*10^8$ \\ \hline
p2 (k/ms) &$3.000*10^8$ & $3.000*10^8$ \\ \hline
p3 (k/ms) & $3.000*10^8$ & $3.000*10^8$ \\ \hline
Total (k/ms) & $3.000*10^8$ &$3.000*10^8$ \\ \hline
\end{tabular}
\caption{Process.}
\label{table:formatting}
\end{table}
\lipsum
\begin{table*}[t]
\begin{minipage}[t]{0.35\linewidth}
\centering
\caption{Process.}
\label{table:formatting}
\begin{tabular}[t]{c*{2}{S[table-format=1.2]}}
\toprule
\thead{data load\\ nums\\ (\si{k\per\milli\second})} & {\thead{W $\cdot 10^8$}} & {\thead{L $\cdot 10^8$}} \\ \midrule
p1 & 3.00 & 3.00 \\
p2 & 3.00 & 3.00 \\
p3 & 3.00 & 3.00 \\
Total & 3.00 & 3.00 \\ \bottomrule
\end{tabular}
\end{minipage}\hfill
\begin{minipage}[t]{0.65\linewidth}
\centering
\caption{ Algorithm 1.}
\label{table:formatting}
\begin{tabular}[t]{lS[table-format=2.3]*{5}{S[table-format=1.3]}}
\toprule
& \multicolumn{3}{c}{Alg.1} & \multicolumn{3}{c}{Alg.2}\\
\cmidrule(r){2-4} \cmidrule(l){5-7}
& {\thead{p1 TB\\ (\%)}}
& {\thead{sender \\ \& pcc (\%)}}
& {\thead{sender \\ only (\%)}}
& {\thead{p1 TB\\ (\%)}}
& {\thead{sender \\ \& pcc (\%)}}
& {\thead{sender \\ only (\%)}}\\
\midrule
L1D & 0.041 & 0.111 & 0.111 & 0.111 & 0.111 & 0.111 \\
L2 & 3.586 & 0.111 & 0.111 & 0.111 & 0.111 & 0.111 \\
LLC & 34.379 & 0.111 & 0.111 & 0.111 & 0.111 & 0.111 \\
\bottomrule
\end{tabular}
\end{minipage}%
\end{table*}
\lipsum
\lipsum
\begin{table*}
\centering
\caption{ Algorithm 1.}
\label{table:formatting}
\begin{tabular}[t]{lS[table-format=2.3]*{5}{S[table-format=1.3]}}
\toprule
& \multicolumn{3}{c}{Alg.1} & \multicolumn{3}{c}{Alg.2}\\
\cmidrule(r){2-4} \cmidrule(l){5-7}
& {\thead{p1 TB (\%)}}
& {\thead{sender \& pcc (\%)}}
& {\thead{sender only (\%)}}
& {\thead{p1 TB (\%)}}
& {\thead{sender \& pcc (\%)}}
& {\thead{sender only (\%)}}\\
\midrule
L1D & 0.041 & 0.111 & 0.111 & 0.111 & 0.111 & 0.111 \\
L2 & 3.586 & 0.111 & 0.111 & 0.111 & 0.111 & 0.111 \\
LLC & 34.379 & 0.111 & 0.111 & 0.111 & 0.111 & 0.111 \\
\bottomrule
\end{tabular}
\end{table*}
\begin{table}
\centering
\caption{Process.}
\label{table:formatting}
\begin{tabular}[t]{c*{2}{S[table-format=1.2]}}
\toprule
\thead{data load nums\\ (\si{k\per\milli\second})} & {\thead{W $\cdot 10^8$}} & {\thead{L $\cdot 10^8$}} \\ \midrule
p1 & 3.00 & 3.00 \\
p2 & 3.00 & 3.00 \\
p3 & 3.00 & 3.00 \\
Total & 3.00 & 3.00 \\ \bottomrule
\end{tabular}
\end{table}
\lipsum
\end{document}