[Tex/LaTex] Section name appears after the wrong table

floats

So I am writing a paper in document class article, and my section name (Appendix) appears after the wrong table.

More specifically, I have some tables in "Figures and Tables" section, and I have few more tables in Appendix section. As you can predict, there are no texts in these sections except those in tables. This is what is happening:

Preamble is

\documentclass[letterpaper,11pt]{article}    
\usepackage{tabularx}     
\usepackage{afterpage}     
\usepackage{pdflscape}     
\usepackage[format=hang]{caption}     
\usepackage[justification=centering]{caption}     
\usepackage{subcaption} \usepackage{float} 

\section{Figures and Tables}
\input{table_1.tex}
\input{table_2.tex}
\input{table_3.tex}
\input{table_4.tex}
\section{Appendix}
\input{table_5.tex}
\input{table_6.tex}

Table 2 code is

\begin{landscape}
\advance\hoffset by -2cm 
\advance\voffset by 1cm
\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Something}

\begin{tabular}{l*{8}{c}}


\end{table}
\end{landscape}

Table 4 code is

\begin{table}[htbp]
\centering
\caption{Something}
\begin{tabular}{l  c  c  c  c }
\hline\hline

\end{table}

And, table 5 code is

\begin{table}[H]
\centering
\caption{something\label}
\begin{tabular}{l  c  c  c  c }
\hline\hline

\end{table}

I want the "Appendix" to appear after table 4 but it appears after table 2. Table 2 is a landscape table (define in table_2.tex}.

When I change table 4 to landscape, then Appendix appears right after table 4 which is what I want. But I can not have table 4 in landscape as it is a long table.

Can anybody suggest how to fix it? I did try \pagebreak, \newpage and \vspace options but they didn't work. Thanks!

I used the float package, and I am used table environment with [H] option, some of the tables are still used with [htbp] option. Now Appendix appears after table 4 which is what I want. But there are two problems now. First, page after table 2 (the landscape one) is blank. And, table 4 (the one before the Appendix) is out of the page. It looks like float package has some effect here.

Best Answer

There are several methods to deal with float placement control, see the comments to the question, e.g.:

  • Comment of Ludovic C.: Package float with placement specifier H sets the floats right "here" without floating.
  • Comment of David Carlisle: \clearpage before \section{Appendix} forces the floats to be output and starts a new page.
  • My comment: \FloatBarrier of package placeins right before \section{Appendix} stops tables from floating past the appendix title.
  • If a section contains only floats without text, then floating is not really needed. The Float captions can be set without the floating environments (e.g., table) with \captionof{table} of package capt-of or the more powerful caption.