4

I try to use a table in a minipage like this:

\begin{center}
    \begin{minipage}[t]{.48\textwidth}
        \subsection{My Title}
    Some text

    \begin{table}[h!]
        \begin{tabular}{ l c l }
            \hline
            Quality            & Abbr. & Frequency \\
            \hline
            Uncirqulated       & UNC   &           \\
            \hline
        \end{tabular}
    \end{table}

\end{minipage}\quad
\begin{minipage}[t]{.48\textwidth}
    ...

\end{minipage}

\end{center}

And I get this error on the line \begin{table}[h!]:

Not in outer par mode.
LaTeX

Undefined control sequence. \latex@xfloat ...vf \fi \global \setbox @currbox LaTeX

Missing number, treated as zero. <to be read again> LaTeX

What did I wrong or what I miss?

netdjw
  • 143
  • Welcome to TeX.SE. – Mico Jan 07 '22 at 17:03
  • Thank you @Mico :) – netdjw Jan 07 '22 at 17:04
  • You get the error because you can't use a float environment (table in this case) inside a minipage. – Imran Jan 07 '22 at 17:07
  • 1
    It's a mistake to embed a LaTeX float -- such as figure or table environment -- in a minipage, as doing so would fly in the face of the purpose of using a float to begin with. Please tell us what you're trying to achieve, typographically speaking. – Mico Jan 07 '22 at 17:07
  • I want to put a table into a column between two paragraps. I'm really new to LaTeX, and the stackoverflow codes suggested this method. What is the correct way? – netdjw Jan 07 '22 at 17:09
  • Unrelated: You should not use only [h!] as the positioning argument. See this answer for details on float placement. – Imran Jan 07 '22 at 17:12

2 Answers2

2

For the purpose of placing some tabular material between two particular paragraphs, you don't need either a table or a minipage environment. If you want to assign a caption to the tabular material, I suggest you load the caption package ane employ its \captionof macro.

enter image description here

\documentclass[twocolumn]{article}

\usepackage{caption} % for '\captionof' macro \usepackage{lipsum} % filler text

\begin{document} \lipsum[2]

\begin{center} %\begin{minipage}[t]{\columnwidth} %%\subsection{My Title} \centering \captionof{table}{My title} %%\begin{table}[h!] \begin{tabular}{ l c l } \hline Quality & Abbr. & Frequency \ \hline Uncirculated & UNC & \ \hline \end{tabular} %%\end{table} %\end{minipage} \end{center}

\lipsum[2] \end{document}

Mico
  • 506,678
2

To have a table (a floating environment, to add a caption?) inside a minipage (non floating environment) can be done using the package float.

a

\documentclass[12pt,a4paper]{article}

\usepackage{float}% added <<<<<<<<<<

\begin{document}

\begin{center} \begin{minipage}[t]{.48\textwidth} \subsection{My Title}
Some text

        \begin{table}[H] % changed &lt;&lt;&lt;&lt;&lt;
            \begin{tabular}{ l c l }
                \hline
                Quality            &amp; Abbr. &amp; Frequency \\
                \hline
                Uncirqulated       &amp; UNC   &amp;           \\
                \hline
            \end{tabular}
        \caption{First table}
        \end{table}     
    \end{minipage} \hfill
    \begin{minipage}[t]{.48\textwidth}
        \subsection{My Title}       
        Some text

        \begin{table}[H]
            \begin{tabular}{ l c l }
                \hline
                Quality            &amp; Abbr. &amp; Frequency \\
                \hline
                Uncirqulated       &amp; UNC   &amp;           \\
                \hline
            \end{tabular}
            \caption{Second table}
        \end{table}     
    \end{minipage}

\end{center}

\end{document}

Alternative

b

\documentclass[12pt,a4paper]{article}

\usepackage{float}% added <<<<<<<<<<
\begin{document}

\section{My Title}

\begin{center} \begin{minipage}[t]{.48\textwidth} Some text

        \begin{table}[H] % changed &lt;&lt;&lt;&lt;&lt;
            \begin{tabular}{ l c l }
                \hline
                Quality            &amp; Abbr. &amp; Frequency \\
                \hline
                Uncirqulated       &amp; UNC   &amp;           \\
                \hline
            \end{tabular}
        \caption{First table}
        \end{table} 
    \smallskip
    Some more text      
    \end{minipage}

\end{center}

\end{document}

Simon Dispa
  • 39,141