TeX - LaTeX Asked by Max Lomba Vrouenraets on October 12, 2020
I created a table and I would like to put a figure next to this table (see picture attached.
I leave you my code:
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]{hspaceleftmargin$#1$}
usepackage{enumitem}
usepackage{array,ragged2e}
newcolumntype{C}{>{Centeringhspace{0pt}}p{0.1textwidth}}
usepackage[output-decimal-marker={,}]{siunitx}
usepackage{booktabs, makecell, tabularx}
newcolumntype{L}{>{raggedrightarraybackslash}X}
newcolumntype{M}{p{dimexpr 0.25textwidth-2tabcolsep}}
newcolumntype{P}[1]{>{centeringarraybackslash}p{#1}}
usepackage{longtable,array,ragged2e}
newlengthmylen
setlengthmylen{dimexpr0.25textwidth-1.5tabcolsep-0.25arrayrulewidthrelax}
newcolumntype{Z}{>{RaggedRight}p{mylen}}
usepackage[export]{adjustbox} % <---
usepackage{booktabs, tabularx}
usepackage{array}
usepackage{booktabs,tabularx}
usepackage[export]{adjustbox}
makeatletter
newcommand*{rom}[1]{expandafter@slowromancapromannumeral #1@}
makeatother
defchangemargin#1#2{list{}{rightmargin#2leftmargin#1}item[]}
letendchangemargin=endlist
bibliographystyle{abbrvnat}
setcitestyle{authoryear,open={(},close={)}}
begin{document}
begin{table}[h]
resizebox{0.5textwidth}{!}{%
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}
My point of view was to have the image and the table inside a tikzpicture
.
The table is the content of a node.
I scaled down the figure and table to have them side by side "without exceeding the margins".
You didn't provide the image, so I created it as a drawing in the tikzpicture
environment. If you want to use it, change the code and use includegraphics
in the content of a node. In general, if possible, draw instead of include!
In the code below, I kept only the commands needed for the compilation. At first sight, your preamble seems heavy.
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}
Correct answer by Daniel N on October 12, 2020
I guess that you looking for this:
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}
Answered by Zarko on October 12, 2020
If you want the tabular and image to take up the same amount of vertical space, you have to resize the tabular, as in your version it takes up more than half of the space. (In principle, I agree with @Zarko's answer to just resize the image and leave the tabular alone.)
Here is one way to resize the table - using a 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}
Note that this takes the whole table and shrinks it, thus resulting in a smaller font size and thickness of rules, potentially looking a bit out of place (which is why I prefer Zarko's answer).
Answered by TivV on October 12, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP