1

I am in the process of creating a documentation and would like to learn how to efficiently place figures right next to their respective tables where there's currently whitespace. The figures are all of the same size, and if the table is shorter, the figure should drive the thin line below. Furthermore the tables should be left-aligned (as is) and the figures should be top-right-aligned.

Example figure

plot1

Tables

enter image description here

What I tried

I tried \multicols...

\begin{multicols}{2}

% code of a table section from below

\begin{figure}
\includegraphics[width=3cm]{plot1.png}
\end{figure}

\end{multicols}

...but that failed terribly.

Working example

The code in the "table sections" below is automatically generated in R, and so it will be with the figures, i.e. there will be a .png ready to place next to the table (i.e. table Type 1: plot1.png, Type 2: plot2.png etc.).

\documentclass{article}

\usepackage{booktabs}
\usepackage{dcolumn}
\usepackage{float}
\restylefloat{table}
\usepackage[T1]{fontenc}
\usepackage[fontsize=9.5]{scrextend}
\usepackage[document]{ragged2e}
\renewcommand{\familydefault}{\sfdefault}
\setlength{\parskip}{.15em plus 0.1em minus 0.2em}
\usepackage{longtable}
\usepackage[left=1.5cm,right=1.5cm,top=2cm,bottom=2cm]{geometry}

\begin{document}   

% first table section ---------------------------------------------

\vspace{.5em}Meta:\quad Type 1

Type:\quad XY

Categories:\quad 6

Complete:\quad 200\kern 0.16667em(100\%)

\vspace{-2em}\begin{table}[H]
\begin{tabular}{rlr}
\textbf{1}  &  Cat. 1  &  66 (33.0\%)  \\ 
\textbf{2}  &  Cat. 2 &  66 (33.0\%)  \\ 
\textbf{3}  &  Cat. 3 &  39 (19.5\%)  \\ 
\textbf{4}  &  Cat. 4  &  19 (9.5\%)  \\ 
\textbf{5}  &  Cat. 5  &  6 (3.0\%)  \\ 
\textbf{6}  &  Cat. 6  &  4 (2.0\%)  \\ 
\end{tabular}
\end{table}
\vspace{-3.5em}\vspace{1.618em}\hrule\vspace{1em}\par

% next table section ---------------------------------------------

\vspace{.5em}Meta:\quad Type 2

Type:\quad XY

Categories:\quad 6

Complete:\quad 200\kern 0.16667em(100\%)

\vspace{-2em}\begin{table}[H]
\begin{tabular}{rlr}
\textbf{1}  &  Cat. 1  &  66 (33.0\%)  \\ 
\textbf{2}  &  Cat. 2 &  66 (33.0\%)  \\ 
\textbf{3}  &  Cat. 3 &  39 (19.5\%)  \\ 
\textbf{4}  &  Cat. 4  &  19 (9.5\%)  \\ 
\textbf{5}  &  Cat. 5  &  6 (3.0\%)  \\ 
\textbf{6}  &  Cat. 6  &  4 (2.0\%)  \\ 
\end{tabular}
\end{table}
\vspace{-3.5em}\vspace{1.618em}\hrule\vspace{1em}\par

% and so on table sections ---------------------------------------------

\end{document}

My question is, how I need to adapt the code of the sections so it puts a figure right next to it's respective table. There are some solutions around like this one, but the tables they use are different.

1 Answer 1

2

A simple way is to use two minipages.

b

\documentclass{article}

\usepackage{booktabs}
\usepackage{dcolumn}
\usepackage{float}
\restylefloat{table}
\usepackage[T1]{fontenc}
\usepackage[fontsize=9.5]{scrextend}
\usepackage[document]{ragged2e}
\renewcommand{\familydefault}{\sfdefault}
\setlength{\parskip}{.15em plus 0.1em minus 0.2em}
\usepackage{longtable}
\usepackage[left=1.5cm,right=1.5cm,top=2cm,bottom=2cm]{geometry}

\usepackage{graphicx} % added <<<<<<<<<

\begin{document}   
    
% first table section ---------------------------------------------
    
\vspace{.5em}
    
\begin{minipage}[c]{0.5\linewidth}
Meta:\quad Type 1

Type:\quad XY

Categories:\quad 6

Complete:\quad 200\kern 0.16667em(100\%)

\begin{tabular}{rlr}
    \textbf{1}  &  Cat. 1  &  66 (33.0\%)  \\ 
    \textbf{2}  &  Cat. 2 &  66 (33.0\%)  \\ 
    \textbf{3}  &  Cat. 3 &  39 (19.5\%)  \\ 
    \textbf{4}  &  Cat. 4  &  19 (9.5\%)  \\ 
    \textbf{5}  &  Cat. 5  &  6 (3.0\%)  \\ 
    \textbf{6}  &  Cat. 6  &  4 (2.0\%)  \\ 
\end{tabular}
\end{minipage}
   \begin{minipage}{0.5\linewidth}
    \includegraphics[width=0.5\linewidth]{example-image-a}
\end{minipage}
    
\vspace{1.618em}\hrule\vspace{1em}\par

% second table section ---------------------------------------------

\vspace{.5em}

\begin{minipage}{0.5\linewidth}
    Meta:\quad Type 2
    
    Type:\quad XY
    
    Categories:\quad 6
    
    Complete:\quad 200\kern 0.16667em(100\%)
    
    \begin{tabular}{rlr}
        \textbf{1}  &  Cat. 1  &  66 (33.0\%)  \\ 
        \textbf{2}  &  Cat. 2 &  66 (33.0\%)  \\ 
        \textbf{3}  &  Cat. 3 &  39 (19.5\%)  \\ 
        \textbf{4}  &  Cat. 4  &  19 (9.5\%)  \\ 
        \textbf{5}  &  Cat. 5  &  6 (3.0\%)  \\ 
        \textbf{6}  &  Cat. 6  &  4 (2.0\%)  \\ 
    \end{tabular}
\end{minipage}
\begin{minipage}{0.5\linewidth}
    \includegraphics[width=0.5\linewidth]{example-image-b}
\end{minipage}

\vspace{1.618em}\hrule\vspace{1em}\par

\begin{minipage}[t]{0.25\linewidth}
    
Meta:\quad Type 3

Type:\quad XY

Categories:\quad 6

Complete:\quad 200\kern 0.16667em(100\%)
\begin{table}[H]
    \begin{tabular}{rlr}
        \textbf{1}  &  Cat. 1  &  66 (33.0\%)  \\ 
        \textbf{2}  &  Cat. 2 &  66 (33.0\%)  \\ 
        \textbf{3}  &  Cat. 3 &  39 (19.5\%)  \\ 
        \textbf{4}  &  Cat. 4  &  19 (9.5\%)  \\ 
        \textbf{5}  &  Cat. 5  &  6 (3.0\%)  \\ 
        \textbf{6}  &  Cat. 6  &  4 (2.0\%)  \\ 
    \end{tabular}
\end{table}
\end{minipage}
\begin{minipage}[t]{0.5\linewidth}
    \begin{figure}[H]
        \centering
        \includegraphics[width=0.4\linewidth]{example-image-c}
        \caption{This is the table--figure}
    \end{figure}
\end{minipage}
\vspace{1.618em}\hrule\vspace{1em}\par
\end{document}
1
  • This is beautiful, thx.
    – jay.sf
    May 22, 2021 at 18:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .