我已经创建了一个与页面宽度相同的表格,但是当尝试将文本置于合并单元格顶行的中心时,文本并没有相对于单元格的整个长度居中。
\documentclass[a4paper,twoside,12pt]{article}
\usepackage{graphicx}
\usepackage{array}
\newcolumntype{N}{>{\centering\arraybackslash}m{.5in}}
\newcolumntype{G}{>{\centering\arraybackslash}m{2in}}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{N|N|N|N|N|N|N|N|N|}
\cline{2-9}
\multicolumn{1}{N|}{\textbf{}} & \multicolumn{4}{G|}{\textbf{Emissions (Pre Catalytic Converter)}} & \multicolumn{4}{G|}{\textbf{Emissions (Post Catalytic Converter)}} \\ \hline
\multicolumn{1}{|N|}{\textbf{Dyno Load (\%)}} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} \\ \hline
\multicolumn{1}{|N|}{10} & 0.77 & 23 & 523 & 14.0 & 0.09 & 18 & 130 & 13.8 \\ \hline
\multicolumn{1}{|c|}{30} & 0.78 & 13 & 555 & 14.2 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{70} & 0.70 & 14 & 580 & 14.4 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{90} & 0.74 & 15 & 630 & 14.5 & 0.70 & 15 & 618 & 14.6 \\ \hline
\multicolumn{1}{|c|}{Neutral} & 0.06 & 7 & 21 & 15.6 & 0.06 & 5 & 27 & 15.7 \\ \hline
\end{tabular}
\caption{\textbf{}}
\label{2000Emissions}
\end{table}
\end{document}
答案1
在这种情况下,只需使用两行作为标题就更简单了:
笔记:
- 您不需要使用
\multicolumn{1}{N|}{\textbf{}}
,只需将其留空即可。
不过,我认为如果您消除垂直规则并使用包,您的表格会更好booktabs
:
代码:
\documentclass[a4paper,twoside,12pt]{article}
\usepackage{graphicx}
\usepackage{array}
\newcolumntype{N}{>{\centering\arraybackslash}m{.5in}}
\newcolumntype{G}{>{\centering\arraybackslash}m{2in}}
\newcommand*{\boldsymbol}[1]{#1}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{N|N|N|N|N|N|N|N|N|}
\cline{2-9}
& \multicolumn{4}{c|}{\textbf{Emissions (Pre}} & \multicolumn{4}{c|}{\textbf{Emissions (Post}} \\
& \multicolumn{4}{c|}{\textbf{Catalytic Converter)}} & \multicolumn{4}{c|}{\textbf{Catalytic Converter)}} \\ \hline
\multicolumn{1}{|N|}{\textbf{Dyno Load (\%)}} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} \\ \hline
\multicolumn{1}{|N|}{10} & 0.77 & 23 & 523 & 14.0 & 0.09 & 18 & 130 & 13.8 \\ \hline
\multicolumn{1}{|c|}{30} & 0.78 & 13 & 555 & 14.2 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{70} & 0.70 & 14 & 580 & 14.4 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{90} & 0.74 & 15 & 630 & 14.5 & 0.70 & 15 & 618 & 14.6 \\ \hline
\multicolumn{1}{|c|}{Neutral} & 0.06 & 7 & 21 & 15.6 & 0.06 & 5 & 27 & 15.7 \\ \hline
\end{tabular}
\caption{\textbf{}}
\label{2000Emissions}
\end{table}
\end{document}
代码:booktabs
:
\documentclass[a4paper,twoside,12pt]{article}
\usepackage{graphicx}
\usepackage{array}
\usepackage{booktabs}
\newcolumntype{N}{>{\centering\arraybackslash}m{.5in}}
\newcolumntype{G}{>{\centering\arraybackslash}m{2in}}
\newcommand*{\boldsymbol}[1]{#1}
\begin{document}
\begin{table}[H]
\centering
\noindent
\begin{tabular}{N N N N N N N N N }\toprule
\multicolumn{1}{N }{\textbf{}} & \multicolumn{4}{c }{\textbf{Emissions (Pre}} & \multicolumn{4}{c }{\textbf{Emissions (Post}} \\
\multicolumn{1}{c }{\textbf{}} & \multicolumn{4}{c }{\textbf{Catalytic Converter)}} & \multicolumn{4}{c }{\textbf{Catalytic Converter)}} \\
\cmidrule(lr){2-5}
\cmidrule(ll){6-9}
\multicolumn{1}{ N }{\textbf{Dyno Load (\%)}} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} \\
\cmidrule(lr){1-1}
\cmidrule(lr){2-5}
\cmidrule(ll){6-9}
\multicolumn{1}{ N }{10} & 0.77 & 23 & 523 & 14.0 & 0.09 & 18 & 130 & 13.8 \\
\multicolumn{1}{ c }{30} & 0.78 & 13 & 555 & 14.2 & - & - & - & - \\
\multicolumn{1}{ c }{70} & 0.70 & 14 & 580 & 14.4 & - & - & - & - \\
\multicolumn{1}{ c }{90} & 0.74 & 15 & 630 & 14.5 & 0.70 & 15 & 618 & 14.6 \\
\multicolumn{1}{ c }{Neutral} & 0.06 & 7 & 21 & 15.6 & 0.06 & 5 & 27 & 15.7 \\
\bottomrule
\end{tabular}
\caption{\textbf{}}
\label{2000Emissions}
\end{table}
\end{document}
答案2
我使用了该代码并对其进行了少许“改进”。
有 4 个单元格需要合并,这意味着,这不仅仅是“N”类型的单元格内容宽度的 4 倍。
|南斯拉夫|南斯拉夫|南斯拉夫|南斯拉夫
其中s
表示\tabcolsep
空格(默认为6pt
和c
单元格内容,“固定”为0.5in
\documentclass[a4paper,twoside,12pt]{article}
\usepackage{amsbsy}%
\usepackage{graphicx}
\usepackage{array}
\usepackage{calc}
\newcolumntype{N}{>{\centering\arraybackslash}m{.5in}}
\newcolumntype{G}{>{\bfseries\centering\arraybackslash}m{2in+6\tabcolsep}}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{*{9}{N|}}
\cline{2-9}
\multicolumn{1}{N|}{} & \multicolumn{4}{G|}{Emissions (Pre Catalytic Converter)} & \multicolumn{4}{G|}{Emissions (Post Catalytic Converter)} \tabularnewline \hline
\multicolumn{1}{|N|}{\textbf{Dyno Load (\%)}} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} \\ \hline
\multicolumn{1}{|N|}{10} & 0.77 & 23 & 523 & 14.0 & 0.09 & 18 & 130 & 13.8 \\ \hline
\multicolumn{1}{|c|}{30} & 0.78 & 13 & 555 & 14.2 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{70} & 0.70 & 14 & 580 & 14.4 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{90} & 0.74 & 15 & 630 & 14.5 & 0.70 & 15 & 618 & 14.6 \\ \hline
\multicolumn{1}{|c|}{Neutral} & 0.06 & 7 & 21 & 15.6 & 0.06 & 5 & 27 & 15.7 \\ \hline
\end{tabular}
\caption{\textbf{}}
\label{2000Emissions}
\end{table}
\end{document}
答案3
数字表通常使用 排版效果更好siunitx
。我更喜欢 提供的规则booktabs
,但它们不是必需的:如果您希望获得印刷上有争议的结果,则可以使用垂直规则。;-)
\documentclass[draft,a4paper,twoside,12pt]{article}
\usepackage{siunitx,booktabs}
\newcommand{\splitcell}[1]{%
\begin{tabular}{@{}c@{}}\strut#1\strut\end{tabular}%
}
\begin{document}
\begin{table}
\centering
\begin{tabular}{
S[table-format=2.0]
S[table-format=1.2]
S[table-format=2.0]
S[table-format=3.0]
S[table-format=2.1]
S[table-format=1.2]
S[table-format=2.0]
S[table-format=3.0]
S[table-format=2.1]
}
\toprule
& \multicolumn{8}{c}{\bfseries Emissions} \\
\cmidrule(lr){2-9}
& \multicolumn{4}{c}{\bfseries Pre Catalytic Converter}
& \multicolumn{4}{c}{\bfseries Post Catalytic Converter} \\
\cmidrule(lr){2-5}\cmidrule(lr){6-9}
{\bfseries\splitcell{Dyno\\ Load\\ (\%)}}
& {\bfseries\splitcell{CO \\ (\%)}}
& {\bfseries\splitcell{HC \\ (ppm)}}
& {\bfseries\splitcell{Nox \\ (ppm)}}
& {\bfseries\boldmath\splitcell{CO$_2$ \\ (\%)}}
& {\bfseries\splitcell{CO \\ (\%)}}
& {\bfseries\splitcell{HC \\ (ppm)}}
& {\bfseries\splitcell{Nox \\ (ppm)}}
& {\bfseries\boldmath\splitcell{CO$_2$ \\ (\%)}} \\
\midrule
10 & 0.77 & 23 & 523 & 14.0 & 0.09 & 18 & 130 & 13.8 \\
30 & 0.78 & 13 & 555 & 14.2 & {--} & {--} & {--} & {--} \\
70 & 0.70 & 14 & 580 & 14.4 & {--} & {--} & {--} & {--} \\
90 & 0.74 & 15 & 630 & 14.5 & 0.70 & 15 & 618 & 14.6 \\
{Neutral} & 0.06 & 7 & 21 & 15.6 & 0.06 & 5 & 27 & 15.7 \\
\bottomrule
\end{tabular}
\caption{Some caption}
\label{2000Emissions}
\end{table}
\end{document}
答案4
N
虽然已指定中的每一列的宽度为0.5in
,但四列N
的宽度并不2in
宽。每列之间的列间距为\tabcolsep
。而且,当您使用垂直规则时,它实际上是2\tabcolsep
。因此,您可以使用 的宽度2in+6\tabcolsep
作为 列的空间G
:
\documentclass{article}
\usepackage{graphicx,array,bm,booktabs}
\newcolumntype{N}{>{\centering\arraybackslash}m{.5in}}
\newcolumntype{G}{>{\centering\arraybackslash}m{\dimexpr2in+6\tabcolsep}}
\begin{document}
\begin{tabular}{N*{8}{|N|}}
\cline{2-9}
\multicolumn{1}{N|}{} & \multicolumn{4}{G|}{\bfseries Emissions (Pre Catalytic Converter)} & \multicolumn{4}{G|}{\bfseries Emissions (Post Catalytic Converter)} \\ \hline
\multicolumn{1}{|N|}{\textbf{Dyno Load (\%)}} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} \\ \hline
\multicolumn{1}{|N|}{10} & 0.77 & 23 & 523 & 14.0 & 0.09 & 18 & 130 & 13.8 \\ \hline
\multicolumn{1}{|c|}{30} & 0.78 & 13 & 555 & 14.2 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{70} & 0.70 & 14 & 580 & 14.4 & - & - & - & - \\ \hline
\multicolumn{1}{|c|}{90} & 0.74 & 15 & 630 & 14.5 & 0.70 & 15 & 618 & 14.6 \\ \hline
\multicolumn{1}{|c|}{Neutral} & 0.06 & 7 & 21 & 15.6 & 0.06 & 5 & 27 & 15.7 \\ \hline
\end{tabular}
\bigskip
\begin{tabular}{c*{8}{N}}
\toprule
& \multicolumn{4}{G}{\bfseries Emissions (Pre Catalytic Converter)} & \multicolumn{4}{G}{\bfseries Emissions (Post Catalytic Converter)} \\
\cmidrule(lr){2-5}\cmidrule(lr){6-9}
\multicolumn{1}{N}{\textbf{Dyno Load (\%)}} & \textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} &
\textbf{CO (\%)} & \textbf{HC (ppm)} & \textbf{Nox (ppm)} & \textbf{$\boldsymbol{\mathrm{CO_2}}$ (\%)} \\
\midrule
10 & 0.77 & 23 & 523 & 14.0 & 0.09 & 18 & 130 & 13.8 \\
30 & 0.78 & 13 & 555 & 14.2 & -- & -- & -- & -- \\
70 & 0.70 & 14 & 580 & 14.4 & -- & -- & -- & -- \\
90 & 0.74 & 15 & 630 & 14.5 & 0.70 & 15 & 618 & 14.6 \\
Neutral & 0.06 & 7 & 21 & 15.6 & 0.06 & 5 & 27 & 15.7 \\
\bottomrule
\end{tabular}
\end{document}
我会用booktabs
尽管...