当我输入这些内容时,为什么“Type I stuff”和“Type II stuff”会分成 2-3 行?我怎样才能将它们写在一行中而不换行?当我使用 c 而不是 M 进行多列时,它不会将文本置于单元格的垂直中间。我该如何改变这种情况?
\documentclass[a4paper,12pt]{scrartcl}
\usepackage{array}
\usepackage{hhline}
\usepackage{xfrac}
\begin{document}
\newcolumntype{M}{>{\centering\arraybackslash}m{\dimexpr.10\linewidth-2\tabcolsep}}
\begin{table}[h]
\centering
\caption{Long Stuff}
\begin{tabular}{|l|MMMM|MMMM|M}
\hline
Primer & \multicolumn{4}{M|}{Type I stuff} & \multicolumn{4}{M|}{Type II stuff} \\[5pt] \hline
Type I & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\[5pt] \hline
Type II & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\[5pt] \hline
\end{tabular}
\end{table}
\end{document}
答案1
非居中源自\\[5pt]
之前使用的\hline
s。我将其替换为加载cellspace
包,这可确保在带有以字母为前缀的说明符的列中单元格上方和下方的垂直间距最小S
(或者C
如果您使用siunitx
)。我还加载了caption
包以确保标题和表格之间的垂直间距正确:
\documentclass[preview]{article}
\usepackage{amsmath, xfrac}
\usepackage{caption}
\usepackage{cellspace}
\setlength\cellspacetoplimit{6pt}
\setlength\cellspacebottomlimit{6pt}
\newcolumntype{M}{>{\centering\arraybackslash}m{\dimexpr.10\linewidth-2\tabcolsep}}
\begin{document}
\begin{table}[h]
\caption{Dilutions used to establish positive and negative controls}
\label{Dilutions used to establish positive and negative controls}
\begin{tabular}{|Sl|*{4}{M}|*{4}{M}|M}
\hline
Primer & \multicolumn{4}{c|}{Type I stuff} & \multicolumn{4}{c|}{Type II stuff} \\ \hline
Type I & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\\hline
Type II & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\ \hline
\end{tabular}
\end{table}
\end{document}
答案2
使用\makecell
同名包(即makecell
(即)但是,此命令必须指定每个单元格。默认设置是垂直居中。
命令存在一些问题\\[5pt]
,导致最后一列的分数上移。我添加了第二个版本,不会发生这种情况
\documentclass{article}
\usepackage{array}
\usepackage{hhline}
\usepackage{mathtools}
\usepackage{makecell}
\usepackage{xfrac}
\newcolumntype{M}{>{\centering\arraybackslash}m{\dimexpr.12\linewidth-2\tabcolsep}}
%\newcolumntype{Q}[1]{>{\centering\arraybackslash}m{\dimexpr.10\linewidth-2\tabcolsep}}
\begin{document}
\begin{table}[h]
\centering
\caption{Dilutions used to establish positive and negative controls}
\label{Dilutions used to establish positive and negative controls}
\begin{tabular}{|l|MMMM|MMMM|M}
\hline
Primer & \multicolumn{4}{M|}{\makecell{Type I stuff}} & \multicolumn{4}{M|}{\makecell{Type II stuff}} \\[5pt] \hline
Type I & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\[5pt] \hline
Type II & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\[5pt] \hline
\end{tabular}
\end{table}
\begin{table}[h]
\centering
\caption{Dilutions used to establish positive and negative controls}
\label{Dilutions used to establish positive and negative controls}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{|l|MMMM|MMMM|M}
\hline
Primer & \multicolumn{4}{M|}{\centering\makecell{Type I stuff}} & \multicolumn{4}{M|}{\makecell{Type II stuff}} \\ \hline
Type I & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\ \hline
Type II & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\ \hline
\end{tabular}
\end{table}
\end{document}
答案3
我建议您删除手动[5pt]
间距指令,并改为指定
\setlength\extrarowheight{5pt}
我还将切换到m
列p
类型,以确保第一列中的材料与其他 8 列中的材料设置在相同的基线上。
此外,我鼓励您改用不使用垂直线、使用较少但间距适当的水平线的表格设计,如下面第二个表格所示。它使用包的线条绘制宏booktabs
。
\documentclass[a4paper,12pt]{scrartcl}
\usepackage{tabularx}
\newcolumntype{M}{>{\centering\arraybackslash}p{\dimexpr.10\linewidth -2\tabcolsep}}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage{hhline}
\usepackage{xfrac}
\usepackage{booktabs}
\begin{document}
\begin{table}[h]
\setlength\extrarowheight{5pt}
\centering
\caption{Long Stuff}
\begin{tabular}{|l|MMMM|MMMM|}
\hline
Primer & \multicolumn{4}{c|}{Type I stuff} & \multicolumn{4}{c|}{Type II stuff} \\ \hline
Type I & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\ \hline
Type II & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\ \hline
\end{tabular}
\end{table}
\begin{table}[h]
\setlength\extrarowheight{3pt}
\centering
\caption{Version with booktabs-based horizontal rules and no vertical rules}
\begin{tabularx}{0.92\textwidth}{@{} l *{8}{C} @{}}
\toprule
Primer & \multicolumn{4}{c}{Type I stuff} & \multicolumn{4}{c}{Type II stuff} \\
\cmidrule(lr){2-5} \cmidrule(l){6-9}
Type I & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\
Type II & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ & undiluted & $\sfrac{1}{10}$ & $\sfrac{1}{100}$ & $\sfrac{1}{1000}$ \\ \bottomrule
\end{tabularx}
\end{table}
\end{document}