如何让两个表格在同一个页面内保持粘在一起?

如何让两个表格在同一个页面内保持粘在一起?

我的 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

如果我正确理解了您的主要问题(我可能没有......),您担心tabularxtabular环境比参数更广泛\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 没有弄清楚要加载哪些包,我就不会费尽心思自己做这件事来回答你。

相关内容