1

I'm trying to have a table generated by the tabular environment and a plot generated by TikZ placed side by side. I tried using the table and minipage environment since it works for having multiple tables side by side. However the two objects seems to be off vertically, what am I doing wrong?

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{gensymb}
\usepackage{pgfplots}

\begin{document}
\begin{table}
  \begin{minipage}[b]{5 cm}
  \centering
  \begin{tabular}{|c|c|}
   \hline                       
   Temperature & IQ Score \\ \hline
   14\celsius & 57\% \\ \hline
   16\celsius & 65\% \\ \hline
   18\celsius & 69\% \\ \hline
   20\celsius & 71\% \\ \hline
   22\celsius & 79\% \\ \hline
   24\celsius & 88\% \\ \hline
   26\celsius & 81\% \\ \hline
   28\celsius & 76\% \\ \hline
   30\celsius & 66\% \\ \hline
   32\celsius & 62\% \\ 
   \hline  
  \end{tabular}
  \end{minipage}
  \hspace{1cm} 
  \begin{minipage}[b]{10cm}
  \centering
   \begin{tikzpicture}
   \begin{axis}[grid=major, grid style={dashed,gray!30}, xlabel=Temperature $\celsius$,ylabel=IQ Scores \%, legend style={at={(axis cs:25,28)},anchor=south}]
   %\addplot[scatter, only marks, scatter/classes={y={black}}] table[x=x, y=y, col sep=comma] {NumbersAndFunctions-Temp-IQ-data.csv};
   \addplot[color=red, domain=7:41, thick, samples=400, mark=none] {88*exp(-(\x-24)^2/253.0889)};
   \legend{Raw, Gaussian};
   \end{axis}   
   \end{tikzpicture}
  \end{minipage}
\end{table}
\end{document}

enter image description here

Thanks

  • 1
    (1) Welcome, (2) you are much more likely to get help if you post a full minimal example instead of just a sniplet. That is something people can copy and run immediately without having to add anything. In your example we for example does not know where \celsius comes from. – daleif Dec 3 '14 at 10:09
  • Does this answer to "Vertical align a tabular and tikz figure in a minipage" help you? – Ignasi Dec 3 '14 at 10:23
  • @daleif Ah yes I'm sorry, should've paid more attention – Vinsen Dec 3 '14 at 10:50
1

These are aligned at the top:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=8cm}
\usepackage{siunitx}
\begin{document}
  \begin{table}
  \begin{minipage}[t]{5 cm}
  \centering
  \begin{tabular}[t]{|c|c|}
   \hline
   Temperature & IQ Score \\ \hline
   \SI{14}{\celsius} & \SI{57}{\percent} \\ \hline    %% change all \% like this
   \SI{16}{\celsius} & 65\% \\ \hline
   \SI{18}{\celsius} & 69\% \\ \hline
   \SI{20}{\celsius} & 71\% \\ \hline
   \SI{22}{\celsius} & 79\% \\ \hline
   \SI{24}{\celsius} & 88\% \\ \hline
   \SI{26}{\celsius} & 81\% \\ \hline
   \SI{28}{\celsius} & 76\% \\ \hline
   \SI{30}{\celsius} & 66\% \\ \hline
   \SI{32}{\celsius} & 62\% \\
   \hline
  \end{tabular}
  \end{minipage}
   \hfill
   \begin{tikzpicture}[baseline={(current bounding box.north)}]
   \begin{axis}[grid=major, grid style={dashed,gray!30}, xlabel=Temperature $\celsius$,ylabel=IQ Scores\si{\percent}, legend style={at={(axis cs:25,28)},anchor=south}]
   %\addplot[scatter, only marks, scatter/classes={y={black}}] table[x=x, y=y, col sep=comma] {NumbersAndFunctions-Temp-IQ-data.csv};
   \addplot[color=red, domain=7:41, thick, samples=400, mark=none] {88*exp(-(\x-24)²/253.0889)};
   \addlegendentry{Raw,Gaussian};
   \end{axis}
   \end{tikzpicture}
\end{table}
\end{document}

enter image description here

With no [t] in minipage and [baseline={(current bounding box.center)}] in tikzpicture they are aligned at the center.

enter image description here

With no [b] in both tabular and minipage and [baseline={(current bounding box.south)}] in tikzpicture they are aligned at the bottom.

enter image description here

  • Change all 65\% etc similar to \SI{57}{\percent}. You can see the difference. – user11232 Dec 3 '14 at 10:45
  • That makes sense now! Thank you for the help. – Vinsen Dec 3 '14 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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