TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a tabular environment and some associated text. Now, I don't want to use this text as the caption for various reasons and I want to make sure that they are always on the same page, or that the text at least comes on the same page as the beginning of the table.

Is there any way to force this to occur without specifying exactly how large the table (or related types of content one might be trying to associate) is?

share|improve this question
I assume by "caption" you're referring to the fact that you want the "associated text" to "go" with the "tabular environment." If this is the case, and the location of the "associated text" is known, boxing them seems to be the option. You can either do this using a minibox environment (with a fixed/full width of \linewidth) or perhaps a varwidth environment from the varwidth package. varwidth is like minipage, but allows to shrink to the content's natural width. If this does not seem to be an option, please elaborate on your requirement. – Werner Nov 3 '11 at 20:27
Have a look at my answer to this post – cmhughes Nov 3 '11 at 21:48

Since you're not sure about specifying a width, you can box the tabular content and let LaTeX extract the width. Here is such an approach:

Boxing the tabular is performed using the lrbox environment:

\begin{lrbox}{<box cmd>}

where <box cmd> is defined using \newsavebox{<box cmd>}. In my MWE (see below), I've used \mytabular. Then you can box the entire contents of the "keep stuff together" inside a minipage of width \linewidth. This way it will stretch the entire text block width, even though you might only use a portion of it.

The width of the boxed tabular \mytabular is accessed using \wd\mytabular (similarly, \ht\mytabular would be the height, while \dp\mytabular would be the depth). With the tabular saved, \usebox{\mytabular} typesets it.

enter image description here

%\usepackage{varwidth}% http://ctan.org/pkg/varwidth
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\newsavebox{\mytabular}% Capture a tabular in a box
\lipsum[1-4]% dummy text
  \begin{lrbox}{\mytabular}% Store tabular in \mytabular
      Heading 1 & Heading 2 & Title & Heading 3 & Heading 4 \\ \hline
      stuff & stuff & some more stuff & stuff & stuff \\
      stuff & stuff & some more stuff & stuff & stuff \\
      stuff & stuff & some more stuff & stuff & stuff \\ \hline

    \usebox{\mytabular}% Print tabular

    \lipsum[1]% dummy text/"caption"
  \end{minipage} \par
  \kern\textfloatsep% Make this seem like a "float"
\lipsum[5-9]% dummy text

Modifications to the width of the "caption" and the vertical gap below the "caption" is possible.

I've commented out the varwidth package since it's use does not seem required here. However, if your request is modified, it might be.

share|improve this answer
What happens, if it is a very long text and and maybe also a long table? This is one of these questions that cannot be answered unless the constraints are specified. – Yiannis Lazarides Nov 3 '11 at 21:11
I agree. It seems very particular to a specific instance of the table. Perhaps using longtable if the table is too long, boxing (as I suggested) if it is not. Also, how is the content around it treated - the left-over white space from page breaking, for example. – Werner Nov 3 '11 at 21:15
Better algo, Combine the minipage+tabular in the lrbox, measure height, if it exceeds the page size, use longtable plus emit message in the log, if it is within say 70% of pageheight float on own page etc. Consider minipage material to be inserted in multicolumn at bottom of tabular. – Yiannis Lazarides Nov 3 '11 at 21:34

I assume the "associated text" materials are explanatory in nature, so they should go below the tabular(x,y) environment. If you place them below the \end{tabular} statement but before the \end{table} statement, you'll get exactly what you're looking for.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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