9

Why won't LaTeX just let me keep things together on one page whenever I want to? Why isn't this straightforward to do? There is this:

Absolutely, definitely, preventing page break.

Maybe that works, always or sometimes, but if so, it's a mess. It is a bad answer, or rather is a good answer to manipulate a seemingly bad or broken system.

I know about \minipage, but like other questioners, I don't want a minipage. I just want a normal page in which normal elements stay together on the same page when I ask them to.

This question has been asked over and over and over again, in one way or another, so I think that I can accept that no really good answer to it exists. By why does no good answer exist?

Is it because there just something fundamentally, internally wrong with TeX?

If so, what is wrong, please?

I do not understand why it should be hard to tell LaTeX to keep certain elements together on the same page. I do not understand why it should be so hard to prevent a page break. Do you?

To me, it looks as though this should be trivial for LaTeX to do.

USE CASE

[Update: Commenters have shown that the below is not a very good illustration of the problem, or of what I perceive to be the problem. Unfortunately, though I have encountered the above problem repeatedly over the years, I do not have a better case at hand at the moment.]

My question is general, because it comes up often in various contexts. However, if you would like to hear about my latest use case as an example: I have a group of six tables which together nearly fill a nice, two-column page. I don't care exactly on which page the tables appear, but the six look a lot better if they are all on the same page. I don't want to do any weird tricks. I just want the six tables—normal, ordinary tables—to stay together.

Why is this so hard?

  • 5
    It is easy: Put your six table together in some box, e.g. a figure environment. – Ulrike Fischer Jan 10 '16 at 20:25
  • @UlrikeFischer: That is a good idea. If you had given it as an answer, I would have upvoted it. The trouble though is that I don't want to enforce any particular formatting on the tables. They can float, as long as they stay on the page. My pages are two-column pages, anyway. But really, I do not seek a special-purpose technique, but a general approach: how can one straightforwardly, without weird tricks, keep any group of elements together? Boxes are boxes, but I do not care about the shape of the box, or even if it is box shaped. I just want my elements not to wander off to separate pages. – thb Jan 10 '16 at 20:36
  • 8
    If you want 6 things to float as one unit then just put all 6 in the same table environment. There is nothing in your question that suggests any problem with latex, just the way you are using it, it seems, but without an example the question isn't really clear enough to say for sure. – David Carlisle Jan 10 '16 at 20:48
  • 4
    If the tables are (together) in one figure or table environment they can float but will stick together. This is not a "weird trick". – Ulrike Fischer Jan 10 '16 at 20:49
  • 1
    Note that the cases that you refer to with your over links are unrelated to the use case that you give later of floating tables together. That is explicitly supported by the design of latex floats. So really you just need to use the environment as documented, no tricks. The questions you refer to are about page breaking in the main text flow where things can be more tricky, and depend on the environment involved, if that has been written to allow page breaking then an environment-specific method may be needed to disable that. – David Carlisle Jan 10 '16 at 20:54
5

As mentioned in comments, if a group of 6 tables are intended to float together then they should be in a single float.

enter image description here

\documentclass[twocolumn]{article}

\def\a{\addtocounter{enumi}{7}\roman{enumi}: One two three four five six seven }
\def\b{\a\a\par\a\a\a\a\par\a\a\a\a\a\a}
\def\c{\b\b Red yellow green blue \a\a\b}
\def\t{\begin{minipage}{.4\textwidth}\centering
\begin{tabular}{cc}
1&2\\3&4\\55&66\\777&888\\9999&aaaaa\\A&B\\X&Y
\end{tabular}\caption{zzzzzz \a\a}
\end{minipage}}

\begin{document}

\c\c

\begin{table*}
\t\hfill \t

\bigskip

\t\hfill \t

\bigskip


\t\hfill \t
\end{table*}

\c\c
\end{document}
4

Use case answer: Assuming that the six tables could really fit in one page of two columns, you can keep things together even if they really are not in the source code. You only need (a) six more or less nearby table floats and (b) use the [p] option to have one page of floats. Example with 4+2 tables in page 1 that are printed together in page 2:

mwe

\documentclass[twocolumn]{article}
\usepackage{lipsum}
\def\Warning#1{\vbox to 3\baselineskip {\vfil\bfseries\huge\sffamily\dotfill\fbox{#1}\vfil}}
\def\TABLE{\begin{table}[p]\centering
\begin{tabular}{|llll|}
\hline
    11 & 12 & 13 & 14\\
    21 & 22 & 23 & 24\\
    31 & 32 & 33 & 34\\
    41 & 42 & 43 & 44\\
    11 & 12 & 13 & 14\\
    21 & 22 & 23 & 24\\
    31 & 32 & 33 & 34\\
    41 & 42 & 43 & 44\\
    11 & 12 & 13 & 14\\
    21 & 22 & 23 & 24\\
    31 & 32 & 33 & 34\\
    41 & 42 & 43 & 44\\
\hline
\end{tabular}
\caption{A Table}
\end{table}}
\begin{document}
\lipsum[1-4]
\Warning{Tables are here ...} \TABLE\TABLE\TABLE\TABLE
\lipsum[5]
\Warning{... and here.} \TABLE\TABLE
\lipsum[6-10]
\end{document}
  • 1
    Lorem ipsum. That's pretty funny. Not a frequent reader at TeX.SE, I had not heard of that package before. Your source-code example merits +3 from me for extreme clarity; alas, only +1 is allowed. So, I double the line \lipsum[1-4], compile, and the tables are on different pages again -- though (for some reason I do not understand) the tables do seem to hold together in columns, rather than pages. – thb Jan 11 '16 at 12:14
  • 2
    @thb In twocolumn mode regard each column as one page (remember that a \newpage could be in fact only a new column) . LaTeX will try to place the floats ASAP in columns ("pages") "only for floats", that is, in the 2 next columns, no matter if first column is the right or the left one. Including 4 paragraph before the table environments, tables are now in the wrong column, because floats can not go back, only forward (except for [t] in the same page/column). So the fix is easy: move the six table environments to some point within the text of the right column of the previous page. – Fran Jan 11 '16 at 14:41
  • why have you got them in different table environments if they need to float together? – David Carlisle Jan 12 '16 at 20:47
  • @DavidCarlisle Because (a) do not use minipages or similar solutions (I understand it was a OP requirement) and (b) you already pointed the one-float solution in the comments, but (c) I thought it worth mentioning also that six floats can be grouped with the [p] option. Of course, we know that in many scenarios LaTeX will choose to do something else, but I think that this is more an advantage than a drawback (in general). On the other hand, if tables/figures are of very different heights could be better a more "modular" solution that coerce their position in a 2 x 3 matrix of minipages. – Fran Jan 13 '16 at 18:54
  • @Fran perhaps but as far as I can tell your answer is what the OP was asking not to do, have separate floats and just hope they land together:-) – David Carlisle Jan 13 '16 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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