在图形标签内使用表格,否则将表格标题更改为图形

在图形标签内使用表格,否则将表格标题更改为图形

我使用图表表格来格式化它们的显示和顺序。但本质上整个图表都是一个图表,所以我现在想让“图 5”作为标题。为此,我想我必须将整个表格放在一个图表中。

这就是我正在做的事情,但发生的只是标题出现了,但是表格却不存在,并且出现错误:

! LaTeX 错误:不在外部模式中。

代码如下:

\begin{figure*}
\centering
\caption{Confusion matrices: Single 29-class model}
\label{Figure 5}
\begin{table}
\begin{tabularx}{\textwidth}{c X c }
\textbf{GentleBoost} & & \textbf{Baseline} \\ \noalign{\smallskip}\\ 
\includegraphics[width=7.25cm]{singlematrix_g1} & & \includegraphics[width=7.25cm]{singlematrix_b1} \\ \noalign{\smallskip}\\ 
\includegraphics[width=7.25cm]{singlematrix_g2} & & \includegraphics[width=7.25cm]{singlematrix_b2} \\ \noalign{\smallskip}\\ 
\includegraphics[width=7.25cm]{singlematrix_g3} & & \includegraphics[width=7.25cm]{singlematrix_b3} \\ \noalign{\smallskip}\\ 
\end{tabularx}
\end{table}
\end{figure*}

但是,我唯一的问题是它显示为图形而不是表格。如果可以轻松将标题从表格更改为图形 - 那么我更喜欢这样!

答案1

我不得不减小图像尺寸,但是结果如下:

% arara: pdflatex

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tabularx}
\usepackage{caption}

\begin{document}
    \begin{table}
        \begin{tabularx}{\textwidth}{c X c }
            \textbf{GentleBoost} & & \textbf{Baseline} \\ \noalign{\bigskip} 
            \includegraphics[width=1.25cm]{singlematrix_g1} & & \includegraphics[width=1.25cm]{singlematrix_b1} \\ \noalign{\bigskip}
            \includegraphics[width=1.25cm]{singlematrix_g2} & & \includegraphics[width=1.25cm]{singlematrix_b2} \\ \noalign{\bigskip} 
            \includegraphics[width=1.25cm]{singlematrix_g3} & & \includegraphics[width=1.25cm]{singlematrix_b3} \\ \noalign{\bigskip} 
        \end{tabularx}
    \captionof{figure}{Confusion matrices: Single 29-class model}\label{Figure 5}
    \end{table}
\end{document}

在此处输入图片描述

答案2

不要使用figure环境,而是使用包\captionof中定义的caption。以下是代码片段:

\begin{table}
\centering
\captionof{figure}{Confusion matrices: Single 29-class model}
\label{Figure 5}
\begin{tabularx}{\textwidth}{c X c }
\textbf{GentleBoost} & & \textbf{Baseline} \\ \noalign{\smallskip}\\
\includegraphics[width=7.25cm]{singlematrix_g1} & & \includegraphics[width=7.25cm]{singlematrix_b1} \\ \noalign{\smallskip}\\
\includegraphics[width=7.25cm]{singlematrix_g2} & & \includegraphics[width=7.25cm]{singlematrix_b2} \\ \noalign{\smallskip}\\
\includegraphics[width=7.25cm]{singlematrix_g3} & & \includegraphics[width=7.25cm]{singlematrix_b3} \\ \noalign{\smallskip}\\
\end{tabularx}
\end{table}

在此处输入图片描述

答案3

只需使用figuretable

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tabularx}


\begin{document}
    \begin{figure}
        \begin{tabularx}{\textwidth}{c X c }
            \textbf{GentleBoost} & & \textbf{Baseline} \\ \noalign{\bigskip} 
            \includegraphics[width=1.25cm]{singlematrix_g1} & & \includegraphics[width=1.25cm]{singlematrix_b1} \\ \noalign{\bigskip}
            \includegraphics[width=1.25cm]{singlematrix_g2} & & \includegraphics[width=1.25cm]{singlematrix_b2} \\ \noalign{\bigskip} 
            \includegraphics[width=1.25cm]{singlematrix_g3} & & \includegraphics[width=1.25cm]{singlematrix_b3} \\ \noalign{\bigskip} 
        \end{tabularx}
    \caption{Confusion matrices: Single 29-class model}\label{Figure 5}
    \end{figure}
\end{document}

但是不要使用tabularx它,因为它很慢而且很痛苦,而且由于 X 列是空的,所以没有做任何非常有用的事情。

\documentclass{article}
\usepackage[demo]{graphicx}


\begin{document}
    \begin{figure}

            \makebox[5.25cm]{\textbf{GentleBoost}}\hfill \makebox[5.25cm]{\textbf{Baseline} }

\bigskip


            \includegraphics[width=5.25cm]{singlematrix_g1}\hfill\includegraphics[width=5.25cm]{singlematrix_b1}

\bigskip

            \includegraphics[width=5.25cm]{singlematrix_g2}\hfill\includegraphics[width=5.25cm]{singlematrix_b2}

\bigskip
            \includegraphics[width=5.25cm]{singlematrix_g3}\hfill\includegraphics[width=5.25cm]{singlematrix_b3}

\bigskip

    \caption{Confusion matrices: Single 29-class model}\label{Figure 5}
    \end{figure}
\end{document}

相关内容