Graphics, Figures & TablesForce LaTeX to keep table in page

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Ciro
Posts: 6
Joined: Mon Oct 03, 2016 11:53 am

Force LaTeX to keep table in page

Post by Ciro »

Hi, I'm placing a set of five images followed for a table, for three times. The first and second set of images followed by its respective tables are placed in the same page, but when trying to place the third set, LaTeX moves the table to the next page, leaving a huge blank space in the bottom. There's plenty of room for the table to fit in, how can I force LaTeX to place this last table in the same page?

Code: Select all

    \documentclass[a4paper,10pt]{memoir}
    \usepackage[utf8x]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{booktabs}
    \usepackage{longtable}
    \usepackage{graphicx}
    \usepackage{fix-cm}
    \usepackage[font=scriptsize]{caption}
    \usepackage[margin=0.5in]{geometry}
    \usepackage[normalem]{ulem}
    \graphicspath{ {images/} }
    \setlength{\tabcolsep}{2pt}
    \begin{document}

    \begin{figure}[!tbp]
    \noindent\rule{18.9cm}{0.1pt}
    \newline
    \hspace{10em}\uline{\textsc{Group1}\hfill}
    \break \break \break
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img1}
    \caption*{img1}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img2}
    \caption*{img2}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img3}
    \caption*{img3}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img4}
    \caption*{img4}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img5}
    \caption*{img5}
    \end{minipage}
    \end{figure}
    \begin{table}[ht]
    \miniscule
    \caption*{Group1}
    \hspace*{-.5cm}
    \scalebox{0.9}{
    \begin{tabular}{p{2.5cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}}
    \toprule
    \field1 & \field2 & field3 & field4 & \textbf{6M} &  \textbf{3M}&  \textbf{1W} &  \textbf{5} &  \textbf{6} & \textbf{7} & \textbf{8} & \textbf{ROE} & \textbf{9} & \textbf{10} & \textbf{1} \\
    \midrule
    Estee & 88.56 & -9.14 & 8.13 & -5.08 & .19 & 1.32 & 33,068 & 29.93 & 1.36 & 19.23 & 30.90 & N/A & N/A & N/A
    \\
    \midrule
    \end{tabular}}
    \end{table}

    \begin{figure}[!tbp]
    \noindent\rule{18.9cm}{0.1pt}
    \newline
    \hspace{10em}\uline{\textsc{Group2}\hfill}
    \break \break \break
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img6}
    \caption*{img6}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img7}
    \caption*{img7}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img8}
    \caption*{img8}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img9}
    \caption*{img9}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img10}
    \caption*{img10}
    \end{minipage}
    \end{figure}
    \begin{table}[ht]
    \miniscule
    \caption*{Group2}
    \hspace*{-.5cm}
    \scalebox{0.9}{
    \begin{tabular}{p{2.5cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}}
    \toprule
    \field1 & \field2 & field3 & field4 & \textbf{6M} &  \textbf{3M}&  \textbf{1W} &  \textbf{5} &  \textbf{6} & \textbf{7} & \textbf{8} & \textbf{ROE} & \textbf{9} & \textbf{10} & \textbf{1} \\
    \midrule
    test & 155.26 & -40.39 & -27.10 & -16.73 & -5.89 & 2.32 & 1,975 & 23.33 & -- & 19.90 & 18.98 & N/A & N/A & N/A
    \\
    \midrule
    test & 47.44 & -13.04 & -5.30 & -2.18 & .47 & 1.91 & 19,224 & 18.09 & 1.43 & 35.31 & 69.54 & N/A & N/A & N/A
    \\
    \midrule
    Constellation & 166.49 & -1.29 & 28.07 & 10.61 & 7.77 & 1.43 & 33,963 & 33.42 & 0.96 & 32.81 & 17.74 & N/A & N/A & N/A
    \\
    \midrule
    \end{tabular}}
    \end{table}

    \begin{figure}[!tbp]
    \noindent\rule{18.9cm}{0.1pt}
    \newline
    \hspace{10em}\uline{\textsc{Group2}\hfill}
    \break \break \break
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img6}
    \caption*{img6}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img7}
    \caption*{img7}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img8}
    \caption*{img8}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img9}
    \caption*{img9}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.18\textwidth}
    \includegraphics[width=\textwidth]{img10}
    \caption*{img10}
    \end{minipage}
    \end{figure}
    \begin{table}[ht]
    \miniscule
    \caption*{Group2}
    \hspace*{-.5cm}
    \scalebox{0.9}{
    \begin{tabular}{p{2.5cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}p{1.2cm}}
    \toprule
    \field1 & \field2 & field3 & field4 & \textbf{6M} &  \textbf{3M}&  \textbf{1W} &  \textbf{5} &  \textbf{6} & \textbf{7} & \textbf{8} & \textbf{ROE} & \textbf{9} & \textbf{10} & \textbf{1} \\
    \midrule
    test & 155.26 & -40.39 & -27.10 & -16.73 & -5.89 & 2.32 & 1,975 & 23.33 & -- & 19.90 & 18.98 & N/A & N/A & N/A
    \\
    \midrule
    test & 47.44 & -13.04 & -5.30 & -2.18 & .47 & 1.91 & 19,224 & 18.09 & 1.43 & 35.31 & 69.54 & N/A & N/A & N/A
    \\
    \midrule
    Constellation & 166.49 & -1.29 & 28.07 & 10.61 & 7.77 & 1.43 & 33,963 & 33.42 & 0.96 & 32.81 & 17.74 & N/A & N/A & N/A
    \\
    \midrule
    \end{tabular}}
    \end{table}
    \end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Ciro
Posts: 6
Joined: Mon Oct 03, 2016 11:53 am

Re: Force LaTeX to keep table in page

Post by Ciro »

I think I found the solution, I've remove the parameters [!htbp] and [ht] when decalring begin figure and table, respectively, and now they're not being moved to the next page.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Force LaTeX to keep table in page

Post by Stefan Kottwitz »

If you tweak it that way, maybe you would see later that something doesn't fit again. Such as in the case when your text before changes, or the text in the table.

I cannot reproduce the problem. This code doesn't show the behavior your described. Did you test the code example above? It's not working, it gives errors. \field1 and \field2 and \miniscule unknown, and no images. We cannot test it, we cannot see the effect. A code example should be small, compilable, actually show the problem. ;-)

I think, adding a ! to the float options may be sufficient.

Stefan
LaTeX.org admin
Post Reply