3

What I would like to create are two tables side by side, each with its own caption above the table. This is my attempt

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath,amssymb,amsfonts,systeme}
\usepackage{makecell}
\setcellgapes{5pt}
\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}

\begin{document}

\begin{table}[H]
\centering
\makegapedcells
\begin{tabular}{| *{7}{>{\centering\arraybackslash}p{1.5cm} |}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 22.727 & 22.272 & 1.0204 \\ \hline
25 & 17.962 & 17.670 & 1.0165 \\ \hline
30 & 14.416 & 14.234 & 1.0127 \\ \hline
35 & 11.631 & 11.528 & 1.0090 \\ \hline
40 & 9.8771 & 9.8264 & 1.0052 \\ \hline
45 & 9.1780 & 9.1658 & 1.0013 \\ \hline
50 & error & error & error \\ \hline
\caption{$x_1 = 0.4$}
\end{tabular}
\end{table}
\quad
\begin{table}[H]
\centering
\makegapedcells
\begin{tabular}{| *{7}{>{\centering\arraybackslash}p{1.5cm} |}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 39.976 & 37.827 & 1.0568 \\ \hline
25 & 30.827 & 29.273 & 1.0531 \\ \hline
30 & 24.157 & 23.027 & 1.0491 \\ \hline
35 & 19.205 & 18.373 & 1.0453 \\ \hline
40 & 15.486 & 14.867 & 1.0417 \\ \hline
45 & 12.577 & 12.115 & 1.0381 \\ \hline
50 & error & error & error \\ \hline
\caption{$x_1 = 0.5$}
\end{tabular}
\end{table}

\end{document}

enter image description here

As you can see, the caption is an unusual position, and the tables are not positioned next to each other

Can you help me?

Thank you in advance

  • Unless you change the margins or the widths of the table cells, your tables won't fit next to each other. – leandriis Jun 8 at 10:58
  • Unrelated to the question, but why did you put the \caption command inside the tabular environment? – leandriis Jun 8 at 11:00
6

Here are two possibilities:

I have moved the \caption command from inside the tabular environment to right before \begin{tabular} so there is no need to use \restylefloat. I have also drastically reduced the margins in order to make the two tables fit into the textwidth. Lastly, I have also changed the column specifiers from 7 to 4 as you only need four columns in your tables. In order to position the tables next to each other, put them in the same table environment and each of the tabulars inside of an own minipage environment.

Since you used the option [H] to place the table exactly where is was defined in the code, I have added the second example. In this I have completely removed the table environment and used \captionof{table} from the caption package instead.

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath,amssymb,amsfonts,systeme}
\usepackage{makecell}
\setcellgapes{5pt}
\usepackage{float}
%\floatstyle{plaintop}
%\restylefloat{table}
\usepackage{caption}
\usepackage[margin=1.5cm]{geometry}

\begin{document}

\begin{table}
\begin{minipage}{0.5\textwidth}
\centering
\makegapedcells
\caption{$x_1 = 0.4$}
\begin{tabular}{| *{4}{>{\centering\arraybackslash}p{1.5cm} |}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 22.727 & 22.272 & 1.0204 \\ \hline
25 & 17.962 & 17.670 & 1.0165 \\ \hline
30 & 14.416 & 14.234 & 1.0127 \\ \hline
35 & 11.631 & 11.528 & 1.0090 \\ \hline
40 & 9.8771 & 9.8264 & 1.0052 \\ \hline
45 & 9.1780 & 9.1658 & 1.0013 \\ \hline
50 & error & error & error \\ \hline
\end{tabular}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering
\makegapedcells
\caption{$x_1 = 0.5$}
\begin{tabular}{| *{4}{>{\centering\arraybackslash}p{1.5cm} |}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 39.976 & 37.827 & 1.0568 \\ \hline
25 & 30.827 & 29.273 & 1.0531 \\ \hline
30 & 24.157 & 23.027 & 1.0491 \\ \hline
35 & 19.205 & 18.373 & 1.0453 \\ \hline
40 & 15.486 & 14.867 & 1.0417 \\ \hline
45 & 12.577 & 12.115 & 1.0381 \\ \hline
50 & error & error & error \\ \hline
\end{tabular}
\end{minipage}
\end{table}


\noindent
\begin{minipage}{0.5\textwidth}
\centering
\makegapedcells
\captionof{table}{$x_1 = 0.4$}
\begin{tabular}{| *{4}{>{\centering\arraybackslash}p{1.5cm} |}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 22.727 & 22.272 & 1.0204 \\ \hline
25 & 17.962 & 17.670 & 1.0165 \\ \hline
30 & 14.416 & 14.234 & 1.0127 \\ \hline
35 & 11.631 & 11.528 & 1.0090 \\ \hline
40 & 9.8771 & 9.8264 & 1.0052 \\ \hline
45 & 9.1780 & 9.1658 & 1.0013 \\ \hline
50 & error & error & error \\ \hline
\end{tabular}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering
\makegapedcells
\captionof{table}{$x_1 = 0.5$}
\begin{tabular}{| *{4}{>{\centering\arraybackslash}p{1.5cm} |}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 39.976 & 37.827 & 1.0568 \\ \hline
25 & 30.827 & 29.273 & 1.0531 \\ \hline
30 & 24.157 & 23.027 & 1.0491 \\ \hline
35 & 19.205 & 18.373 & 1.0453 \\ \hline
40 & 15.486 & 14.867 & 1.0417 \\ \hline
45 & 12.577 & 12.115 & 1.0381 \\ \hline
50 & error & error & error \\ \hline
\end{tabular}
\end{minipage}


\end{document}

If you don't want to decrease the margins, you might want to consider decreasing the column width. You could for example use c tpe columns. With this column type, both tables will easily fit next to each other in the standard text width of the article documentclass. Personally, I'd prefer tables with less lines, so in the following MWE, I have als included an example on how to achieve that, using the booktabs package. (If you'd also like to align the numbers with respect to the decimal separator, you might want to have a look into the siunitx or the dcolumn package.)

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath,amssymb,amsfonts,systeme}
\usepackage{makecell}
\setcellgapes{5pt}
\usepackage{booktabs}

\begin{document}

\begin{table}
\begin{minipage}{0.5\textwidth}
\centering
\makegapedcells
\caption{$x_1 = 0.4$}
\begin{tabular}{| *{4}{c|}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 22.727 & 22.272 & 1.0204 \\ \hline
25 & 17.962 & 17.670 & 1.0165 \\ \hline
30 & 14.416 & 14.234 & 1.0127 \\ \hline
35 & 11.631 & 11.528 & 1.0090 \\ \hline
40 & 9.8771 & 9.8264 & 1.0052 \\ \hline
45 & 9.1780 & 9.1658 & 1.0013 \\ \hline
50 & error & error & error \\ \hline
\end{tabular}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering
\makegapedcells
\caption{$x_1 = 0.5$}
\begin{tabular}{| *{4}{c|}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 39.976 & 37.827 & 1.0568 \\ \hline
25 & 30.827 & 29.273 & 1.0531 \\ \hline
30 & 24.157 & 23.027 & 1.0491 \\ \hline
35 & 19.205 & 18.373 & 1.0453 \\ \hline
40 & 15.486 & 14.867 & 1.0417 \\ \hline
45 & 12.577 & 12.115 & 1.0381 \\ \hline
50 & error & error & error \\ \hline
\end{tabular}
\end{minipage}
\end{table}

\begin{table}
\begin{minipage}{0.5\textwidth}
\centering
\caption{$x_1 = 0.4$}
\begin{tabular}{cccc}
\toprule
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \midrule
20 & 22.727 & 22.272 & 1.0204 \\ 
25 & 17.962 & 17.670 & 1.0165 \\ 
30 & 14.416 & 14.234 & 1.0127 \\ 
35 & 11.631 & 11.528 & 1.0090 \\ 
40 & 9.8771 & 9.8264 & 1.0052 \\ 
45 & 9.1780 & 9.1658 & 1.0013 \\ 
50 & error & error & error \\ \bottomrule
\end{tabular}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering
\caption{$x_1 = 0.5$}
\begin{tabular}{cccc}
\toprule
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \midrule
20 & 39.976 & 37.827 & 1.0568 \\ 
25 & 30.827 & 29.273 & 1.0531 \\ 
30 & 24.157 & 23.027 & 1.0491 \\ 
35 & 19.205 & 18.373 & 1.0453 \\ 
40 & 15.486 & 14.867 & 1.0417 \\ 
45 & 12.577 & 12.115 & 1.0381 \\ 
50 & error & error & error \\ \bottomrule
\end{tabular}
\end{minipage}
\end{table}

\end{document}

enter image description here


As your two tables seem to be closely related, you could also combine them into one:

enter image description here

\documentclass{article}
\usepackage{caption}
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\caption{The caption text}
\begin{tabular}{ccccccc}
\toprule
& \multicolumn{3}{c}{$x_1 = 0.4$} & \multicolumn{3}{c}{$x_1 = 0.5$} \\
\cmidrule(r){2-4} \cmidrule(l){5-7}
$\theta $ & $\eta$ & $\nu$ & $\rho$ & $\eta$ & $\nu$ & $\rho$ \\ \midrule
20 & 22.727 & 22.272 & 1.0204 & 39.976 & 37.827 & 1.0568\\ 
25 & 17.962 & 17.670 & 1.0165 & 30.827 & 29.273 & 1.0531\\ 
30 & 14.416 & 14.234 & 1.0127 & 24.157 & 23.027 & 1.0491\\ 
35 & 11.631 & 11.528 & 1.0090 & 19.205 & 18.373 & 1.0453\\ 
40 & 9.8771 & 9.8264 & 1.0052 & 15.486 & 14.867 & 1.0417\\ 
45 & 9.1780 & 9.1658 & 1.0013 & 12.577 & 12.115 & 1.0381\\ 
50 & error  & error  & error  & error  & error  & error \\ \bottomrule
\end{tabular}
\end{table}

\end{document}
5

A layout with siunitx and the floatrow package (incompatible with float, but redefines macros from float):

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath,amssymb,systeme}
\usepackage{makecell}
\setcellgapes{5pt}
\usepackage{floatrow}
\usepackage{siunitx}

\begin{document}

Some text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.

\begin{table}[H]
\floatsetup[table]{floatrowsep=qquad}
\setlength{\tabcolsep}{4pt}
\sisetup{table-format =2.4, table-number-alignment=center}
\begin{floatrow}
\centering
\makegapedcells
\ttabbox{\caption{$x_1 = 0.4$}\label{x1: 4}}{
\begin{tabular}{|>{\centering}p{1cm}|*{3}{S |}}
\hline
{$\theta $} & {$\eta$} & {$\nu$} & {$\rho$} \\ \hline\hline
20 & 22.727 & 22.272 & 1.0204 \\ \hline
25 & 17.962 & 17.670 & 1.0165 \\ \hline
30 & 14.416 & 14.234 & 1.0127 \\ \hline
35 & 11.631 & 11.528 & 1.0090 \\ \hline
40 & 9.8771 & 9.8264 & 1.0052 \\ \hline
45 & 9.1780 & 9.1658 & 1.0013 \\ \hline
50 & {error} & {error} & {error} \\ \hline

\end{tabular}}
\ttabbox{\caption{$x_1 = 0.5$}\label{x1: 5}}
{\begin{tabular}{|>{\centering}p{1cm}|*{3}{S |}}
\hline
{$\theta $} & {$\eta$} & {$\nu$} & {$\rho$} \\ \hline\hline
20 & 39.976 & 37.827 & 1.0568 \\ \hline
25 & 30.827 & 29.273 & 1.0531 \\ \hline
30 & 24.157 & 23.027 & 1.0491 \\ \hline
35 & 19.205 & 18.373 & 1.0453 \\ \hline
40 & 15.486 & 14.867 & 1.0417 \\ \hline
45 & 12.577 & 12.115 & 1.0381 \\ \hline
50 & {error} & {error} & {error} \\ \hline
\end{tabular}}
\end{floatrow}
\end{table}

\end{document} 

enter image description here

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.