minipage 中的 LaTeX 表格:不处于外部 par 模式

minipage 中的 LaTeX 表格:不处于外部 par 模式

我尝试在小页面中使用表格,如下所示:

\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}

我收到此错误\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

我做错了什么或者错过了什么?

答案1

想要在小页面(非浮动环境)内放置一个表格(浮动环境,添加标题?),可以使用包来实现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}

选择

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

为了在两个特定段落之间放置一些表格材料,您不需要或table环境minipage。如果您想为表格材料指定标题,我建议您加载caption包并使用其\captionof宏。

在此处输入图片描述

\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}

相关内容