![如何让两个表格在同一个页面内保持粘在一起?](https://linux22.com/image/352244/%E5%A6%82%E4%BD%95%E8%AE%A9%E4%B8%A4%E4%B8%AA%E8%A1%A8%E6%A0%BC%E5%9C%A8%E5%90%8C%E4%B8%80%E4%B8%AA%E9%A1%B5%E9%9D%A2%E5%86%85%E4%BF%9D%E6%8C%81%E7%B2%98%E5%9C%A8%E4%B8%80%E8%B5%B7%EF%BC%9F.png)
我的 latex 项目中有两个表格,而我首先描述第一个表格的主要内容,然后在该文本之后渲染表格。在我的上下文中,我的第一个表格有点大(适合一半的页面),然后我给出换行符来继续我的讨论并渲染第二个表格(它是小表格)。然而,在 latex 输出中,表格和文本的位置并不完全对齐。我如何控制表格的位置,而给定的文本在前面,表格在后面?
这是我的乳胶代码:
%% 5~6 line text
\begin{table}
\centering
\caption{MuSERA parameter setup}
\label{tab:parameter setup}
\noindent\setlength\extrarowheight{3pt}\begin{tabularx}{1.25\linewidth}{|c|c| >{\arraybackslash}X|} \hline
\diagbox[width = 5cm, height =1.25cm]{Param. list}{\raisebox{5ex}{Name}}
& Parameter & \multicolumn{1}{c|}{Description} \\\hline
\hline
\multirowcell{2}{Replicate Type} & Biological & biological replicates exhibit biologically similar results\\\hline
\multirow{3}*{Thresholds} & $T^{w} = 1.0e-04 $ & stringent enrichment threshold\\
\cline{2-3}
& $T^{s} = 1.0e-08 $ & weakly enrichment threshold\\
\cline{2-3}
& $\gamma = 1.0e-08 $ & combined stringency threshold\\
\hline
\multirowcell{2}{Multiple Testing \\correction} & FDR = 0.05 & false discovery rate to correct the p-value\\\hline
\multirowcell{2}{Multiple Overlap\\ ERs treatment} & Use most stringent peak & choose the most stringent \ac{er} (with lowest p-value) from multiple overlapping\\\hline
\end{tabularx}
\end{table}
%% 5~6 line text
\settowidth\mylen{wgEncodeOpenChromChip}
\begin{table}[ht]
\centering
\caption{\textit{MuSERA output}}
\label{tab:MuSERA output}
\begin{tabular}{@{}m{\mylen}ccccccc@{}}
\toprule
Replicate & total ERs & $R^{s}$ & $R^{w}$ & $R^{c}$ & $R^{d}$ & $R^{mtc}$ & outputset\\
\midrule
wgEncodeOpenChromChip K562CmycAlnRep1 & 283 & 158 & 125 & 241 & 42 & 241 & 241 \\
wgEncodeOpenChromChip K562CmycAlnRep2 & 459 & 230 & 229 & 465 & 195 & 266 & 266 \\
wgEncodeOpenChromChip K562CmycAlnRep3 & 297 & 109 & 188 & 368 & 107 & 191 & 191 \\
\bottomrule
\end{tabular}
\end{table}
答案1
如果我正确理解了您的主要问题(我可能没有......),您担心tabularx
和tabular
环境比参数更广泛\textwidth
。
如果是这种情况,我建议您改用tabularx
环境(宽度设置为\textwidth
)和tabular*
环境。为了防止它们浮动得离它们前面的文本部分太远,请考虑为这两个环境分配[ht!]
位置说明符。table
\documentclass{article} % I don't have the file "ituthesis.cls"
\usepackage{array, tabularx, multirow, booktabs,
diagbox, makecell, amsmath, calc, ragged2e}
\usepackage[skip=0.333\baselineskip]{caption}
\providecommand\ac[1]{#1} % ??
\newlength\mylen
\usepackage{lipsum}
\begin{document}
\begin{table}
\setlength\extrarowheight{3pt}
\caption{MuSERA parameter setup}
\label{tab:parameter setup}
\begin{tabularx}{\linewidth}{|p{3.25cm-2\tabcolsep}|c| >{\RaggedRight\arraybackslash}X|}
\hline
\diagbox[width = 3.25cm, height =1.25cm]{Param. list}{Name}
& Parameter & \multicolumn{1}{c|}{Description} \\
\hline\hline
\multirowcell{2}{Replicate Type} & Biological & biological replicates exhibit biologically similar results\\
\hline
\multirow{6}{*}{Thresholds}
& $T^{w} = 1.0e{-}04 $ & stringent enrichment threshold\\
\cline{2-3}
& $T^{s} = 1.0e{-}08 $ & weakly enrichment threshold\\
\cline{2-3}
& $\gamma = 1.0e{-}08 $ & combined stringency threshold\\
\hline
\multirowcell{2}{Multiple Testing \\correction} & FDR${} = 0.05$ & false discovery rate to correct the $p$\nobreakdash-value\\
\hline
\multirowcell{2}{Multiple Overlap\\ ERs treatment} & Use most stringent peak & choose the most stringent \ac{er} (with lowest $p$\nobreakdash-value) from multiple overlapping\\
\hline
\end{tabularx}
\end{table}
\lipsum[2] % filler text
\begin{table}[h!]
\settowidth\mylen{wgEncodeOpenChromChip}
\setlength\tabcolsep{0pt}
\caption{\textit{MuSERA output}}
\label{tab:MuSERA output}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}m{\mylen}*{7}{c}}
\toprule
Replicate & total ERs & $R^{s}$ & $R^{w}$ & $R^{c}$ & $R^{d}$ & $R^{mtc}$ & outputset\\
\midrule
wgEncodeOpenChromChip K562CmycAlnRep1 & 283 & 158 & 125 & 241 & 42 & 241 & 241 \\
wgEncodeOpenChromChip K562CmycAlnRep2 & 459 & 230 & 229 & 465 & 195 & 266 & 266 \\
wgEncodeOpenChromChip K562CmycAlnRep3 & 297 & 109 & 188 & 368 & 107 & 191 & 191 \\
\bottomrule
\end{tabular*}
\end{table}
%% still more text
\end{document}
答案2
如果我理解正确的话,您希望内容以文本-表格-文本-表格的形式出现。您可能根本不希望表格浮动。试试这个:
\documentclass[a4paper]{scrartcl}
\usepackage{caption}
\usepackage{array, tabularx, multirow, booktabs,
diagbox, makecell, amsmath, calc, ragged2e}
\newcommand{\ac}[1]{\emph{#1}}
\newlength{\mylen}
\setlength{\mylen}{\textwidth}
\begin{document}
Here are just a few lines of text. This is just to show how the text would run and how the tables would in each case occur directlyafter the text were they are referred to.
\begin{center}
\captionof{table}{MuSERA parameter setup\label{tab:parameter setup}}
\noindent\setlength\extrarowheight{3pt}\begin{tabularx}{\linewidth}{|c|c| >{\arraybackslash}X|} \hline
\diagbox[width = 5cm, height =1.25cm]{Param. list}{\raisebox{5ex}{Name}}
& Parameter & \multicolumn{1}{c|}{Description} \\\hline
\hline
\multirowcell{2}{Replicate Type} & Biological & biological replicates exhibit biologically similar results\\\hline
\multirow{3}*{Thresholds} & $T^{w} = 1.0e-04 $ & stringent enrichment threshold\\
\cline{2-3}
& $T^{s} = 1.0e-08 $ & weakly enrichment threshold\\
\cline{2-3}
& $\gamma = 1.0e-08 $ & combined stringency threshold\\
\hline
\multirowcell{2}{Multiple Testing \\correction} & FDR = 0.05 & false discovery rate to correct the p-value\\\hline
\multirowcell{2}{Multiple Overlap\\ ERs treatment} & Use most stringent peak & choose the most stringent \ac{er} (with lowest p-value) from multiple overlapping\\\hline
\end{tabularx}
\end{center}
Here are just a few lines of text. This is just to show how the text would run and how the tables would in each case occur directlyafter the text were they are referred to.
\settowidth\mylen{wgEncodeOpenChromChip}
\begin{center}
\captionof{table}{\textit{MuSERA output}\label{tab:MuSERA output}}
\begin{tabular}{@{}m{\mylen}ccccccc@{}}
\toprule
Replicate & total ERs & $R^{s}$ & $R^{w}$ & $R^{c}$ & $R^{d}$ & $R^{mtc}$ & outputset\\
\midrule
wgEncodeOpenChromChip K562CmycAlnRep1 & 283 & 158 & 125 & 241 & 42 & 241 & 241 \\
wgEncodeOpenChromChip K562CmycAlnRep2 & 459 & 230 & 229 & 465 & 195 & 266 & 266 \\
wgEncodeOpenChromChip K562CmycAlnRep3 & 297 & 109 & 188 & 368 & 107 & 191 & 191 \\
\bottomrule
\end{tabular}
\end{center}
\end{document}
看在上帝的份上,请提供一个适当的在职的下次再举个最小的例子!您的代码片段中有很多需要加载的包和自定义的长度和命令,但这些在您的示例中从未加载或定义过,因为它不是 MWE。如果 Mico 没有弄清楚要加载哪些包,我就不会费尽心思自己做这件事来回答你。