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?

6
  • Welcome to TeX.SE.
    – Mico
    Commented Jan 7, 2022 at 17:03
  • Thank you @Mico :)
    – netdjw
    Commented Jan 7, 2022 at 17:04
  • You get the error because you can't use a float environment (table in this case) inside a minipage.
    – Imran
    Commented Jan 7, 2022 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
    Commented Jan 7, 2022 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
    Commented Jan 7, 2022 at 17:09

2 Answers 2

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 <<<<<
                \begin{tabular}{ l c l }
                    \hline
                    Quality            & Abbr. & Frequency \\
                    \hline
                    Uncirqulated       & UNC   &           \\
                    \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            & Abbr. & Frequency \\
                    \hline
                    Uncirqulated       & UNC   &           \\
                    \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 <<<<<
                \begin{tabular}{ l c l }
                    \hline
                    Quality            & Abbr. & Frequency \\
                    \hline
                    Uncirqulated       & UNC   &           \\
                    \hline
                \end{tabular}
            \caption{First table}
            \end{table} 
        \smallskip
        Some more text      
        \end{minipage}
\end{center}    
    
\end{document}
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}

You must log in to answer this question.

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