在图形环境中包含子图和表

在图形环境中包含子图和表

我想在宏图环境中包含一个表格和一个图像作为两个子图。显然代码可以编译,但它没有按照我想要的方式放置元素:表格和图像并排(而不是一个在另一个之上)在页面顶部的单个图形环境中。

以下是代码:

\begin{figure*}[!t]
%\begin{table*}[!t]
\centering 
\scriptsize{
\begin{tabular}[H]{|c||c|c|c|c|c|}
\cline{1-3}
\Xhline{2\arrayrulewidth} % $k$
 & 1 & 2 & 3 & 4 & 5 \\ \cline{1-6}
\Xhline{2\arrayrulewidth}
Attribute1 & $\uparrow$ p1 & $\uparrow$ p2 & $\downarrow$ p3 & $\uparrow$ p4 & $\downarrow$ p5 \\ \cline{1-6}
Accuracy & 60.22\% & 65.24\% & 68.66\% & 70.21\% & 71.87\% \\ \cline{1-6}
\Xhline{3\arrayrulewidth}
Attribute2 & $\uparrow$ p1 & $\uparrow$ p2 & $\uparrow$ p3 & $\downarrow$ p4 & $\uparrow$ p5 \\ \cline{1-6}
Accuracy & 45.70\% & 54.53\% & 59.49\% & 62.91\% & 65.56\% \\ \cline{1-6}
\Xhline{3\arrayrulewidth}
 Attribute3 & $\uparrow$ p1 & $\uparrow$ p2 & $\uparrow$ p3 & $\uparrow$ p4 & $\downarrow$ p5 \\ \cline{1-6}
 Accuracy & 50.08\% & 60.37\% & 64.84\% & 68.02\% & 69.32\% \\ \cline{1-6}
\Xhline{2\arrayrulewidth}
\end{tabular}
}
\label{fig:AttributeComb}
%\vspace{-7pt}
\captionof{table}{Table1}
\label{table:AttributeCombT}
%\vspace{-25pt}
\subfigure[Title2]
{\includegraphics[scale=0.295,clip=true,draft=false,]{Performance.pdf}
\label{fig:performance}
}
\vspace{-25pt}

%\end{table*}
\end{figure*}

答案1

的大小写mixed floats可以由包管理floatrow,请参阅文档的 §2.3.1。我将我最喜欢的一张图片与您的表格混合在一起(使用命令对垂直间距进行了轻微改进 setcellgapes,来自mmakecell

        \documentclass[12pt,a4paper]{article}
        \usepackage[utf8]{inputenc}
        \usepackage[T1]{fontenc}
        \usepackage{lmodern}
        \usepackage{graphicx}
        \usepackage{caption}
        \captionsetup{font = footnotesize}
         \usepackage{floatrow, makecell}%
         \setcellgapes{2.8pt}\makegapedcells
        \begin{document}

        \begin{figure}\CenterFloatBoxes
        \floatsetup{floatrowsep = qquad}
           \begin{floatrow}
           \ffigbox[\FBwidth]{\raisebox{-1\height}{\includegraphics[scale = 0.4]{AliceSteadman}}}{\caption{Ralph Steadman’s Alice}\label{Dinah}}
             \killfloatstyle
             \ttabbox{\scriptsize%
            \begin{tabular}[H]{|c||c|c|c|c|c|}
            \cline{1-3}
            \Xhline{2\arrayrulewidth} % $k$
             & 1 & 2 & 3 & 4 & 5 \\ \cline{1-6}
            \Xhline{2\arrayrulewidth}
            Attribute1 & $\uparrow$ p1 & $\uparrow$ p2 & $\downarrow$ p3 & $\uparrow$ p4 & $\downarrow$ p5 \\ \cline{1-6}
            Accuracy & 60.22\% & 65.24\% & 68.66\% & 70.21\% & 71.87\% \\ \cline{1-6}
            \Xhline{3\arrayrulewidth}
            Attribute2 & $\uparrow$ p1 & $\uparrow$ p2 & $\uparrow$ p3 & $\downarrow$ p4 & $\uparrow$ p5 \\ \cline{1-6}
            Accuracy & 45.70\% & 54.53\% & 59.49\% & 62.91\% & 65.56\% \\ \cline{1-6}
            \Xhline{3\arrayrulewidth}
             Attribute3 & $\uparrow$ p1 & $\uparrow$ p2 & $\uparrow$ p3 & $\uparrow$ p4 & $\downarrow$ p5 \\ \cline{1-6}
             Accuracy & 50.08\% & 60.37\% & 64.84\% & 68.02\% & 69.32\% \\ \cline{1-6}
            \Xhline{2\arrayrulewidth}
            \end{tabular}
             }{\caption{A table}\label{mytable}}
           \end{floatrow}
        \end{figure}

        \end{document}

在此处输入图片描述

答案2

有很多方法可以做到这一点。您会注意到,小页面目前设置为底部对齐。如果您想要顶部对齐,则包含 \rasieboxes。此外,您可能希望使第二个小页面更宽,以便在一行中处理标题。

\documentclass{article}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{mwe}

\newsavebox{\tempbox}
\newlength{\tempwidth}

\begin{document}

\begin{figure*}[!t]
%\begin{table*}[!t]
\savebox{\tempbox}{% compute size of tabulat
\scriptsize{
\begin{tabular}[b]{|c|}
Frankly, it doesn't\\
matter what your\\
tabular looks like!
\end{tabular}
}}%
\settowidth{\tempwidth}{\usebox{\tempbox}}%
\hfil\begin{minipage}[b]{\tempwidth}%
\raisebox{-\height}{\usebox{\tempbox}}%
%\vspace{-7pt}
\captionof{table}{Table1}%
\label{table:AttributeCombT}%
\end{minipage}%
%\vspace{-25pt}
\savebox{\tempbox}{\includegraphics[scale=0.295,clip=true,draft=false,]{example-image}}%
\settowidth{\tempwidth}{\usebox{\tempbox}}%
\hfil\begin{minipage}[b]{\tempwidth}%
\raisebox{-\height}{\usebox{\tempbox}}%
\captionof{figure}{performance}%
\label{fig:AttributeComb}%
\end{minipage}%
%\vspace{-25pt}
%\end{table*}
\end{figure*}

\end{document}

混合表格和图形

相关内容