Take the 2-minute tour ×
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.

Sometimes, table cannot locate itself properly inside my document and I don't know how to fix this.

Here is an example:

The current page which the table cannot locate itself properly in looks like as follows:

enter image description here

As you can see, there is too much space in between.

The previous and next pages look like this (left one is previous and the right one is the next page):

enter image description here enter image description here

The documentclass is book and the table code is as follows:

\begin{center}
\begin{tabular}{ p{4cm} p{5cm}  p{6cm} }
%\hline
\cellcolor[gray]{0.9} Foo1 Title & \cellcolor[gray]{0.9}Foo2 Title & \cellcolor[gray]{0.9} Foo3 Title \\ \hline
Foo & Foo & Foo Bar bla bla bla...\\
Foo & Foo & Foo Bar bla bla bla...\\[5pt]

\hline
\end{tabular}

Table xxx: Foo Caption 
\end{center}

Figures can do this very properly. If the space is not enough inside the page, then the image puts itself in the next page but the space in the current page filled with text or something else.

Any idea how can I can fix this problem so that tables can locate themselves properly?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

The reason your figure environments behave the way you describe is that they are floats. The tabular environment is not a float.

To achieve the desired behaviour, you should wrap your tabular environments within the table environment, which does float.

\begin{table}[htbp]
\centering
\caption{Table caption goes here}
\begin{tabular}
...
\end{tabular}
\end{table}

Note that I've used \centering and not \begin{center}...\end{center} which adds extra vertical space.

You can change the htbp to suit your desired placement of floats. For further reading, have a look at

share|improve this answer
    
I am having one other problem with this one: I have also lstlisting blocks and they can sometimes go into two pages. If I follow the above style that u have suggested, table goes inside the lstlisting block if the listing block occupies two pages. Any chance I can fix this? –  tugberk May 9 '12 at 12:31
2  
@tugberk that's really a separate question :) however, the placeins package provides the command \FloatBarrier which you could put before your lstlisting environments –  cmhughes May 9 '12 at 12:44
    
Thanks for the tip. I will try that. –  tugberk May 9 '12 at 12:47

Your Answer

 
discard

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.