0
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{caption}

\title{Table Test}


\begin{document}

\maketitle

\begin{center}
\hskip 0.5 cm \begin{tabularx}{100pt}{c|c|c|}
\multicolumn{1}{c}{ } &\multicolumn{1}{c}{$D$} &\multicolumn{1}{c}{$R$} \\ \cline{2-3}
$D$ & $\frac{6}{15}$ & $\frac{4}{15}$  \\ \cline{2-3}
$R$ & $\frac{4}{15}$ & $\frac{1}{15}$   \\ \cline{2-3}
\end{tabularx}
\begin{tabularx}{100pt}{c|c|c|}
\multicolumn{1}{c}{ } &\multicolumn{1}{c}{$D$} &\multicolumn{1}{c}{$R$} \\ \cline{2-3}
$D$ & $\frac{1}{15}$ & $\frac{4}{15}$  \\ \cline{2-3}
$R$ & $\frac{4}{15}$ & $\frac{6}{15}$   \\ \cline{2-3}
\end{tabularx}\vskip 0.5cm

$\omega_1$ \hskip 3cm $\omega_2$
\vskip .7cm
\captionof{table}{Blabla}
\end{center}

\end{document}

I have an impression that float can solve this problem. But I thought it is used with table environment which I am not using. Thank you for your help!

3
  • 2
    a table environment is how you specify a float. That allows latex to adjust the position to avoid bad space at page breaks. If you choose not to allow floating you need to adjust the position by hand after you have written the surrounding text so it appears at a good place. Commented Jun 16, 2022 at 14:35
  • 2
    never do \begin{tabularx}{100pt}{c|c|c|} a tabularx must always have at least one X column, but here just use a standard tabular you should not use tabularx for such a table. Commented Jun 16, 2022 at 14:47
  • It is not a clean solution but with the placeins package you can define a float barrier that tells LaTeX to print the floats.
    – mab0189
    Commented Jun 18, 2022 at 0:02

1 Answer 1

1

Your table in center environment stay on page where are inserted if there is sufficient space for it. If it is not, than it is pushed to the next page but left empty space on page before.

This space, as explained @David Carlisle in his comments, can be filled by text after table inserting point, if you use table float environment:

\documentclass{article}
\usepackage{tabularray}
\usepackage{caption}

\title{Table Test}
\author{Me}


\begin{document}

\maketitle

\begin{table}[ht]
\centering
    \begin{tblr}{hline{2-Z} = {2-Z}{solid},
                 vline{2-Z} = {2-Z}{solid},
                    colspec = {*{3}{Q[c, mode=math]}}
                }
    & D   &   R                     \\ 
D & \frac{6}{15} & \frac{4}{15}    \\ 
R & \frac{4}{15} & \frac{1}{15}     \\  
    \end{tblr}

\medskip
    \begin{tblr}{hline{2-Z} = {2-Z}{solid},
                 vline{2-Z} = {2-Z}{solid},
                    colspec = {*{3}{Q[c, mode=math]}}
                }
    & D   &   R                     \\
D & \frac{6}{15} & \frac{4}{15}    \\
R & \frac{4}{15} & \frac{1}{15}     \\
    \end{tblr}

$\omega_1$ \hspace{3cm} $\omega_2$
\caption{Blabla}
\end{table}

\end{document}

For your table I suggest to use tabularray package. Using it, table is nicer (cells contents doesn't touch horizontal lines) and code is a bit shorter and clearer.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .