2

I have two table in my latex project, whereas I first describe the main context of the first table, then render the table after that text. In my context, my first table is a bit of large (fit half of pages), then I give new line sentences to continue my discussion and render the second table (it is the small table). However, in latex output, the position of table and text is not aligned perfectly. How can I control the position of table whereas given text comes first then table comes after?

Here is my latex code:

%% 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
    Which document class do you use? Which packages do you load? How or where are the \diagbox, \multirowcell, and \ac macros defined? – Mico Mar 30 '17 at 9:20
  • @Mico I used \documentclass{ituthesis}, and I used \usepackage{array, tabularx, multirow, booktabs, diagbox} and \usepackage{makecell}, which are defined in my preamble. – Jared Mar 30 '17 at 9:25
  • Is the ituthesis document class available online somewhere? – Mico Mar 30 '17 at 9:47
  • @Mico or how to fit above two table stick together in one page? I could use cross reference with corresponding text? Any idea? let me know if you intend to check my project, so I could share it with you. – Jared Mar 30 '17 at 10:59
  • If you're OK with making both tabular environments and their associated \caption directives be part of a single table environment, that would probably be the easiest solution. – Mico Mar 30 '17 at 11:14
2

If I understood your main issues correctly (and I may not have...), you're concerned that the tabularx and tabular environments are wider than the parameter \textwidth.

If that's the case, I suggest you use a tabularx environment (with width set to \textwidth) and a tabular* environment instead. To keep them from floating too far from the text portions that directly precede them, consider assigning [ht!] location specifiers for both table environments.

enter image description here

\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}
| improve this answer | |
  • How can I avoid that spanish text? – Jared Mar 30 '17 at 12:53
  • Do you mean the fake-Latin filler paragraph? Just omit the instruction \lipsum[2]. – Mico Mar 30 '17 at 13:15
  • I think your approach is great. I got rid of param list table that massed up my project, while keep using your improvement. Plus any way I could simplify param list table (don't add description column, just get plain table is enough for me). Any idea? – Jared Mar 30 '17 at 13:18
  • @Dan - I'm afraid I don't understand the background, objective, and contents of the first table sufficiently to give advice on matters of contents. Sorry. – Mico Mar 30 '17 at 13:50
  • Dear Mico, regarding the output of your solution, how can I highlight one particular cell and use cross-reference for corresponding text? – Jared Mar 30 '17 at 23:11
2

If I understand you correctly then you want the content to occur as text-table-text-table. You probably don't want the tables to float at all. Try this:

\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}

And for god's sake, please provide a proper working minimum example next time! There are loads of packages to load and self-defined lengths and commands in your code-snippet which are never loaded or defined in your example because it is no MWE. Had Mico not have figured out which packages to load, I would have never gone through the trouble to do it myself just to answer you.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.