0

I have two tables that I managed to put together on top of the other. I would like to have both tables under a set of text and then the remaining text on the next page. For example:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent quis ornare mi. Morbi metus risus, mattis quis vehicula aliquet, ultricies quis justo. Aliquam rhoncus, ante id convallis porta, ligula lectus rutrum justo, sed vehicula nunc sapien eu augue. Nam porttitor lacus et nulla sodales, ut sagittis orci sollicitudin. Phasellus elementum, dolor et auctor tempus, nulla nunc dapibus diam, nec porttitor nibh sapien eu mauris. Fusce venenatis odio lorem, blandit lobortis arcu viverra sed.

Table 1

Table 2

Footer

Duis vitae justo eros. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aenean eu dignissim magna. Donec at pharetra urna. Sed neque massa, eleifend ut ornare in, ullamcorper quis ex.

An image below of the gap:

Image of Gap

I have tried everything but it just keeps staying on the next page leaving a large gap in between the end of the text and footer. Both tables can fit in perfectly. When I try to use \vspace{-5mm} it moves the tables up but onto the text. Then I tried to remove \begin{table}[htbp] and the \caption{text} and use \captionof{table}{text} instead but then the second table is still stuck in the other page but it's caption is above the page I want it to be in.

Here is my code below:

\documentclass{article}
\usepackage[skip=0.5\baselineskip,labelfont=bf,format=plain,labelsep=newline,singlelinecheck=false]{caption} 
\usepackage[utf8]{inputenc}
\usepackage[hyphens]{url}
\usepackage[authoryear,round]{natbib}
\usepackage{fullpage} 
\usepackage{graphicx}
%\usepackage[left=0.5in, right=0.5in, top=.70in]{geometry}  
\setlength{\footskip}{25mm}


\begin{document}

\hspace{-5mm}\textbf{\large{3. Methods}} 

\vspace{2mm}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas at auctor tellus. Cras auctor viverra euismod. Cras faucibus eu quam vitae varius. Ut fringilla bibendum consectetur. Duis libero tortor, imperdiet sed dignissim in, commodo ac odio. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent pellentesque diam ut mauris ultrices, quis efficitur metus maximus. Aenean velit ligula, efficitur ut pulvinar a, sodales vel metus. Morbi pellentesque scelerisque erat quis porta.Ut scelerisque imperdiet odio ut tincidunt. Vestibulum elementum scelerisque tincidunt. Sed vel nunc rhoncus ligula mollis tempor. Maecenas sit amet mi risus. Nulla sed ultricies sapien, et aliquam tellus. Aliquam sed mauris at felis tempus varius vel eu erat. Quisque id lectus aliquet, fringilla nibh sed, mollis enim. Mauris turpis sem, ullamcorper ac mattis ac, egestas a erat. Maecenas auctor mi non venenatis luctus. Phasellus gravida elementum est vitae dictum. Curabitur sollicitudin sodales est, non semper magna facilisis sit amet. Nam posuere eget ligula ut hendrerit. Nulla non porttitor augue. Curabitur euismod augue tincidunt, faucibus justo sed, fermentum eros.

\pagebreak 
\begin{table}[htbp]
\centering
\caption{The training and test data frequencies for each city for Case 1.}
\label{tab:case1}
\resizebox{\textwidth}{!}{%
\setlength{\tabcolsep}{7pt} 
\renewcommand{\arraystretch}{1.5}

\begin{tabular}{lcccc}
\hline 
\multicolumn{1}{c}{Training Set} & Test Set & Dates for Training Set & Dates for Test Set                  & Dates for Test Set                  \\ 
\hline 
Seattle        & 750      & 367                    & January 1, 2018 -  January 20, 2020 & January 21, 2020 - January 21, 2021 \\ [0.5ex]
San Francisco                    & 750      & 370                    & January 1, 2018 -  January 20, 2020 & January 21, 2020 - January 24, 2021 \\ [0.5ex]
Los Angeles                      & 750      & 364                    & January 1, 2018 -  January 20, 2020 & January 21, 2020 - January 18, 2021 \\[0.5ex]
Philadelphia                     & 750      & 370                    & January 1, 2018 -  January 20, 2020 & January 21, 2020 - January 24, 2021 \\ \hline
\end{tabular}} 

\bigskip

\caption{The training and test data frequencies for each city for Case 2.}
\label{tab:case2}
\resizebox{\textwidth}{!}{%
\setlength{\tabcolsep}{7pt} 
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{lcccc}
\hline
\multicolumn{1}{c}{Training Set} & Test Set & Dates for Training Set & Dates for Test Set                  & Dates for Test Set                  \\ \hline
Seattle                          & 876      & 241                    & January 1, 2018 -  May 25, 2020 & May 26, 2020 - January 21, 2021 \\
San Francisco                    & 876      & 244                    & January 1, 2018 -  May 25, 2020 & May 26, 2020 - January 24, 2021 \\
Los Angeles                      & 876      & 238                    & January 1, 2018 -  May 25, 2020 & May 26, 2020 - January 18, 2021 \\
Philadelphia                     & 876      & 244                    & January 1, 2018 -  May 25, 2020 & May 26, 2020 - January 24, 2021 \\ \hline
\end{tabular}}  
\end{table} 

