用图形和表格分割图形

用图形和表格分割图形

我正在尝试让函数图和表格环境的图像看起来还不错,但遇到了麻烦。以下是代码片段。

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

我已附加此代码片段的 PDF 输出的屏幕截图。输出1

我不明白为什么图像和表格会偏移。由于表格和图像的高度大致相同,我想将它们排列得更少一些,留出更少的空白。我该怎么做?

我曾尝试使用子图来修复它,但没有成功。

答案1

以下是关于如何使图像和表格垂直居中的两种不同建议:

在此处输入图片描述

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

\usepackage[export]{adjustbox}

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

如果要使图像和表格顶部对齐,可以使用

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

附注:您可能不想手动对子问题进行编号,而是希望使用如下所示的类\parts机制 :exam

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

\usepackage[export]{adjustbox}

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

相关内容