Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The table and graph are not vertically aligned and I don't know how to fix it. Any suggestions?

\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}
share|improve this question

1 Answer 1

up vote 5 down vote accepted

You can use the t option for tabular and (current bounding box.base) for baseline= in the 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}

enter image description here

Notice the character % that I added twice to remove spurious blank spaces. Perhaps instead of a hardwired horizontal space you could use \hfill.

share|improve this answer
    
Thank you so much...this is perfect. –  Garth Fleming Aug 26 '12 at 5:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.