# Table and plot next to each other

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

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

• 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). 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. 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. 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. Feb 7 '20 at 22:51

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}


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.

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

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}