4

As can be seen in the screenshot below, there is no spacing between the table and the text that follows. What is the reason for this and what is the best solution?

enter image description here

Here is my latex:

\documentclass{report}

% \usepackage[dvips]{graphicx} \usepackage{multirow} \usepackage{tabularx} \begin{document}

\begin{tabular}{ |p{3cm}||p{2cm}|p{2cm}|p{2cm}|} \hline \multicolumn{1}{|c||}{} & \multicolumn{3}{c|}{\textbf{Performance}} \ \multicolumn{1}{|c||}{\textbf{Method}} & \multicolumn{1}{c}{Excellent} & \multicolumn{1}{c}{Suboptimal} & \multicolumn{1}{c|}{Poor} \ \cline{2-4} Title Search & 22 & 15 & 14 \ Newline Freq. & 44 & 3 & 4 \ \hline \end{tabular}

As the change point detection algorithm performs quite well on these 50 samples and is much better than the title search method, we use it to trim our entire dataset.

\end{document}

----------------------------EDIT------------------------------

When I attempt to use the solution posted by Karlo in my full latex document, my table appears inbetween two items in my enumerated list. Here is a screenshot:

enter image description here

I was able to get a similar (and most likely related) issue as the screenshot above with the following code:

\documentclass{report}

% \usepackage[dvips]{graphicx} \usepackage{multirow} \usepackage{tabularx} \begin{document}

\begin{enumerate} \item \textbf{Excellent}: The trimming occurred exactly where desired. \item \textbf{Suboptimal}: The trimming occurred within a couple sentences of where desired. \item \textbf{Poor}: A good chunk (more than a 3-4 sentences) of the book was erroneously trimmed or a significant amount of the noise was kept. \end{enumerate}

\begin{table} \begin{tabular}{ |p{3cm}||p{2cm}|p{2cm}|p{2cm}|} \hline \multicolumn{1}{|c||}{} & \multicolumn{3}{c|}{\textbf{Performance}} \ \multicolumn{1}{|c||}{\textbf{Method}} & \multicolumn{1}{c}{Excellent} & \multicolumn{1}{c}{Suboptimal} & \multicolumn{1}{c|}{Poor} \ \cline{2-4} Title Search & 22 & 15 & 14 \ Newline Freq. & 44 & 3 & 4 \ \hline \end{tabular} \end{table}

As the change point detection algorithm performs quite well on these 50 samples and is much better than the title search method, we use it to trim our entire dataset.

\end{document}

With the code above, the table gets outputted completely before the list even though it comes after the enumerated list in the code.

4 Answers4

3

This is because you have typeset your table inline next to regular text. Usually, tables are put in a float environment, as you would do with figures (see for instance here).

Adapting your code like this:

\documentclass{report}

% \usepackage[dvips]{graphicx} \usepackage{multirow} \usepackage{tabularx} \begin{document}

\begin{table} \caption{Caption text} \label{myTable} \center \begin{tabular}{ |p{3cm}||p{2cm}|p{2cm}|p{2cm}|} \hline \multicolumn{1}{|c||}{} & \multicolumn{3}{c|}{\textbf{Performance}} \ \multicolumn{1}{|c||}{\textbf{Method}} & \multicolumn{1}{c}{Excellent} & \multicolumn{1}{c}{Suboptimal} & \multicolumn{1}{c|}{Poor} \ \cline{2-4} Title Search & 22 & 15 & 14 \ Newline Freq. & 44 & 3 & 4 \ \hline \end{tabular} \end{table}

As the change point detection algorithm performs quite well on these 50 samples and is much better than the title search method, we use it to trim our entire dataset (Table \ref{myTable}).

\end{document}

gives:

enter image description here

UPDATE

As with figures, LaTeX decides where to put the float. Use \begin{table}[h!] to force the float position (see list of alternative letters here).

Karlo
  • 3,257
  • 1
    So when I try this on my full latex document, it for some reason puts the table in between two points of an enumerated list. Do you have a guess as to why? I will make an edit to my question with a screenshot – Luca Guarro Sep 17 '21 at 23:07
  • In the meantime, I will see if I can reproduce the problem on a simpler file. – Luca Guarro Sep 17 '21 at 23:10
  • @LucaGuarro See updated answer. – Karlo Sep 17 '21 at 23:43
3

enter image description here

\documentclass{report}

% \usepackage[dvips]{graphicx} \usepackage{multirow} \usepackage{tabularx, booktabs}%<-----------------new \begin{document}

