當我輸入此內容時,為什麼「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
非居中來自於s\\[5pt]
之前使用的\hline
。我用加載包來替換它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}