0

I am trying to put side-by-side a plot and a table. I have tried using minipage and tried applying the following solution to my problem here. I cannot seem to get it working correctly.

The file is called conMat_NN.pdf

File location: https://easyupload.io/lethp7

\documentclass[12pt]{article}

\usepackage{graphicx}

\begin{document}



\begin{figure}[!ht]
\begin{center}
\includegraphics[width=1\textwidth, angle=0]{plots/conMat_NN.pdf}
\caption{Neural Network: Confusion Matrix}
\label{fig:conMat_NN}
\end{center}
\end{figure}

\begin{table}
\centering
Statistics \\
\begin{tabular}{|c|c|c|c|c|}
\hline
Year 1 & 2 & 3 & 4 \\
\hline
\multicolumn{5}{c}{Neural Network} \\
\hline
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
\hline
\end{tabular}
\caption{some caption}
\label{tab:stats}
\end{table}


\end{document}

EDIT:

With current version: The table overlays the figure:

\documentclass{article}

\usepackage{floatrow}
% Table float box with bottom caption, box width adjusted to content
\newfloatcommand{capbtabbox}{table}[][\FBwidth]

\usepackage{blindtext}
\usepackage{graphicx}

\begin{document}

\begin{figure}
\begin{floatrow}
\ffigbox{%
  \rule{3cm}{3cm}%
}{%
\begin{center}
\includegraphics[width=1\textwidth, angle=0]{plots/conMat_NN.pdf}
\caption{Neural Network: Confusion Matrix}
\label{fig:conMat_NN}
\end{center}
}
\capbtabbox{%
\begin{tabular}{|c|c|c|c|c|}
\hline
Year 1 & 2 & 3 & 4 \\
\hline
\multicolumn{5}{c}{Neural Network} \\
\hline
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
\hline
\end{tabular}
}{%
  \caption{A table}%
}
\end{floatrow}
\end{figure}

\end{document}
4
  • Which of the answers from the question you linked to are you trying to use here? Please provide a link to the specific answer (look for share at the end of the answer, right-click on it and select Copy Link Location, or something approaching).
    – frougon
    Feb 7 '20 at 22:31
  • This one: tex.stackexchange.com/a/6869/173150 , however I am open to any general working solution - Thanks for highlighting the "share" option I never saw / realised to use it before.
    – user113156
    Feb 7 '20 at 22:37
  • Okay, but the code you posted doesn't contain any occurrence of floatrow, therefore you don't show us that you tried to apply that answer. Please show us what you tried, then we can help you further.
    – frougon
    Feb 7 '20 at 22:39
  • I added my version in which the table overlays the plot. I was hoping for a long table to the right of the plot.
    – user113156
    Feb 7 '20 at 22:51
3

In order to apply the solution in the answer you linked to, you need to replace the \rule (which produces the big black rectangle) with your image: \includegraphics[...]{...}. Using example-image that is present in all TeX distributions, we obtain:

\documentclass{article}
\usepackage{graphicx}
\usepackage{floatrow}
% Table float box with bottom caption, box width adjusted to content
\newfloatcommand{capbtabbox}{table}[][\FBwidth]

\begin{document}

\begin{figure}
\begin{floatrow}
\ffigbox{%
  \includegraphics[width=\linewidth]{example-image}%
}{%
  \caption{Neural Network: Confusion Matrix}%
  \label{fig:conMat_NN}%
}%
\capbtabbox{%
\begin{tabular}{|c|c|c|c|c|}
\hline
Year & 1 & 2 & 3 & 4 \\
\hline
\multicolumn{5}{c}{Neural Network} \\
\hline
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
\hline
\end{tabular}
}{%
  \caption{A table}%
}
\end{floatrow}
\end{figure}

\end{document}

enter image description here

I used \includegraphics[width=\linewidth]{example-image}, so the image uses all the available horizontal space (approx. half of \textwidth). Use 0.7\linewidth or so for something a bit narrower.

I also fixed your table “header” (Year 1, etc.). One & was presumably missing between Year and 1. Moreover, without all &s, the right vertical rule would not be drawn.

2
  • Thank you very much! I really appreciate your help, it works great and looks very nice in the paper.
    – user113156
    Feb 7 '20 at 23:37
  • 1
    You're welcome, glad to help. :-)
    – frougon
    Feb 7 '20 at 23:46
1

You can load the floatrow package, which can manage mixed float types with \killfloatstyle command:

\documentclass[12pt]{article}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{floatrow}

\begin{document}

\begin{figure}[!ht]\TopFloatBoxes
\begin{floatrow}
\ffigbox[\FBwidth]{\caption{Neural Network: Confusion Matrix}\label{fig:conMat_NN}}{\includegraphics[width=0.5\textwidth, angle=0]{conMat_NN.pdf}}
\killfloatstyle
\ttabbox{\caption{some caption}\label{tab:stats}}{%
\begin{tabular}{|c|c|c|c|c|}
\multicolumn{5}{c}{Statistics} \\
\hline
Year 1 & 2 & 3 & 4 & \\
\hline
\multicolumn{5}{c}{Neural Network} \\
\hline
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
Accuracy & 0.78 & 0.76 & 0.74 & 0.72 \\
\hline
\end{tabular}}
\end{floatrow}
\end{figure}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.