表格和图表未垂直对齐,我不知道如何修复。有什么建议吗?
\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
您可以使用以下t
选项tabular
和的(current bounding box.base)
选项: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
。