2

I followed the approach outlined in this answer to place two tables (and also figures and tables) beside each other. Unfortunately if the height of one of the two floats is greater than the other one the captions are no longer aligned.

Image and MWE of this problem below: enter image description here MWE

\documentclass[ngerman]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\usepackage{tabularx} \usepackage{booktabs} \begin{document}

\begin{table}[!htb] \begin{minipage}{.49\textwidth} \centering \label{tab:state0_eval_sarsa} \caption{Bewertung State 0 \ bester Sarsa Agent} \begin{tabular}{lr} \toprule Aktion & Bewertung \ \midrule 0 & -0,0283 \ 1 & -0,0258 \ 2 & -0,0223 \ 3 & -0,0272 \ 4 & 0,0019 \ 5 & -0,0218 \ 6 & -0,0337 \ 7 & -0,0394 \ 8 & -0,0274 \ \bottomrule \end{tabular} \end{minipage}% \begin{minipage}{.49\textwidth} \centering \caption{Bewertung Aktionsklassen State 0 bester Sarsa Agent} \label{tab:state0_eval_sarsa_aggregated} \begin{tabular}{lr} \toprule Aktion & Bewertung \ \midrule Ecke & -0,0279 \ Kante & -0,0286 \ Mitte & 0,0019 \ \bottomrule

    \end{tabular}
\end{minipage}

\end{table}

\end{document}

legnib
  • 77

3 Answers3

4

Use \begin{minipage}[t]{<width>} The optional argument t puts the contents at the top of the box.

d

The \hfill between the minipages pushes the tables to the left and right edge of the text area.

\documentclass[ngerman]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\usepackage{tabularx} \usepackage{booktabs}

\usepackage{kantlipsum}% to add dummy text

\begin{document}

\kant[1]

\noindent\begin{table}[!htb]
    \begin{minipage}[t]{.45\textwidth}
        \centering
        \label{tab:state0_eval_sarsa}
        \caption{Bewertung State 0 \\ bester Sarsa Agent}
        \begin{tabular}{lc}
            \toprule
            Aktion  &amp; Bewertung \\ \midrule
            0   &amp; -0,0283 \\
            1   &amp; -0,0258 \\
            2   &amp; -0,0223 \\
            3   &amp; -0,0272 \\
            4   &amp; 0,0019  \\
            5   &amp; -0,0218 \\
            6   &amp; -0,0337 \\
            7   &amp; -0,0394 \\
            8   &amp; -0,0274 \\ \bottomrule
        \end{tabular}
    \end{minipage}\hfill%
    \begin{minipage}[t]{.45\textwidth}
        \centering
        \caption{Bewertung Aktionsklassen State 0 bester Sarsa Agent}
        \label{tab:state0_eval_sarsa_aggregated}
        \begin{tabular}{lc}
            \toprule
            Aktion  &amp; Bewertung \\ \midrule
            Ecke    &amp; -0,0279 \\
            Kante   &amp; -0,0286 \\
            Mitte   &amp;  0,0019 \\ \bottomrule                
        \end{tabular}
    \end{minipage}
\end{table}

\kant[1]

\end{document}

Simon Dispa
  • 39,141
4

Here is a solution with the floatrow package. I also loaded siunitx to have a better formatting of the numbers in the right column.

\documentclass[ngerman]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{floatrow}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{table}[!htb] \sisetup{table-format=-1.4} %\captionsetup{format=plain} \begin{floatrow} \ttabbox[1.4\FBwidth]{\caption{Bewertung State 0 \ bester Sarsa Agent}\label{tab:state0_eval_sarsa}} {\begin{tabular}{lS} \toprule Aktion & {Bewertung} \ \midrule 0 & -0,0283 \ 1 & -0,0258 \ 2 & -0,0223 \ 3 & -0,0272 \ 4 & 0,0019 \ 5 & -0,0218 \ 6 & -0,0337 \ 7 & -0,0394 \ 8 & -0,0274 \ \bottomrule \end{tabular}} \captionsetup{format=plain} \ttabbox[1.5\FBwidth]{\caption{Bewertung Aktionsklassen State 0 bester Sarsa Agent} \label{tab:state0_eval_sarsa_aggregated}} {\begin{tabular}{lS} \toprule Aktion &{ Bewertung} \ \midrule Ecke & -0,0279 \ Kante & -0,0286 \ Mitte & 0,0019 \ \bottomrule \end{tabular}} \end{floatrow} \end{table}

\end{document}

enter image description here

Bernard
  • 271,350
  • Thank you for sharing this solution and also for the inclusion of siunitx package. I will look into it and use it in the future. I decided to accept Simon's answer as it solved the problem without using another package. – legnib Feb 28 '22 at 22:28
2

Bottom align of two tables.

\documentclass{article}
\usepackage{subfig}

\begin{document}

\begin{figure}
    \centering
    \subfloat[]{%
        \begin{tabular}[b]{c|cc}
            a &amp; b &amp; c\\
            \hline
            1 &amp; 2 &amp; 3\\
            x &amp; y &amp;z\\
            \hline
    \end{tabular}}\qquad
    \subfloat[]{%
        \begin{tabular}[b]{cc}

            1 &amp; 2\\
            \hline
            x &amp; y\\
            a &amp; b\\
            A &amp; B\\
            \hline
    \end{tabular}}
\end{figure}

\end{document}

enter image description here