表格和圖表未對齊

表格和圖表未對齊

表格和圖表沒有垂直對齊,我不知道如何解決。有什麼建議麼?

\begin{tabular}{|c|c|} \hline
    $x$     &   $y$ \\ \hline 
    $-2$    &   $-5$    \\ \hline
    $-1$    &   $-3$    \\ \hline
    $0$ &   $-1$    \\ \hline
    $1$ &   $1$ \\ \hline
    $2$ &   $3$ \\ \hline
    $3$ &   $5$ \\ \hline
\end{tabular} 
\hspace{5cm}
\begin{tikzpicture}[scale=.3]
    \begin{scope}
        \clip (-10,-20) rectangle (10,0);
        \draw[step=2cm,gray,very thin]
            (-12,-22) grid (10,0);
    \end{scope} 
    \draw [<->] (-11,-10) -- (11,-10);
    \draw [<->](0,-21) -- (0,1);
    \clip (-10,-20) rectangle (10,0);
\end{tikzpicture}

答案1

您可以在 中使用tfortabular(current bounding box.base)for選項:baseline=tikzpicture

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tabular}[t]{|c|c|} \hline
    $x$     &   $y$ \\ \hline 
    $-2$    &   $-5$    \\ \hline
    $-1$    &   $-3$    \\ \hline
    $0$ &   $-1$    \\ \hline
    $1$ &   $1$ \\ \hline
    $2$ &   $3$ \\ \hline
    $3$ &   $5$ \\ \hline
\end{tabular}% 
\hspace{5cm}%
\begin{tikzpicture}[baseline=(current bounding box.base),scale=.3]
    \begin{scope}
        \clip (-10,-20) rectangle (10,0);
        \draw[step=2cm,gray,very thin]
            (-12,-22) grid (10,0);
    \end{scope} 
    \draw [<->] (-11,-10) -- (11,-10);
    \draw [<->](0,-21) -- (0,1);
    \clip (-10,-20) rectangle (10,0);
\end{tikzpicture}

\end{document}

在此輸入影像描述

%請注意我添加了兩次以刪除虛假空格的字元。也許您可以使用 來代替硬連線的水平空間\hfill

相關內容