# How to combine ‘float’ and ‘longtable’ packages functionality

I want to use exact placement for my table. As I read on SO it can be done with [H] option for table environment provided by ‘float’ package. But this doesn't seem to work with longtable which I have to use due to the fact that my table is really long.

What I tried so far

% Preamble
\usepackage{longtable}
\usepackage{float}
\restylefloat{longtable} % as \restylefloat{table} doesn't take effect

…

% Long table
\begin{longtable}[H]{| c | c | c | c |}
\hline
1        & 5 & 6 & 7  \\ \hline
1        & 5 & 6 & 7  \\ \hline
1        & 5 & 6 & 7  \\ \hline
% and so on, many rows
\end{longtable}


This gives me a bunch of errors like

Misplaced \noalign. [\hline]
Misplaced alignment tab character &. [1          &]


Maybe there are some other ways to get desired behaviour of longtable?

EDIT: I add the screenshot of exact problem with longtable placement. In short: it is placed before the paragraph, while I wrote it after.

-
tables will never move unless you ask them to move by surrounding them with begin{table} which makes them float. longtable never moves at all. So what problem are you trying to solve? – David Carlisle Jul 22 '14 at 9:14
please always make your code sections complete documents so people can reproduce the error. – David Carlisle Jul 22 '14 at 9:16
@DavidCarlisle I use \paragraph{Title} then longtable. The table is placed before the paragraph title and that's not what I expect. – Artem Pelenitsyn Jul 22 '14 at 9:21
@DavidCarlisle I can't see an incorrect markup so I added an image of what is going on. – Artem Pelenitsyn Jul 22 '14 at 9:35
Please always make a complete document that demonstrates the problem, don't post incomplete fragments or images of code. \paragraph is an inline heading, the heading is added to the first line of the following paragraph so you may need to use \mbox{} after the heading, but why are you using an inline heading there? – David Carlisle Jul 22 '14 at 9:41

As clarified in comments the problem is unrelated to floating environments.

\documentclass{article}
\usepackage{longtable}

\begin{document}

\paragraph{zz}

\begin{longtable}{| c | c | c | c |}
\hline
1        & 5 & 6 & 7  \\ \hline
1        & 5 & 6 & 7  \\ \hline
1        & 5 & 6 & 7  \\ \hline
% and so on, many rows
\end{longtable}

aa

\end{document}


\paragraph is an inline heading (designed to be used after \subsubsection) the heading is held back and added to the first line of the following paragraph.

longtable does not start a paragraph so the heading gets added to aa.

To fix this add an empty paragraph

\documentclass{article}
\usepackage{longtable}

\begin{document}

\paragraph{zz}
\mbox{}%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

\begin{longtable}{| c | c | c | c |}
\hline
1        & 5 & 6 & 7  \\ \hline
1        & 5 & 6 & 7  \\ \hline
1        & 5 & 6 & 7  \\ \hline
% and so on, many rows
\end{longtable}

aa

\end{document}


But are you sure you want an inline rather than a display heading in this context?

-
Then I've got the problem pictured on a screenshot that I added to my post. – Artem Pelenitsyn Jul 22 '14 at 9:36
@ArtemPelenitsyn that is why every question should have a complete document that demonstrates the problem (which is unrelated to floats in this case). – David Carlisle Jul 22 '14 at 9:43
@ArtemPelenitsyn I edited the answer – David Carlisle Jul 22 '14 at 9:49
Thank you very much, it works! This “empty mbox”-weird things I encountered them a couple of times… Never understand why tables don't start paragraph (unless you use table environment and got floating which is the whole another story). – Artem Pelenitsyn Jul 22 '14 at 10:19
I need inline variant for the sake of consistensy. I have a text, where some paragraphs must have numbers and optional titles, both inline. But some paragraphs, as you see, have number, title and display table right after it. – Artem Pelenitsyn Jul 22 '14 at 10:25