如何将表格和图形并排排列,并将所有标题放在一侧

如何将表格和图形并排排列,并将所有标题放在一侧

为了最大程度地利用空间,我尝试将表格和图片并排放在文档中。由于图片比表格长,因此我想将两个标题都放在表格下方(如果可能)。我设想的效果如下所示。

示例输出

我已按照此步骤操作例子。但是我找不到将图形标题移到表格下方的方法。以下是一些有效代码:

\documentclass{article}

\usepackage[demo]{graphicx} % for inclusion of graphics
\usepackage{floatrow}
\newfloatcommand{capbtabbox}{table}[][\FBwidth]
\usepackage{booktabs}

\begin{document}

\begin{figure}[t]
\begin{floatrow}
\TopFloatBoxes
  \capbtabbox{
    \begin{tabular}{ccc} \toprule
    Heading 1 & Heading 2 & Heading 3 \\ \midrule
      1 & $\{1\}$ & A  \\ 
      2 & $\{1,2\}$ & B   \\ 
      3 & $\{1,2,3\}$ & C  \\ 
      4 & $\{1,2,3,4\}$ & D  \\ 
      5 & $\{1,2,3,4,5\}$ & E  \\ 
      6 & $\{1,2,3,4,5,6\}$ & F  \\ 
      7 & $\{1,2,3,4,5,6,7\}$ & G  \\ 
      8 & $\{1,2,3,4,5,6,7,8\}$ & H  \\
      9 & $\{1,2,3,4,5,6,7,8,9\}$ & I  \\ 
      10 & $\{1,2,3,4,5,6,7,8,9,10\}$ & J  \\ \bottomrule
    \end{tabular}
}{
  {\caption{A caption for a table in a figure and a table side by side}\label{fig:test}}
}
\ffigbox{
  \includegraphics[height=8cm]{Images/preNet.pdf}  
}{
  {\caption{A caption for a figure in a figure and a table side by side}\label{fig:test}}
}
\end{floatrow}
\end{figure}

\end{document}    

答案1

这与 Gonzalo 的答案类似,但优点是不需要明确的计算或奇怪的调整。

\documentclass{article}

\usepackage[demo]{graphicx} % for inclusion of graphics
\usepackage{booktabs}
\usepackage{capt-of,calc}

\newsavebox{\figurebox}

\begin{document}

\begin{figure}[t]
%% get the dimensions of the figure
\sbox{\figurebox}{\includegraphics[height=8cm]{Images/preNet.pdf}}

\begin{minipage}[t][\ht\figurebox]{\textwidth-\wd\figurebox-1em}
\centering\footnotesize
\vspace*{0pt}% to set the top
\begin{tabular}{ccc} \toprule
Heading 1 & Heading 2 & Heading 3 \\ \midrule
        1 & $\{1\}$ & A  \\ 
        2 & $\{1,2\}$ & B   \\ 
        3 & $\{1,2,3\}$ & C  \\ 
        4 & $\{1,2,3,4\}$ & D  \\ 
        5 & $\{1,2,3,4,5\}$ & E  \\ 
        6 & $\{1,2,3,4,5,6\}$ & F  \\ 
        7 & $\{1,2,3,4,5,6,7\}$ & G  \\ \bottomrule
\end{tabular}
\captionof{table}{A caption for a table in a figure and a table side by side}
\label{tab:test}

\vfill

\captionof{figure}{A caption for a figure in a figure and a table side by side}
\label{fig:test}
\end{minipage}\hfill
\begin{minipage}[t]{\wd\figurebox}
\centering
\vspace*{0pt}% to set the top
\usebox{\figurebox}
\end{minipage}
\end{figure}

\end{document}

相反,capt-of可以加载caption具有其他优点的;但是,有些类不允许使用caption

在此处输入图片描述

答案2

我认为minipage在这里使用固定高度更容易;标题是\captionof使用caption包裹:

\documentclass{article}
\usepackage[margin=3.5cm]{geometry}
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{caption}
\usepackage{booktabs}

\begin{document}

\begin{figure}
\begin{minipage}[c][8cm][t]{.67\linewidth}
  \centering
  \begin{tabular}{ccc} \toprule
    Heading 1 & Heading 2 & Heading 3 \\ \midrule
      1 & $\{1\}$ & A  \\ 
      2 & $\{1,2\}$ & B   \\ 
      3 & $\{1,2,3\}$ & C  \\ 
      4 & $\{1,2,3,4\}$ & D  \\ 
      5 & $\{1,2,3,4,5\}$ & E  \\ 
      6 & $\{1,2,3,4,5,6\}$ & F  \\ 
      7 & $\{1,2,3,4,5,6,7\}$ & G  \\ 
      8 & $\{1,2,3,4,5,6,7,8\}$ & H  \\
      9 & $\{1,2,3,4,5,6,7,8,9\}$ & I  \\ 
      10 & $\{1,2,3,4,5,6,7,8,9,10\}$ & J  \\ \bottomrule
  \end{tabular}
  \captionof{table}{a caption for a table side-by-side with a figure}
  \vfill
  \captionof{figure}{a caption for a figure side-by-side with a figure}
\end{minipage}%
\begin{minipage}[c][8cm][t]{.33\linewidth}
  \centering
  \adjustbox{valign=t}{%
    \includegraphics[height=8cm,width=\linewidth]{example-image-a}} 
\end{minipage}
\end{figure}

\end{document}  

在此处输入图片描述

对图像进行装箱并测量箱子的总高度可以让你minipage自动找到所需的高度

答案3

使用\floatbox \capbeside and \thisfloatsetup来自floatrow,从 Gonzalo Medina 的作品中受到启发和学习https://tex.stackexchange.com/a/29144/34618

在此处输入图片描述

代码

\documentclass{article}
\usepackage[landscape]{geometry}
\usepackage[demo]{graphicx} % for inclusion of graphics
\usepackage{floatrow}
\newfloatcommand{capbtabbox}{table}[][\FBwidth]
\usepackage{booktabs}

\begin{document}

\begin{figure}[t]
\begin{floatrow}
\TopFloatBoxes
  \capbtabbox{
    \begin{tabular}{ccc} \toprule
    Heading 1 & Heading 2 & Heading 3 \\ \midrule
      1 & $\{1\}$ & A  \\ 
      2 & $\{1,2\}$ & B   \\ 
      3 & $\{1,2,3\}$ & C  \\ 
      4 & $\{1,2,3,4\}$ & D  \\ 
      5 & $\{1,2,3,4,5\}$ & E  \\ 
      6 & $\{1,2,3,4,5,6\}$ & F  \\ 
      7 & $\{1,2,3,4,5,6,7\}$ & G  \\ 
      8 & $\{1,2,3,4,5,6,7,8\}$ & H  \\
      9 & $\{1,2,3,4,5,6,7,8,9\}$ & I  \\ 
      10 & $\{1,2,3,4,5,6,7,8,9,10\}$ & J  \\ \bottomrule
    \end{tabular}
}{
  {\caption{A caption for a table in a figure and a table side by side}\label{tab:test}}
}
\hspace{-9cm}
\ffigbox{
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,bottom},capbesidewidth=9cm}}]{figure}
{
  \includegraphics[height=8cm]{Images/preNet.pdf}  
}
}{
  {\caption{A caption for a figure in a figure and a table side by side}\label{fig:test}}
}
\end{floatrow}
\end{figure}

\end{document}    

相关内容