2

I've checked out related questions here, and found similar answers via Google, and still can't figure out why the following code does not produce two side-by-side tables. They are narrow enough to fit on the page, but for any variation of textwidth, using either parbox or minipage, I always get the tables stacked vertically on top of each other instead of left to right.

I must be missing something obvious, but this is driving me nuts. What have I done wrong?

\documentclass{article}
\usepackage[margin=1in]{geometry}
\begin{document}

\begin{table}[h]
 \begin{minipage}{0.4\textwidth}
  \centering
  \begin{tabular}{|l|l|c|}\hline
    Site & Species & Abundance \\\hline
    S1 & A.rubrum & 25 \\
    S1 & A.saccharum & 5 \\
    S2 & Q.rubrum & 45 \\\hline
  \end{tabular}
  \caption{Long-form data}
  \label{tab:long-form}
\end{minipage}

\begin{minipage}{0.5\textwidth}
 \centering
 \begin{tabular}{|l|c|c|c|}\hline
  Sites & A.rubrum & A.sacch & Q.rubrum \\\hline
  S1    & 25 & 5 & 0 \\
  S2    & 0 & 0 & 45 \\\hline
 \end{tabular}
 \caption{Wide-form data}
 \label{tab:wide-form}
\end{minipage}

\end{table}

\end{document}
2
  • This isn't related to your question, but you might consider following the advice in the booktabs package's manual for making good looking tables. – TH. Mar 27 '11 at 11:14
  • @TH: Yes, you're right, and normally I would. In this particular instance, the tables are meant to be examples of spreadsheet data, so I've added extra lines to make it look closer to what you see in Excel. That may still be excessive, though! – Tyler Mar 27 '11 at 13:43
8

The empty line between the minipages generates a new paragraph. This pushes the second one down. Simply remove that line or end it with % will avoid the paragraph.

1
  • Ack! I can't tell you how much time I spent staring at that code, trying and retrying every variation I could think of. Thank you!!! – Tyler Mar 26 '11 at 23:50

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.