0

I have a latex file with a 'longtable' in it, which spans a couple of pages. I added a new figure earlier in the document, and now, the figure appears in the middle of my longtable - i.e. it splits it in two. Obviously I don't want this to happen.

I am having difficulty supplying a MWE, because the text and figures are part of an academic document which I cannot share, but when I remove parts of the text, everything gets shuffled around and the problem goes away.

Any advice would be great.

  • 2
    Figures you can replace with example-image provided by package graphics, instead real text you can use \lipsum` from package lipsum. Without seeing the MWE, which show your problem is difficult to help you. Wild guess: see if figure option [!ht] can help, or option [H]` – Zarko Jul 26 '17 at 13:49
  • 3
    \clearpage will force the figure to print immediately (and start a new page). You can turn off top floats temporarily using \def\topfraction{0} inside a group. – John Kormylo Jul 26 '17 at 15:21
  • Did you try the suggestions of Zarko and John Kormylo? Can you give some feedback? If you need more fine control over the text length then \lipsum, try either different paragraphs if lipsum \lipsum[2] or just copy and paste text as often as needed - but without seeing some code that produces the problem, its really hard to try to help you. – user36296 Jul 29 '17 at 18:46
  • 2
    I would also suggest trying to supply an MWE with dummy text, dummy figures and dummy data in the table, otherwise recreating the problem in this instance is close to impossible. For dummy table data, you could use a free only service like mockaroo, which is able to generate realistic data that can easily be exported. From a CSV export to a LaTeX table is as easy as automatically replacing "," with " & " and "\n" with "\\\n". How text and figures can be replaced was already covered in the previous comments. – Big-Blue Jul 29 '17 at 21:00
1
+50

You could use the package float and use the H option.

\usepackage{float}
...
\begin{documment}
    \begin{figure}[H]
        your figure
    \end{figure}
\end{document}

this option makes the figure to not float, but stay where it was in your code

  • Hmm, when I did that, the figure just didn't appear at all. Is it possible that it's overlapped by the table? – user1551817 Jul 29 '17 at 19:40
  • Oh yeah I had {figure*} - when I removed the asterisk, the figure appeared, but it was only partially only the page and it was overlaid by the main text of the document. – user1551817 Jul 29 '17 at 19:42
  • 1
    is the figure big? is there anything between the figure and the table? – geekformoney Jul 29 '17 at 19:43
  • Yeah, the figure is about 2/3 the height of the page. There is the figure, then a bunch of text (in the tex document) and then the table. – user1551817 Jul 29 '17 at 21:58
  • 2
    try to add an example using the lipsum package, which produces a long dummy text, an image big like yours and a table long like yours. I think this is a problem with the alignment os the text. is it inside a multicols, minipage, parbox, or something else? are you using the wrapfig environment? – geekformoney Jul 29 '17 at 22:09
0

If the image is before the table, a call to \clearpage will force all images that come before the call to print ensuring that any previous images won't interfere with your table.

Not the answer you're looking for? Browse other questions tagged or ask your own question.