\begin{enumerate}
    \item \textbf{Excellent}: The trimming occurred exactly where desired.
    \item \textbf{Suboptimal}: The trimming occurred within a couple sentences of where desired.
    \item \textbf{Poor}: A good chunk (more than a 3-4 sentences) of the book was erroneously trimmed or a significant amount of the noise was kept.
\end{enumerate}

\begin{table}[h]%&lt;-------------------------added
    \begin{tabular}{ p{3cm}p{2cm}p{2cm}p{2cm}}
        \toprule
        \multicolumn{1}{c}{} 
            &amp; \multicolumn{3}{c}{\textbf{Performance}} \\
        \multicolumn{1}{c}{\textbf{Method}} 
            &amp; \multicolumn{1}{c}{Excellent} 
                &amp; \multicolumn{1}{c}{Suboptimal} 
                    &amp; \multicolumn{1}{c}{Poor} \\ 
        \cmidrule{2-4}
        Title Search 
            &amp; 22 
                &amp; 15 
                    &amp; 14 \\
        Newline Freq. 
            &amp; 44 
                &amp; 3 
                    &amp; 4 \\
        \bottomrule 
    \end{tabular}
\end{table}


As the change point detection algorithm performs quite well on these 50 samples and is much better than the title search method, we use it to trim our entire dataset.


\end{document}

js bibra
  • 21,280
1

With provided MWE is not possible to reproduce your problem. Table has vertical distance from followed text defined by default valu of \textfloatsep (for details see for example see Werner's answer).

So, now it seems that your problem is not what you stated in question's title but placement of float table. Please correct question title accordingly.

Regarding possibilities of float placement see wiki LaTeX/Floats, Figures and Captions. According to this description you should add placement option to your float table, for example \begin{table}[htb] which will place table where you like to have (if there is enough space otherwise it will be moved to top of the next page).

Off topic: Your table I would write by use of the tabularray package. With its use you can get more professional looks:

\documentclass[11pt,a4paper,twoside,openright]{report}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\usepackage[skip=1ex]{caption}

\usepackage{lipsum}

\begin{document} \lipsum[65] \begin{table}[htb] \centering \caption{My table} \label{tab:tblr} \begin{tblr}{width=0.8\linewidth, colspec={ X[2,l] *{3}{X[si={table-format=2.0}, c]} }, row{1} ={font=\bfseries} } \toprule \SetCell[r=2]{c,f} Method & \SetCell[c=3]{c} {{{Performance}}} & & \ \midrule & \SetCell[c=1]{c} {{{Excellent}}} & {{{Suboptimal}}} & {{{Poor}}} \ \midrule Title Search & 22 & 15 & 14 \ Newline Frequency & 44 & 3 & 4 \ \bottomrule \end{tblr} \end{table} \lipsum[66] \end{document}

enter image description here

Zarko
  • 296,517
1

Some suggestions:

  • Since you don't want the table to "float" -- in the LaTeX-specific sense of the word -- and since you don't appear to want to provide a \caption, there's really no point in employing a table environment. Instead, just place the tabular material in a center environment, at the end of the list. Using a center environment has the added benefit of not causing an exaggerated vertical separation between the final list item and the tabular material.

  • I'd switch from an enumerate environment to a description environment, especially as there appears to be no meaning attached to numbering the items.

  • I'd also give the table a more open "look" by loading the booktabs package, getting ride of all vertical rules, and replacing \hline with -- as needed -- \toprule, \midrule, and \bottomrule and replacing \cline{2-4} with \cmidrule(l){2-4}. And, I'd just use the l and c column types to allow the columns occupy their natural widths, the more so since no line breaking within cells appears to be needed. And, since the table is not that big, I see no need for bold-facing the header cells to make them stand out visually.

enter image description here

\documentclass{report}
\usepackage{tabularx,booktabs}
\begin{document}

\begin{description} \item[Excellent] The trimming occurred exactly where desired. \item[Suboptimal] The trimming occurred within a couple sentences of where desired. \item[Poor] A good chunk (more than 3 to 4 sentences) of the book was erroneously trimmed or a significant amount of the noise was kept. \end{description}

\begin{center} \begin{tabular}{@{} l *{3}{c} @{}} \toprule Method & \multicolumn{3}{c}{Performance} \ \cmidrule(l){2-4} & Excellent & Suboptimal & Poor \ \midrule Title Search & 22 & 15 & 14 \ Newline Freq. & 44 & 3 & 4 \ \bottomrule \end{tabular} \end{center}

As the change point detection algorithm performs quite well on these 50 samples and is much better than the title search method, we use it to trim our entire dataset.

\end{document}

Mico
  • 506,678