1

I want two tables in the same line. I insert them using a figure environment and then minipages, inside each minipage I include one table.

The trouble is that it doesn't allow me to include the caption on my table.

Here my code:

\begin{figure}[h]
\begin{minipage}{0.5\columnwidth}
\begin{table}
        \caption{Datos medidos para $L_1$.}
        \label{1L1}
        \begin{tabular}{|c|c|c|c|}
            \hline
            n&  $S_o$ [cm]&     $S_i$ [cm]&     $y_i$ [cm]\\
            &  $\pm0.05$ cm& $\pm0.05$ cm& $\pm0.05$ cm\\
            \hline
            1&  10.0&   56.7&   17.8\\
            \hline
            2&  12.0&   36.7&   10.7\\
            \hline
        \end{tabular}
\end{table}
\end{minipage}
\begin{minipage}
.....
\end{minipage}
\end{figure}

It shows me the error: Not outer in par mode \caption

If I retire \begin{table},\end{table}, it compiles good but the caption says Figure #. And I want it to be Table #......

3

Don't nest table environments inside another floating environments (such as a figure environment). Instead, use a single table environment to encase two minipage environments, each containing a tabular environment plus \caption and \label directives.

Furthermore, do consider giving the tables a more open look, say by omitting all vertical bars and reducing the number of horizontal bars.

enter image description here

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[h]
\small
\begin{minipage}{0.48\textwidth}
\centering
        \caption{Datos medidos para $L_1$.}
        \label{1L1}
        \begin{tabular}{@{}l ccc@{}}
            \toprule
            n&  $S_o$ [cm]&     $S_i$ [cm]&     $y_i$ [cm]\\
            &  $\pm0.05$ cm& $\pm0.05$ cm& $\pm0.05$ cm\\
            \midrule
            1&  10.0&   56.7&   17.8\\
            2&  12.0&   36.7&   10.7\\
            \bottomrule
        \end{tabular}
\end{minipage}\hfill % maximize space between the minipages
\begin{minipage}{0.48\textwidth}
\centering
        \caption{Datos medidos para $L_2$.}
        \label{2L2}
        \begin{tabular}{@{}l ccc@{}}
            \toprule
            n&  $S_o$ [cm]&     $S_i$ [cm]&     $y_i$ [cm]\\
            &  $\pm0.05$ cm& $\pm0.05$ cm& $\pm0.05$ cm\\
            \midrule
            1&  10.0&   56.7&   17.8\\
            2&  12.0&   36.7&   10.7\\
            \bottomrule
        \end{tabular}
\end{minipage}
\end{table}
\end{document}
2

Like @Mico, I'd use booktabs, and floatrow, which is done to place floats side by side, and has a better spacing between caption and table than the default. I also use makecell, to group the first two rows, since they're semantically linked. This results in a shortercode:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs, floatrow, makecell}
\floatsetup{floatrowsep=qquad}

\begin{document}

\begin{table}[h]
  \small\centering
  \begin{floatrow}
    \ttabbox{ \caption{Datos medidos para $L_1$.} \label{1L1}}
    {\begin{tabular}{@{}l ccc@{}}
      \toprule
      \thead{n}& \thead{ $S_o$ [cm]\\ $\pm0.05$ cm}& \thead{$S_i$ [cm]\\ $\pm0.05$ cm}& \thead{$y_i$ [cm]\\ $\pm0.05$ cm}\\
      \midrule
      1& 10.0& 56.7& 17.8\\
      2& 12.0& 36.7& 10.7\\
      \bottomrule
      \end{tabular}}
    \ttabbox{ \caption{Datos medidos para $L_2$.} \label{2L2}}
    {\begin{tabular}{@{}l ccc@{}}
      \toprule
      \thead{n}& \thead{ $S_o$ [cm]\\ $\pm0.05$ cm}& \thead{$S_i$ [cm]\\ $\pm0.05$ cm}& \thead{$y_i$ [cm]\\ $\pm0.05$ cm}\\
      \midrule
      1& 10.0& 56.7& 17.8\\
      2& 12.0& 36.7& 10.7\\
      \bottomrule
      \end{tabular}}
  \end{floatrow}
\end{table}

\end{document} 

enter image description here

1

I guess, the problem is, that you want to use a floating environment in an other floating environment (table in figure). If you remove the \begin{table}...\end{table} it solves the error, but the \caption{} will be the part of the figure. The cheap solution for your problem is the renaming the string "Figure" to "Table":

\renewcommand{\figurename}{Table}

The only weak point that this "false table labels" will be considered as figure labels (in the list of figures, in the list of tables ect...).

If you want do this trick once in the document, you have to restore the \figurename with storing it.

Here is my full code for it:

\documentclass{article}

\usepackage[margin=2cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\begin{document}

\let\OldFigurename\figurename       %% store the original 'Figure'
\renewcommand{\figurename}{Table}   %% overwrite 'Figure' with 'Table'

\begin{figure}[h]
\begin{minipage}{0.5\columnwidth}
        \caption{Datos medidos para $L_1$.}
        \label{1L1}
        \begin{tabular}{|c|c|c|c|}
            \hline
            n&  $S_o$ [cm]&     $S_i$ [cm]&     $y_i$ [cm]\\
            &  $\pm0.05$ cm& $\pm0.05$ cm& $\pm0.05$ cm\\
            \hline
            1&  10.0&   56.7&   17.8\\
            \hline
            2&  12.0&   36.7&   10.7\\
            \hline
        \end{tabular}
\end{minipage}
\begin{minipage}{0.5\columnwidth}
        \caption{Datos medidos para $L_1$.}
        \label{1L1}
        \begin{tabular}{|c|c|c|c|}
            \hline
            n&  $S_o$ [cm]&     $S_i$ [cm]&     $y_i$ [cm]\\
            &  $\pm0.05$ cm& $\pm0.05$ cm& $\pm0.05$ cm\\
            \hline
            1&  10.0&   56.7&   17.8\\
            \hline
            2&  12.0&   36.7&   10.7\\
            \hline
        \end{tabular}
\end{minipage}
\end{figure}

\renewcommand{\figurename}{\OldFigurename}  %% restore 'Figure'

\begin{figure}
        \caption{Datos medidos para $L_1$.}
        \label{1L1}
        \begin{tabular}{|c|c|c|c|}
            \hline
            n&  $S_o$ [cm]&     $S_i$ [cm]&     $y_i$ [cm]\\
            &  $\pm0.05$ cm& $\pm0.05$ cm& $\pm0.05$ cm\\
            \hline
            1&  10.0&   56.7&   17.8\\
            \hline
            2&  12.0&   36.7&   10.7\\
            \hline
        \end{tabular}
    \end{figure}
\end{document}
  • Wouldn't it be more straightforward to use a table environment instead of renaming \figurename twice? – Mico Mar 9 '16 at 7:29
  • 1
    This does not work, you have renamed the figure to table but it will be kept in sequence with figures not tables. – David Carlisle Mar 9 '16 at 8:01
  • 1
    Yes the best solution is using table instead of figure; but if the questioner wants to use figure... – Tom Solid Mar 9 '16 at 8:07
  • 2
    No the questioner was confused and the answer is supposed to make the document better not maintain the main error. The code above will make tables be printed out of sequence in a real document that has more tables. – David Carlisle Mar 9 '16 at 9:01

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.