\vspace{5mm}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas at auctor tellus. Cras auctor viverra euismod. Cras faucibus eu quam vitae varius. Ut fringilla bibendum consectetur. Duis libero tortor, imperdiet sed dignissim in, commodo ac odio. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent pellentesque diam ut mauris ultrices, quis efficitur metus maximus. Aenean velit ligula, efficitur ut pulvinar a, sodales vel metus. Morbi pellentesque scelerisque erat quis porta.Ut scelerisque imperdiet odio ut tincidunt. Vestibulum elementum scelerisque tincidunt. Sed vel nunc rhoncus ligula mollis tempor. Maecenas sit amet mi risus. Nulla sed ultricies sapien, et aliquam tellus. Aliquam sed mauris at felis tempus varius vel eu erat. Quisque id lectus aliquet, fringilla nibh sed, mollis enim. Mauris turpis sem, ullamcorper ac mattis ac, egestas a erat. Maecenas auctor mi non venenatis luctus. Phasellus gravida elementum est vitae dictum. Curabitur sollicitudin sodales est, non semper magna facilisis sit amet. Nam posuere eget ligula ut hendrerit. Nulla non porttitor augue. Curabitur euismod augue tincidunt, faucibus justo sed, fermentum eros.\\  

\hspace{-5mm}\textbf{\large{4. Results}} 

\vspace{2mm}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas at auctor tellus. Cras auctor viverra euismod. Cras faucibus eu quam vitae varius. Ut fringilla bibendum consectetur. Duis libero tortor, imperdiet sed dignissim in, commodo ac odio. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent pellentesque diam ut mauris ultrices, quis efficitur metus maximus. Aenean velit ligula, efficitur ut pulvinar a, sodales vel metus. Morbi pellentesque scelerisque erat quis porta.Ut scelerisque imperdiet odio ut tincidunt. Vestibulum elementum scelerisque tincidunt. Sed vel nunc rhoncus ligula mollis tempor. Maecenas sit amet mi risus. Nulla sed ultricies sapien, et aliquam tellus. Aliquam sed mauris at felis tempus varius vel eu erat. Quisque id lectus aliquet, fringilla nibh sed, mollis enim. Mauris turpis sem, ullamcorper ac mattis ac, egestas a erat. Maecenas auctor mi non venenatis luctus. Phasellus gravida elementum est vitae dictum.\\  


\end{document}
 

I would appreciate any help and if there is anymore info I can provide, please let me know.

12
  • One way or another, you will have to make it smaller. I would reduce \arraystretch. Mar 29, 2021 at 22:13
  • maybe you can combine both tables?
    – Excelsior
    Mar 29, 2021 at 22:39
  • @ John Kormylo Thank you, I will try to do that.
    – guest1234
    Mar 29, 2021 at 23:13
  • @Excelsior They are already combined together, one top of the other. Edit: After looking at your answer below, now I get what you meant. The issue is the table keeps getting put back into the other page.
    – guest1234
    Mar 29, 2021 at 23:21
  • @guest 1234 I cannot reproduce your problem. What do you mean with large space between table and text.You do realize that there is a \pagebreak between your text and first table.
    – Roland
    Mar 30, 2021 at 0:14

2 Answers 2

1

In case it fits and still suits your need, you can combine both tables.

\documentclass{article}

\usepackage[
    skip=0.5\baselineskip,
    labelfont=bf,
    format=plain,
    labelsep=newline,
    singlelinecheck=false
    ]{caption} 
\usepackage[utf8]{inputenc}
\usepackage{fullpage} 
\usepackage{graphicx,multirow,booktabs}

\setlength{\footskip}{25mm}

\begin{document}
    
    \begin{table}[htbp]
        \centering
        \caption{The training and test data frequencies for each city.}
        \label{tab:cases}
        \resizebox{\textwidth}{!}{%
            \setlength{\tabcolsep}{7pt} 
            \renewcommand{\arraystretch}{1.5}
            
            \begin{tabular}{llcccc}
                \toprule 
                & Training Set & Test Set & Dates for  Training Set & Dates for Test Set & Dates for Test Set \\ 
                \midrule 
                \multirow{4}{*}{\rotatebox[origin=c]{90}{Case1}} & Seattle & 750 & 367 & Jan 1, 2018 - Jan 20, 2020 & Jan 21, 2020 - Jan 21, 2021 \\
                & San Francisco & 750 & 370 & Jan 1, 2018 - Jan 20, 2020 & Jan 21, 2020 - Jan 24, 2021 \\
                & Los Angeles & 750 & 364 & Jan 1, 2018 - Jan 20, 2020 & Jan 21, 2020 - Jan 18, 2021 \\
                & Philadelphia & 750 & 370 & Jan 1, 2018 - Jan 20, 2020 & Jan 21, 2020 - Jan 24, 2021 \\ \cmidrule{2-6}
                \multirow{4}{*}{\rotatebox[origin=c]{90}{Case2}} & Seattle & 876 & 241 & Jan 1, 2018 - May 25, 2020 & May 26, 2020 - Jan 21, 2021 \\
                & San Francisco & 876 & 244 & Jan 1, 2018 - May 25, 2020 & May 26, 2020 - Jan 24, 2021 \\
                & Los Angeles & 876 & 238 & Jan 1, 2018 - May 25, 2020 & May 26, 2020 - Jan 18, 2021 \\
                & Philadelphia & 876 & 244 & Jan 1, 2018 - May 25, 2020 & May 26, 2020 - Jan 24, 2021 \\ \bottomrule
            \end{tabular}
        } 
    \end{table} 
    
