2

I am doing the final layouting pass on a book, and while LaTeX does "the right thing" most of the time, and the occassional ugliness can be tweaked with minor touches to the text, there are cases where I feel there is no alternative to forcing LaTeX's hand.

The case I am looking at right now are three tables, which need to be close together due to context, and basically would fill a complete page on their own.

However, LaTeX basically insists that three tables on one page look bad, and spreads them over multiple pages.

How could I force those tables to be on the same page?

Stating \begin{table}[h] doesn't work. (LaTeX apparently simply ignores the setting.)

Putting the tables into individual cells of a page-sized table ("the HTML way") doesn't work, because I cannot put captions and labels to them properly that way.

Attached is a much dumbed-down version of the problem as a kind of MWE. I used scrbook as documentclass because that's what the original document is in, and changing that (or the twocolumn layout) is not an option.

\documentclass[paper=a4,fontsize=10pt,twocolumn]{scrbook}

\usepackage{lipsum}
\usepackage{tabularx}

\begin{document}

\lipsum[1]

\begin{table}
\caption{Tab 1}
\begin{tabularx}{\columnwidth}{|X|}
\hline
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\hline
\end{tabularx}
\end{table}

\lipsum[2]

\begin{table}
\caption{Tab 2}
\begin{tabularx}{\columnwidth}{|X|}
\hline
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\hline
\end{tabularx}
\end{table}

\lipsum[3]

\begin{table}
\caption{Tab 3}
\begin{tabularx}{\columnwidth}{|X|}
\hline
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\hline
\end{tabularx}
\end{table}

\end{document}
  • 1
    If they realy fit in/on one page, put all tabulars and captions inside a single table-environment. Using p as placement specifier to all tables might also work. Using a twocolumn document is a bit more difficult tough, and needs extra manual work. – Johannes_B Sep 16 '14 at 8:59
  • I cannot believe I missed out on the [p] positional specifier. It indeed did the trick just like that. Feel welcome to turn that into an answer. – DevSolar Sep 16 '14 at 9:05
5

If you really want to have the tables together on one page, cheat a bit. Put all the material in a single table-environemt. That means you need to put the stuff between the tables either in front or after them. Here as a quick example.

\documentclass[twocolumn,paper=a4,fontsize=11pt,captions=tableabove]{scrbook}

\usepackage{showframe}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{tabularx}
\colorlet{tablegray}{gray!50!white}
\newcommand{\faketable}[1]{{\color{tablegray}\rule{\linewidth}{.#1\textheight}}}
\begin{document}

\lipsum[1-2]

Now we are using a twocolumn, floating environment and put all
tables and all captions inside. This is hardwired, LaTeX will
float the *whole container* around. This might need some
readjustments.

\begin{table*}
    \begin{minipage}{0.45\textwidth}
        \caption{I am das duck}
        \faketable{3}
        \bigbreak
        \caption{I am the penguin}
        \faketable{5}
    \end{minipage}
    \hfill
    \begin{minipage}{.45\linewidth}
        \caption{I bin das Walross}
        \faketable{8}
    \end{minipage}
\end{table*}

\lipsum[2]
\lipsum[3]
\end{document}

Here is what pdflatex will give you:

Page 1 Page 2

  • Could it be that you accidently posted the original MWE again instead of your answer? – Gilean0709 Sep 16 '14 at 9:10
  • @Gilean0709 Yes, i did. Sorry. I was already heading for lunch. I am going to have a look at this this eveniing and extend my answer a bit. – Johannes_B Sep 16 '14 at 12:28
  • @Johannes_B any chance for an update/extension? ;-) – Paul Gessler Feb 16 '15 at 7:06
  • @PaulGessler Oh, forgot about that. Give me a bit of time. – Johannes_B Feb 16 '15 at 13:24

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.