Colocar uma mesa ao lado de uma figura

Colocar uma mesa ao lado de uma figura

Criei uma tabela e gostaria de colocar uma figura ao lado desta tabela (ver imagem em anexo.

  • A legenda pode ser a mesma para ambos.
  • Provavelmente precisaria aumentar o espaço entre as linhas para alinhar a tabela com a figura.
  • A mesa pode ser posicionada à direita ou à esquerda.

Deixo-vos o meu código:

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

insira a descrição da imagem aqui

Responder1

insira a descrição da imagem aqui

  1. Meu ponto de vista era ter a imagem e a tabela dentro de um arquivo tikzpicture. A tabela é o conteúdo de um nó.

  2. Reduzi a figura e a tabela para colocá-las lado a lado “sem ultrapassar as margens”.

  3. Você não forneceu a imagem, então criei ela como desenho no tikzpictureambiente. Se quiser utilizá-lo, altere o código e utilize includegraphicsno conteúdo de um nó. Em geral, se possível, desenhe em vez de incluir!

  4. No código abaixo, mantive apenas os comandos necessários para a compilação. À primeira vista, o seu preâmbulo parece pesado.

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

Responder2

Eu acho que você está procurando por isso:

insira a descrição da imagem aqui

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

Responder3

Se você deseja que o tabular e a imagem ocupem a mesma quantidade de espaço vertical, é necessário redimensionar o tabular, pois na sua versão ele ocupa mais da metade do espaço. (Em princípio, concordo com a resposta de @Zarko de apenas redimensionar a imagem e deixar a tabela em paz.)

Aqui está uma maneira de redimensionar a tabela - usando 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}

Observe que isso pega a tabela inteira e a reduz, resultando em um tamanho de fonte e espessura de regras menores, potencialmente parecendo um pouco fora do lugar (é por isso que prefiro a resposta de Zarko).

insira a descrição da imagem aqui

informação relacionada