\end{document}

enter image description here

Let me know if the saved space is enough.

18
  • @ Excelsior, thank you but is there a way to keep it into two separate tables and fit it within below the text and footer? If not, then I guess this can work. The only issue is how can I prevent the table from going back to the next page?
    – guest1234
    Mar 29, 2021 at 23:18
  • @guest1234 Can you add the sentences (or some dummy text), where the table should fit between?
    – Excelsior
    Mar 29, 2021 at 23:22
  • @ Excelsior Sure
    – guest1234
    Mar 29, 2021 at 23:28
  • @ Excelsior You can just use \lipsum[1] of the lipsum package to generate dummy pacakge.
    – Roland
    Mar 29, 2021 at 23:31
  • @ Excelsior I just updated my code with some text and a note of the footer and next page would be.
    – guest1234
    Mar 29, 2021 at 23:31
0

This may not answer to your question, but something you may want to consider. \resizebox may solve your problem of fitting the table to your pagewidth put it also changes the font size of the table. To avoid that you can use tabularx as seen in my table 1.

I also added \section to keep it organized.

\documentclass{article}
\usepackage[skip=0.5\baselineskip,labelfont=bf,format=plain,labelsep=newline,singlelinecheck=false]{caption} 
\usepackage[utf8]{inputenc}
\usepackage[hyphens]{url}
\usepackage[authoryear,round]{natbib}
\usepackage{fullpage} 
\usepackage{graphicx}
%\usepackage[left=0.5in, right=0.5in, top=.70in]{geometry}  
\setlength{\footskip}{25mm}

\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}%middle aligns X column type
\usepackage{lipsum}
\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage} %pagebreak after new section


\begin{document}

\section{Methods}

\lipsum[1-2]

\begin{table}[htbp]
\centering
\caption{The training and test data frequencies for each city for Case 1.}
\label{tab:case1}
%\resizebox{\textwidth}{!}{%
%\setlength{\tabcolsep}{7pt} 
\renewcommand{\arraystretch}{1.5}

\begin{tabularx}{\textwidth}{@{}l *5{>{\centering\arraybackslash}X}@{}}
\hline 
\multicolumn{1}{c}{Training Set} & Test Set & Dates for Training Set & Dates for Test Set                  & Dates for Test Set                  \\ 
\hline 
Seattle        & 750      & 367                    & January 1, 2018 -  January 20, 2020 & January 21, 2020 - January 21, 2021 \\ [0.5ex]
San Francisco                    & 750      & 370                    & January 1, 2018 -  January 20, 2020 & January 21, 2020 - January 24, 2021 \\ [0.5ex]
Los Angeles                      & 750      & 364                    & January 1, 2018 -  January 20, 2020 & January 21, 2020 - January 18, 2021 \\[0.5ex]
Philadelphia                     & 750      & 370                    & January 1, 2018 -  January 20, 2020 & January 21, 2020 - January 24, 2021 \\ \hline
\end{tabularx}

\bigskip

\caption{The training and test data frequencies for each city for Case 2.}
\label{tab:case2}
\resizebox{\textwidth}{!}{%
\setlength{\tabcolsep}{7pt} 
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{lcccc}
\hline
\multicolumn{1}{c}{Training Set} & Test Set & Dates for Training Set & Dates for Test Set                  & Dates for Test Set                  \\ \hline
Seattle                          & 876      & 241                    & January 1, 2018 -  May 25, 2020 & May 26, 2020 - January 21, 2021 \\
San Francisco                    & 876      & 244                    & January 1, 2018 -  May 25, 2020 & May 26, 2020 - January 24, 2021 \\
Los Angeles                      & 876      & 238                    & January 1, 2018 -  May 25, 2020 & May 26, 2020 - January 18, 2021 \\
Philadelphia                     & 876      & 244                    & January 1, 2018 -  May 25, 2020 & May 26, 2020 - January 24, 2021 \\ \hline
\end{tabular}}  
\end{table} 


\section{Results}

\vspace{2mm}
\lipsum[1-3]\\  


\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .