5

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. longtable problem

5
  • 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? Commented Jul 22, 2014 at 9:14
  • please always make your code sections complete documents so people can reproduce the error. Commented Jul 22, 2014 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. Commented Jul 22, 2014 at 9:21
  • @DavidCarlisle I can't see an incorrect markup so I added an image of what is going on. Commented Jul 22, 2014 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? Commented Jul 22, 2014 at 9:41

1 Answer 1

6

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?

5
  • Then I've got the problem pictured on a screenshot that I added to my post. Commented Jul 22, 2014 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). Commented Jul 22, 2014 at 9:43
  • @ArtemPelenitsyn I edited the answer Commented Jul 22, 2014 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). Commented Jul 22, 2014 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. Commented Jul 22, 2014 at 10:25

You must log in to answer this question.

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