1

I am constructing a report with multiple tables, but these tables keeps floating to the next page even when is small enough to fit under a text on one page. What can i do? Below is the code i am using. Thanks in advance.

\documentclass[openany]{book}


\usepackage[USenglish]{babel} 
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}

\usepackage{lmodern} 
\usepackage{url}             
\usepackage[hyperref,dvipsnames]{xcolor}
\usepackage[a4paper,pdftex]{geometry}    
\usepackage{fix-cm}             
\usepackage{fancyhdr, blindtext}     
\usepackage{graphicx}
\usepackage[colorlinks=true,% 
            linkcolor=blue,%
            citecolor=blue]{hyperref} 

\usepackage[Sonny]{fncychap}     


\usepackage{graphicx} %%For loading graphic files

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage[toc,page]{appendix}

\usepackage[utf8]{inputenc}

\setlength{\arrayrulewidth}{0.5mm}
\setlength{\tabcolsep}{8pt}
\renewcommand{\arraystretch}{1.5}
\usepackage[english]{babel}    
\addto\captionsenglish


\begin{document}
\begin{table}
    \begin{tabular}{ |p{3cm}||p{3cm}|p{3cm}|p{3cm}|  }
     \hline
     \multicolumn{4}{|c|}{Country List} \\
     \hline
     Country Name     or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 Code&ISO numeric Code\\
     \hline
     Afghanistan   & AF    &AFG&   004\\
     Aland Islands&   AX  & ALA   &248\\
     Albania &AL & ALB&  008\\
     Algeria    &DZ & DZA&  012\\
     American Samoa&   AS  & ASM&016\\
     Andorra& AD  & AND   &020\\
     Angola& AO  & AGO&024\\
     \hline
    \end{tabular}
\end{table}
Gonzalo Medina
  • 505,128
Reynolds
  • 11
  • 3

2 Answers2

1

Not sure I understand your objective, but it sounds like you may want to use a longtable environment, which (a) doesn't "float and (b) can break across pages if necessary. In contrast, a table environment will occasionally "float" to the following page, but it'll never break across pages.

Some additional comments about your code, listed in no particular order:

  • If you load the fix-cm package, it should be loaded at the very start of the document, i.e., before the \documentclass instruction. However, since your code loads the lmodern font family, there's really no point in loading fix-cm to begin with.

  • Don't load packages multiple times (e.g., babel), especially not with incompatible options (e.g., inputenc, which is first loaded with the option ansinew and later with the option utf8).

  • Since you use unusually thick lines, it's a good idea to load the array package to even out the intersections between vertical and horizontal lines at the edges of the table.

enter image description here

%%\RequirePackage{fix-cm} % not needed since "lmodern" package is used
\documentclass[openany]{book}


\usepackage[english]{babel} 
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{lmodern} 
\usepackage{url}             
\usepackage[hyperref,dvipsnames]{xcolor}
\usepackage[a4paper]{geometry}    
\usepackage{fancyhdr}     
\usepackage{graphicx}

\usepackage[Sonny]{fncychap}     


\usepackage{amsmath,amsthm,amsfonts}
\usepackage[toc,page]{appendix}

\setlength{\arrayrulewidth}{0.5mm}
%\setlength{\tabcolsep}{8pt}
\renewcommand{\arraystretch}{1.5}

\usepackage{longtable,array,ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}

\usepackage[colorlinks=true,% 
            linkcolor=blue,%
            citecolor=blue]{hyperref} 

\begin{document}

\begin{longtable}{ |P{2.7cm}|P{3.2cm}|P{3.2cm}|P{3.2cm}|  }
%% headers and footers
     \hline
     \multicolumn{4}{|c|}{Country List} \\
     \hline
     Country Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 Code&ISO numeric Code\\
     \hline
\endfirsthead
     \hline
     \multicolumn{4}{|c|}{Country List, continued} \\
     \hline
     Country Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 Code&ISO numeric Code\\
     \hline
\endhead
     \hline
\endfoot
%% body of table follows
     Afghanistan   & AF    &AFG&   004\\
     Aland Islands &   AX  & ALA   &248\\
     Albania       &AL & ALB&  008\\
     Algeria       &DZ & DZA&  012\\
     American Samoa&   AS  & ASM&016\\
     Andorra       & AD  & AND   &020\\
     Angola        & AO  & AGO&024\\
\end{longtable}

\end{document}
Mico
  • 506,678
-1

hey friend use position specified after \begin{table} or \begin{longtable}. here it is:

  • H - it places your table where you put in .tex file on the same page
  • hp! - it places where you mentioned if there is no space just after text, it tries to place it somewhere else but on the same page.
\begin{table}[H]
\caption{Notations used in our work}
\label{tab:1}       % Give a unique label
\begin{tabular}{c p{6.5cm}}
\end{tabular}
\end{table}
Torbjørn T.
  • 206,688
ANUJ SINGH
  • 137
  • 6
  • 2
    Your answer is incomplete. H is not a default float specifier, it is only available if you load the float package. With hp! the table will be placed where you put it or on a separate page. Finally, as Mico mentions in his answer, longtable doesn't float, so float specifiers are pointless. – Torbjørn T. Jun 20 '15 at 07:25