表格中文本对齐问题

表格中文本对齐问题

我在使用表格时遇到了问题。

似乎我无法正确对齐表格。第二行和第三行之间的文本应该对齐;而且文本非常靠近顶部栏。有没有什么简单的方法可以解决这个问题?

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}

 \begin{document}


 \begin{table*}[ht]\centering
 \begin{tabular}{  l  l  l  l  l  l  l  l  } \hline
 \ & \ & \ Yellow conidia & \  & \  & \ & Black conidia  \  & \  \\ \hline
 \ & Yield  & Yield & OD Reference \ & \ & Yield  & Yield & OD Reference  \  \\
 Run & (ng/uL) &  ($\mu$g/g of conidia) & (260/280) & Run & (ng/uL) &  ($\mu$g/g of conidia) & (260/280) \\ \hline
 1 & 685 & 1370 & 2.04 & 1 & 377.5 & 754.9 & 1.98 \\ 
 2 & 186.7 & 373.4 & 1.71 & 2 & 122.6 & 245.2 & 1.6 \\ 
 3 & 314.1 & 628.2 & 1.81 & 3 & 387.2 & 774.4 & 2.04 \\ 
 4 & 209.1 & 418.2 & 1.84 & 4 & 291.3 & 582.7 & 1.92 \\ 
 5 & 724.3 & 1448.5 & 1.99 & 5 & 615.5 & 1231 & 1.99 \\ 
 6 & 582.7 & 1165.3 & 1.74 & 6 & 337.4 & 674.9 & 2.09 \\ 
 7 & 334.4 & 668.7 & 2.00 & 7 & 282 & 564 & 2.04 \\ 
 8 & 126 & 252 & 2.13 & 8 & 92.8 & 185.6 & 1.99 \\ 
 9 & 647.1 & 1294.2 & 1.95 & 9 & 507.6 & 1015.2 & 1.99 \\ 
10 & 964.4 & 1928.8 & 2.06 & 10 & 508 & 1016 & 1.87 \\
11 & 1033.9 & 2067.8 & 1.92 & 11 & 760.9 & 1521.8 & 1.92 \\ 
12 & 439 & 877.9 & 1.88 & 12 & 368.6 & 737.1 & 1.88 \\ 
13 & 1242.7 & 2485.4 & 1.88 & 13 & 911.2 & 1822.4 & 1.93 \\ 
14 & 1113 & 2226 & 1.82 & 14 & 283.7 & 567.4 & 1.56 \\ 
15 & 1081.7 & 2163.4 & 1.93 & 15 & 575.9 & 1151.8 & 1.92 \\ 
16 & 274.3 & 548.6 & 1.87 & 16 & 151.3 & 302.6 & 1.79 \\ \hline
\end{tabular}
\end{table*}

\end{document}

答案1

在此处输入图片描述

仍然有点过满但是......

\documentclass[fleqn,10pt]{article}
\usepackage[utf8]{inputenc}

\usepackage{dcolumn,booktabs}
\begin{document}

  \begin{table}\centering
  \begin{tabular}{   *{2}{D..{2.0} D..{4.1} D..{4.1} D..{1.2}}}
\toprule
&
\multicolumn{3}{c}{Yellow conidia}&
\multicolumn{3}{c}{Black conidia} \\
\midrule
\multicolumn{1}{c}{Run} &
\multicolumn{1}{p{1.3cm}}{\centering Yield\\ (ng/uL)}&
\multicolumn{1}{p{1.3cm}}{\centering Yield\\  ($\mu$g/g of conidia)}&
\multicolumn{1}{p{1.3cm}}{\centering OD Reference  \\ (260/280)}&
\multicolumn{1}{c}{Run} &
\multicolumn{1}{p{1.3cm}}{\centering Yield\\ (ng/uL)}&
\multicolumn{1}{p{1.3cm}}{\centering Yield\\  ($\mu$g/g of conidia)}&
\multicolumn{1}{p{1.3cm}}{\centering OD Reference  \\ (260/280)}\\
\midrule
  1 & 685 & 1370 & 2.04 & 1 & 377.5 & 754.9 & 1.98 \\
  2 & 186.7 & 373.4 & 1.71 & 2 & 122.6 & 245.2 & 1.6 \\
  3 & 314.1 & 628.2 & 1.81 & 3 & 387.2 & 774.4 & 2.04 \\
  4 & 209.1 & 418.2 & 1.84 & 4 & 291.3 & 582.7 & 1.92 \\
  5 & 724.3 & 1448.5 & 1.99 & 5 & 615.5 & 1231 & 1.99 \\
  6 & 582.7 & 1165.3 & 1.74 & 6 & 337.4 & 674.9 & 2.09 \\
  7 & 334.4 & 668.7 & 2.00 & 7 & 282 & 564 & 2.04 \\
  8 & 126 & 252 & 2.13 & 8 & 92.8 & 185.6 & 1.99 \\
  9 & 647.1 & 1294.2 & 1.95 & 9 & 507.6 & 1015.2 & 1.99 \\
  10 & 964.4 & 1928.8 & 2.06 & 10 & 508 & 1016 & 1.87 \\\\
  11 & 1033.9 & 2067.8 & 1.92 & 11 & 760.9 & 1521.8 & 1.92 \\
  12 & 439 & 877.9 & 1.88 & 12 & 368.6 & 737.1 & 1.88 \\
  13 & 1242.7 & 2485.4 & 1.88 & 13 & 911.2 & 1822.4 & 1.93 \\
  14 & 1113 & 2226 & 1.82 & 14 & 283.7 & 567.4 & 1.56 \\
  15 & 1081.7 & 2163.4 & 1.93 & 15 & 575.9 & 1151.8 & 1.92 \\
  16 & 274.3 & 548.6 & 1.87 & 16 & 151.3 & 302.6 & 1.79 \\
\bottomrule
  \end{tabular}
  \end{table}

\end{document}

答案2

这里有一个解决方案,它使用 (a)S的列类型siunitx将数字条目对齐到小数点标记上,(b)\si宏(也是siunitx包的)来格式化单位,以及 (c)tabularx包(以及该包的列类型的修改形式,X用于 8 个子标题中的 6 个)强制表格占据文本块的整个宽度(并且不会更多!)。最后,包的规则绘制宏booktabs用于在水平线周围获得良好的间距。

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,booktabs}
\usepackage{siunitx}
  \sisetup{per-mode=symbol}
\usepackage{tabularx,ragged2e}
  \newcolumntype{C}{>{\Centering\arraybackslash}X} % centered form of "X" column type
  \newcommand\mC[1]{\multicolumn{1}{C}{#1}}        % handy shortcut macro
\begin{document}

\begin{table}[ht]
\setlength\tabcolsep{5pt} % default value: 6pt
\begin{tabularx}{\textwidth}{@{} *{2}{l *{2}{S[table-format=4.1]} S[table-format=1.2]}  @{}} 
\toprule
\multicolumn{4}{@{}c}{Yellow conidia} & \multicolumn{4}{c@{}}{Black conidia} \\ 
\cmidrule(r){1-4} \cmidrule(l){5-8}
%% use "C" column type for six of the eight header cells
Run & \mC{Yield (\si{\nano\gram\per\micro\liter})} 
    & \mC{Yield (\si{\micro\gram\per\gram} of conidia)} 
    & \mC{OD Reference (260/280)} &
Run & \mC{Yield (\si{\nano\gram\per\micro\liter})} 
    & \mC{Yield (\si{\micro\gram\per\gram} of conidia)} 
    & \mC{OD Reference (260/280)}\\
\midrule
 1 & 685 & 1370 & 2.04 & 1 & 377.5 & 754.9 & 1.98 \\ 
 2 & 186.7 & 373.4 & 1.71 & 2 & 122.6 & 245.2 & 1.6 \\ 
 3 & 314.1 & 628.2 & 1.81 & 3 & 387.2 & 774.4 & 2.04 \\ 
 4 & 209.1 & 418.2 & 1.84 & 4 & 291.3 & 582.7 & 1.92 \\ 
 5 & 724.3 & 1448.5 & 1.99 & 5 & 615.5 & 1231 & 1.99 \\ 
 6 & 582.7 & 1165.3 & 1.74 & 6 & 337.4 & 674.9 & 2.09 \\ 
 7 & 334.4 & 668.7 & 2.00 & 7 & 282 & 564 & 2.04 \\ 
 8 & 126 & 252 & 2.13 & 8 & 92.8 & 185.6 & 1.99 \\ 
 9 & 647.1 & 1294.2 & 1.95 & 9 & 507.6 & 1015.2 & 1.99 \\ 
10 & 964.4 & 1928.8 & 2.06 & 10 & 508 & 1016 & 1.87 \\
11 & 1033.9 & 2067.8 & 1.92 & 11 & 760.9 & 1521.8 & 1.92 \\ 
12 & 439 & 877.9 & 1.88 & 12 & 368.6 & 737.1 & 1.88 \\ 
13 & 1242.7 & 2485.4 & 1.88 & 13 & 911.2 & 1822.4 & 1.93 \\ 
14 & 1113 & 2226 & 1.82 & 14 & 283.7 & 567.4 & 1.56 \\ 
15 & 1081.7 & 2163.4 & 1.93 & 15 & 575.9 & 1151.8 & 1.92 \\ 
16 & 274.3 & 548.6 & 1.87 & 16 & 151.3 & 302.6 & 1.79 \\ 
\bottomrule
\end{tabularx}
\end{table}
\end{document}

相关内容