我使用“booktabs”创建了一个表格,如下所示:
\documentclass[12pt,a4paper]{report}
\renewcommand{\familydefault}{\rmdefault}
\usepackage[top=1in,bottom=1in,left=1.25in,right=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{@{}cr@{}c@{}lSSS@{}}
\toprule
\multicolumn{1}{l}{\textbf{Batch}} &
\multicolumn{3}{c}{\textbf{Ratio}} &
\multicolumn{1}{c}{\textbf{\begin{tabular}[c]{@{}c@{}}Concentration 1\\ (mole/L)\end{tabular}}} &
\multicolumn{1}{c}{\textbf{\begin{tabular}[c]{@{}c@{}}Concentration 2\\ (mole/L)\end{tabular}}} \\
\midrule
1 & 10 & : & 1 & 55.55 & 5.555 \\
2 & 1 & : & 1 & 7.8 & 7.8 \\
3 & 1 & : & 10 & 0.61 & 6.1 \\
4 & 1 & : & 1.43 & 1.134 & 0.795 \\ \bottomrule
\end{tabular}%
\end{table}
\end{document}
上述代码的输出如下:
这很好。现在为了增强上表,我愿意将上表的最后两列转换为以下两列,而不会干扰上表前两列的格式。
我尝试了几种方法,但所有方法都会以某种方式影响前两列的格式。任何关于这个问题的帮助都非常受欢迎,这将对我使表格更具可读性有很大帮助。
答案1
\documentclass[12pt,a4paper]{report}
\renewcommand{\familydefault}{\rmdefault}
\usepackage[top=1in,bottom=1in,left=1.25in,right=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{multirow}
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize\bfseries}
\usepackage{calc}
\newlength{\mycolumnwidth}
\setlength{\mycolumnwidth}{\widthof{\textbf{Concentration (mole/L)}}}
\begin{document}
\begin{table}[h]
\sisetup{table-column-width=0.5\mycolumnwidth}
\centering
\begin{tabular}{@{}cr@{}c@{}lSS[table-format=2.3]S[table-format=1.3]@{}}
\toprule
\multirow{2.5}{*}{\thead{Batch}} &
\multicolumn{3}{c}{\multirow{2.5}{*}{\thead{Ratio}}} &
\multicolumn{2}{c}{\thead{Concentration (mole/L)}} \\
\cmidrule{5-6}
&&&& {\thead{1}} & {\thead{2}}\\
\midrule
1 & 10 & : & 1 & 55.55 & 5.555 \\
2 & 1 & : & 1 & 7.8 & 7.8 \\
3 & 1 & : & 10 & 0.61 & 6.1 \\
4 & 1 & : & 1.43 & 1.134 & 0.795 \\ \bottomrule
\end{tabular}%
\end{table}
\begin{table}[h]
\sisetup{table-column-width=0.5\mycolumnwidth}
\centering
\begin{tabular}{@{}cr@{}c@{}lSS[table-format=2.3]S[table-format=1.3]@{}}
\toprule
\thead{Batch} &
\multicolumn{3}{c}{\thead{Ratio}} &
\multicolumn{2}{c}{\thead{Concentration (mole/L)}} \\
\cmidrule{5-6}
&&&& {\thead{1}} & {\thead{2}}\\
\midrule
1 & 10 & : & 1 & 55.55 & 5.555 \\
2 & 1 & : & 1 & 7.8 & 7.8 \\
3 & 1 & : & 10 & 0.61 & 6.1 \\
4 & 1 & : & 1.43 & 1.134 & 0.795 \\ \bottomrule
\end{tabular}%
\end{table}
\begin{table}[h]
\centering
\begin{tabular}{@{}cr@{}c@{}lSS[table-format=2.3]S[table-format=1.3]@{}}
\toprule
\multirow{3.5}{*}{\thead{Batch}} &
\multicolumn{3}{c}{\multirow{3.5}{*}{\thead{Ratio}}} &
\multicolumn{2}{c}{\thead{Concentration \\ (mole/L)}} \\
\cmidrule{5-6}
&&&& {\thead{1}} & {\thead{2}}\\
\midrule
1 & 10 & : & 1 & 55.55 & 5.555 \\
2 & 1 & : & 1 & 7.8 & 7.8 \\
3 & 1 & : & 10 & 0.61 & 6.1 \\
4 & 1 & : & 1.43 & 1.134 & 0.795 \\ \bottomrule
\end{tabular}%
\end{table}
\begin{table}[h]
\centering
\begin{tabular}{@{}cr@{}c@{}lSS[table-format=2.3]S[table-format=1.3]@{}}
\toprule
\thead{Batch} &
\multicolumn{3}{c}{\thead{Ratio}} &
\multicolumn{2}{c}{\thead{Concentration \\ (mole/L)}} \\
\cmidrule{5-6}
&&&& {\thead{1}} & {\thead{2}}\\
\midrule
1 & 10 & : & 1 & 55.55 & 5.555 \\
2 & 1 & : & 1 & 7.8 & 7.8 \\
3 & 1 & : & 10 & 0.61 & 6.1 \\
4 & 1 & : & 1.43 & 1.134 & 0.795 \\ \bottomrule
\end{tabular}%
\end{table}
\end{document}
答案2
我会 (a) 在环境中只使用 4 列tabular
,并且 (b) 加载dcolumn
包并创建一个新的列类型,使其内容与:
(冒号)字符对齐。我还质疑是否需要喊通过使用大胆的在标题行中。设计良好的表格可以传达其信息,而无需借助视觉上的喊叫。
\documentclass[12pt,a4paper]{report}
%\renewcommand{\familydefault}{\rmdefault} %% that's the default
\usepackage[vmargin=1in,hmargin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{booktabs,siunitx,dcolumn}
\newcolumntype{d}[1]{D{:}{:}{#1}}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{@{} c d{2.3} S[table-format=2.3] S[table-format=1.3] @{}}
\toprule
Batch & \multicolumn{1}{c}{Ratio} & \multicolumn{2}{c@{}}{Concentration} \\
& & \multicolumn{2}{c@{}}{(mole/L)}\\
\cmidrule(l){3-4}
& & {1} & {2} \\
\midrule
1 & 10:1 & 55.55 & 5.555 \\
2 & 1:1 & 7.8 & 7.8 \\
3 & 1:10 & 0.61 & 6.1 \\
4 & 1:1.43 & 1.134 & 0.795 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}