# Split figure with graph and table

I'm trying to get an image of a function plot and a tabular environment to look somewhat decent, and having trouble. Here is the code snippet.

\documentclass{article}
\usepackage{graphicx}

\begin{document}

(a) On the left is the Cartesian plot of the function $y = 2 + 2 \cos (x)$ with
$0 \le x \le 2 \pi$. Using it, fill in the table, following the format
established in the first row.

\includegraphics[scale=0.5]{cosine-2}
\begin{tabular}{l|l}
Range & Behavior of $2 + 2 \cos \theta$ \\
\hline
$\left( 0, \frac \pi 2 \right)$ & Decreasing from 4 to 2 \\
\hline
$\left(\frac \pi 2, \pi \right)$ & \\
\hline
$\left(\pi, \frac{3\pi}{2} \right)$ & \\
\hline
$\left(\frac{3\pi}{2}, 2\pi \right)$ &
\end{tabular}

\end{document}


I have attached a screenshot of the PDF output of this code snippet. Output1

I do not understand why the image and table are offset as they are. Since the table and image are about the same height, I would like to arrange them to leave less blank space. How can I do that?

I briefly tried to fix it using subfigures, but I was not successful.

• Welcome to TeX.SX! Could you please make your code fragment compilable (see minimal working example (MWE)) by adding the documentclass as well as the relevant packages? – leandriis Aug 12 at 19:12
• I have added the document class and graphicx package. I do not know which other elements of my code require which packages, if any. – Joshua Ruiter Aug 12 at 19:17
• You can easily test this by copying the code from your question into a blank document. If you can successfully compile it and the original alignment / issue can be reproduced with the code, you have created a MWE. – leandriis Aug 12 at 19:20

Here are two different suggestions on how to vertically center image and table with respect to each other:

\documentclass[addpoints,12pt,answers]{exam}
\usepackage{graphicx}

\begin{document}

(a) On the left is the Cartesian plot of the function $y = 2 + 2 \cos (x)$ with
$0 \le x \le 2 \pi$. Using it, fill in the table, following the format
established in the first row.

\includegraphics[scale=0.5,valign=c]{example-image}
\begin{tabular}{l|l}
Range & Behavior of $2 + 2 \cos \theta$ \\
\hline
$\left( 0, \frac \pi 2 \right)$ & Decreasing from 2 to 0 \\
\hline
$\left(\frac \pi 2, \pi \right)$ & \\
\hline
$\left(\pi, \frac{3\pi}{2} \right)$ & \\
\hline
$\left(\frac{3\pi}{2}, 2\pi \right)$ &\\
\end{tabular}

\bigskip

(a) On the left is the Cartesian plot of the function $y = 2 + 2 \cos (x)$ with
$0 \le x \le 2 \pi$. Using it, fill in the table, following the format
established in the first row.

\begin{minipage}{0.475\textwidth}
\centering
\includegraphics[scale=0.5,valign=t]{example-image}
\end{minipage}
\hfill
\begin{minipage}{0.475\textwidth}
\centering
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l|l}
Range & Behavior of $2 + 2 \cos \theta$ \\
\hline
$\left( 0, \frac{\pi}{2} \right)$ & Decreasing from 2 to 0 \\
\hline
$\left(\frac{\pi}{2}, \pi \right)$ & \\
\hline
$\left(\pi, \frac{3\pi}{2} \right)$ & \\
\hline
$\left(\frac{3\pi}{2}, 2\pi \right)$ &\\
\end{tabular}
\end{minipage}
\end{document}


If you want to top align image and tabular, you can use

\includegraphics[scale=0.5,valign=t]{example-image}
\begin{tabular}[t]{l|l}


As a side note: Instead of manually numbering the subquestions, you might want to use the \parts mechanism of the exam class as shown below:

\documentclass[addpoints,12pt,answers]{exam}
\usepackage{graphicx}

\begin{document}

\begin{questions}
\question
This is the question text
\begin{parts}
\part On the left is the Cartesian plot of the function $y = 2 + 2 \cos (x)$ with
$0 \le x \le 2 \pi$. Using it, fill in the table, following the format
established in the first row.

\begin{minipage}{0.475\textwidth}
\centering
\includegraphics[scale=0.5,valign=t]{example-image}
\end{minipage}
\hfill
\begin{minipage}{0.475\textwidth}
\centering
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{l|l}
Range & Behavior of $2 + 2 \cos \theta$ \\
\hline
$\left( 0, \frac{\pi}{2} \right)$ & Decreasing from 2 to 0 \\
\hline
$\left(\frac{\pi}{2}, \pi \right)$ & \\
\hline
$\left(\pi, \frac{3\pi}{2} \right)$ & \\
\hline
$\left(\frac{3\pi}{2}, 2\pi \right)$ &\\
\end{tabular}
\end{minipage}
\end{parts}
\end{questions}
\end{document}

• Thank you, the second method involving minipages worked on the first try. I still do not understand what your code does in the 1st example that is different from my code, is it just the \usepackage[export]{adjustbox} and valign=c? With respect to the "parts," yes, I use parts but I hardcoded it just for the MWE. – Joshua Ruiter Aug 12 at 19:30
• @JoshuaRuiter: You correctly observed that the additional package and the option are the only difference to your original code. The baseline of an image is at its bottom while the baseline of a tabular is at its center. Therefore the vertical center of the table is at the same height as the bottom of the image in your example. To change the baseline of the image, one can use the package and option that I used. To change the baseline of the tabular, you can use the optional argument ([t], [b]) For an example of top aligned image and tabular, please see my updated answer. – leandriis Aug 12 at 19:35
• @leandris : Where can I get a documentation ou user book for "class=exam"? Within ctan.org I get easily docs for packages but for class=exam it seems impossible. – pzorba75 Aug 13 at 3:23