将表格放在图表旁边

将表格放在图表旁边

我创建了一个表格,我想在这个表格旁边放一个图(见附图)。

  • 两者的标题可以相同。
  • 我可能需要增加行之间的空间以使表格与图形对齐。
  • 桌子可以放置在右侧或左侧。

我给你留下了我的代码:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[super]{natbib}
\usepackage{comment}
\usepackage{graphicx}
\usepackage{float}
\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=black,
    urlcolor=black
}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{caption}
\usepackage{adjustbox}
\usepackage{lipsum}
\usepackage{lscape}
\usepackage{multicol}
\usepackage{longtable}
\usepackage{chngcntr}
\counterwithin{figure}{section}
\counterwithin{table}{section}
\captionsetup[figure]{font=small,labelfont=bf}
\captionsetup[table]{font=small,labelfont=bf}
\usepackage[justification=centering]{caption}
\usepackage{eurosym}
\usepackage{mhchem}
\usepackage{relsize}
\usepackage[table, dvipsnames]{xcolor}
\renewcommand*\descriptionlabel[1]{\hspace\leftmargin$#1$}
\usepackage{enumitem}


\usepackage{array,ragged2e}
\newcolumntype{C}{>{\Centering\hspace{0pt}}p{0.1\textwidth}}
\usepackage[output-decimal-marker={,}]{siunitx}

\usepackage{booktabs, makecell, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcolumntype{M}{p{\dimexpr 0.25\textwidth-2\tabcolsep}}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}

\usepackage{longtable,array,ragged2e}
\newlength\mylen
\setlength\mylen{\dimexpr0.25\textwidth-1.5\tabcolsep-0.25\arrayrulewidth\relax}
\newcolumntype{Z}{>{\RaggedRight}p{\mylen}}

\usepackage[export]{adjustbox}   % <---
\usepackage{booktabs, tabularx}
\usepackage{array}
\usepackage{booktabs,tabularx}
\usepackage[export]{adjustbox}


\makeatletter
\newcommand*{\rom}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother
\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist 

\bibliographystyle{abbrvnat}
\setcitestyle{authoryear,open={(},close={)}}
\begin{document}

\begin{table}[h]
\resizebox{0.5\textwidth}{!}{%
\begin{tabular}{lcc}
\toprule
                    & Deterministic   & Stochastic \\
                    \midrule
Mean                & \euro430,96M        & \euro429,89M   \\
StDev               & \euro6,36M          & \euro5,44M     \\
n                   & 100             & 100        \\
\midrule
Best SP result      & \multicolumn{2}{c}{-\euro4,40M}  \\
Worst SP result     & \multicolumn{2}{c}{+\euro2,89M}  \\
Average performance & \multicolumn{2}{c}{-\euro1,08M}  \\
t-test              & \multicolumn{2}{c}{3,87E-10}\\
\hline
\end{tabular}%
}
\caption{Analysis of the comparison between the SP and the deterministic model.}
\label{tab:my-table}
\end{table}

\begin{figure}[H]
\centerline{\includegraphics[scale=0.26]{SD5.png}}
\begin{changemargin}{0.5cm}{0.5cm}
\vspace*{-1mm}
\caption{Analysis of the comparison between the SP and the deterministic model.}
\end{changemargin}
\label{fig}
\end{figure}
\vspace{-8mm}

在此处输入图片描述

答案1

在此处输入图片描述

  1. 我的观点是将图像和表格放在里面tikzpicture表是节点的内容

  2. 我缩小了图形和表格,使它们并排放置“但不超过边距”。

  3. 您没有提供图像,所以我在环境中将其创建为绘图tikzpicture。如果要使用它,请更改代码并includegraphics在节点的内容中使用。一般来说,如果可能的话,请绘制而不是包含!

  4. 在下面的代码中,我只保留了编译所需的命令。乍一看,你的序言似乎很沉重。

\documentclass[a4paper]{article}
\usepackage{eurosym}
\usepackage{booktabs, tabularx}

\usepackage{tikz}
\usetikzlibrary{calc, math}
\usepackage{lipsum}

\begin{document}

\lipsum[1]

\begin{table}[ht]
  \centering
  \tikzmath{real \r; \r=2.1; }
  \begin{tikzpicture}[scale=.9]
    \fill[green!30!black] (0, 0) circle (\r);
    \fill[gray!40] (0, 0) -- (\r, 0) arc (0:90:\r) -- cycle;
    \path (\r*.45, \r*.4)
    node[text width=8em, align=center, scale=.7] {Deterministic 25\%};
    \path (-\r*.45, -\r*.4)
    node[white, text width=6em, align=center, scale=.7] {\textbf{Stochastic 75\%}};
    
    \path (\r+.5, 0) node[right, scale=.9] {%
      \begin{tabular}{lcc}
        \toprule
        & Deterministic & Stochastic \\
        \midrule
        Mean                & \euro430,96M  & \euro429,89M   \\
        StDev               & \euro6,36M    & \euro5,44M     \\
        n                   & 100           & 100        \\
        \midrule
        Best SP result      & \multicolumn{2}{c}{-\euro 4,40M}  \\
        Worst SP result     & \multicolumn{2}{c}{+\euro 2,89M}  \\
        Average performance & \multicolumn{2}{c}{-\euro 1,08M}  \\
        t-test              & \multicolumn{2}{c}{3,87e-10}\\
        \hline
      \end{tabular}
    };
  \end{tikzpicture}
  \caption{Analysis of the comparison between the SP and the deterministic model.}
  \label{tab:my-table}
\end{table}

\lipsum[2-3]

\end{document}

答案2

我猜你正在寻找这个:

在此处输入图片描述

\documentclass{article}
\usepackage{eurosym}             % <---
\usepackage{caption}
\usepackage[export]{adjustbox}   % <---
\usepackage{booktabs, tabularx} 

\begin{document}
\begin{table}[ht]
    \begin{tabularx}{\linewidth}{@{}c X @{}}
    \includegraphics[width=0.3 \linewidth,valign=c]{example-image-duck}
    &   
        \begin{tabular}{lcc}
            \toprule
        & Deterministic   & Stochastic \\
                    \midrule
        Mean                & \euro430,96M  & \euro429,89M   \\
        StDev               & \euro6,36M    & \euro5,44M     \\
        n                   & 100           & 100        \\
        \midrule
        Best SP result      & \multicolumn{2}{c}{-\euro 4,40M}  \\
        Worst SP result     & \multicolumn{2}{c}{+\euro 2,89M}  \\
        Average performance & \multicolumn{2}{c}{-\euro 1,08M}  \\
        t-test              & \multicolumn{2}{c}{3,87E-10}\\
\hline
\end{tabular}
    \end{tabularx}
\caption{Analysis of the comparison between the SP and the deterministic model.}
\label{tab:my-table}
\end{table}
\end{document}

答案3

如果您希望表格和图像占用相同的垂直空间,则必须调整表格的大小,因为在您的版本中,它占用了一半以上的空间。(原则上,我同意@Zarko 的回答,只调整图像大小,不调整表格。)

以下是调整表格大小的一种方法 - 使用resizebox

\documentclass{article}
\usepackage{graphicx}
\usepackage{eurosym}
\usepackage{array}
\usepackage{booktabs,tabularx}
\usepackage[export]{adjustbox}

\begin{document}
text text text text text

\begin{table}[ht]
    \begin{tabularx}{\textwidth}{@{} X X @{}}
        \includegraphics[width=\linewidth,valign=c]{example-image-a}
        
        &
        \resizebox{\linewidth}{!}{
                \begin{tabular}{lcc}
                    \toprule
                    & Deterministic &    Stochastic    \\ \midrule
                    Mean                & \euro430,96M  &   \euro429,89M   \\
                    StDev               &  \euro6,36M   &    \euro5,44M    \\
                    n                   &      100      &       100        \\ \midrule
                    Best SP result      & \multicolumn{2}{c}{-\euro 4,40M} \\
                    Worst SP result     & \multicolumn{2}{c}{+\euro 2,89M} \\
                    Average performance & \multicolumn{2}{c}{-\euro 1,08M} \\
                    t-test              & \multicolumn{2}{c}{3,87e-10}     \\ \hline % or \bottomrule to keep in theme with toprule and midrule...
                \end{tabular}
        }
    \end{tabularx}
    \caption{Analysis of the comparison between the SP and the deterministic model.}
    \label{tab:my-table}
\end{table}

\end{document}

请注意,这会占用整个表格并将其缩小,从而导致字体大小和规则粗细较小,可能看起来有点不合适(这就是我更喜欢 Zarko 的答案的原因)。

在此处输入图片描述

相关内容