You should use the subfig
package.
\begin{table*}
\subfloat[First caption]{\begin{tabular}{...}...\end{tabular}}
\subfloat[Second caption]{\begin{tabular}{...}...\end{tabular}}
\caption{Overall caption}
\end{table*}
This can be used in conjunction with the floatrow
package. See the subfig
documentation for an example that aligns captions using floatrow
.
EDIT:
Your example has an extra \begin{table}
that doesn't belong. It also has a blank line which causes TeX to start a new paragraph which is why one table appears on top of the other.
Here's a complete example where I've also cleaned up your tables following the guidelines given in the documentation to the booktabs
package.
\documentclass[twocolumn]{article}
\usepackage{subfig}
\usepackage{booktabs}
\begin{document}
\begin{table*}
\subfloat[Before processing]{
\begin{tabular}{ccccc}
\toprule
Year & Month & Country & State & Impressions\\
\midrule
2007 & JAN & IN & TN & 3\\
2007 & JAN & IN & TN & 1\\
\bottomrule
\end{tabular}
}%
\hfill
\subfloat[After processing]{
\begin{tabular}{ccccc}
\toprule
Year & Month & Country & State & Impressions\\
\midrule
2007 & JAN & IN & TN & 7\\
2007 & FEB & IN & KA & 13\\
\bottomrule
\end{tabular}
}
\caption{overall}
\end{table*}
\end{document}
knitr
has a few pretty straightforward ways of handling this.
Option 1: Using knit_child()
with inline R code
Say your setup is like the following. In the same directory, you have:
graph.R
## ---- graph
library(ggplot2)
CarPlot <- ggplot() +
stat_summary(data= mtcars,
aes(x = factor(gear),
y = mpg
),
fun.y = "mean",
geom = "bar"
)
CarPlot
chapter1.Rnw
Hey, look, a graph (Figure~\ref{fig:graph})!
<<graph, echo=FALSE, message=FALSE, fig.lp='fig:', out.width='.5\\linewidth', fig.align='center', fig.cap="A graph", fig.pos='h!'>>=
@
main.Rnw
\documentclass{article}
\begin{document}
<<external-code, echo=FALSE, cache=FALSE>>=
read_chunk('./graph.R')
@
\Sexpr{knit_child('chapter1.Rnw')}
\end{document}
Then, you can knit
the main.Rnw
file and compile the resulting .tex
file with either pdflatex
or xelatex
.
The output is:

Note that you can also read the external .R
file from the child .Rnw
file.
So, the following would have worked just as well.
chapter1-mod.Rnw
<<external-code, echo=FALSE, cache=FALSE>>=
read_chunk('./graph.R')
@
Hey, look, a graph (Figure~\ref{fig:graph})!
<<graph, echo=FALSE, message=FALSE, fig.lp='fig:', out.width='.5\\linewidth', fig.align='center', fig.cap="A graph", fig.pos='h!'>>=
@
main-mod.Rnw
\documentclass{article}
\begin{document}
\Sexpr{knit_child('chapter1-mod.Rnw')}
\end{document}
Option 2: Using chunk option child
Assuming you have graph.R
and chapter1.Rnw
from above in the same directory, then your main.Rnw
should be:
\documentclass{article}
\begin{document}
<<external-code, echo=FALSE, cache=FALSE>>=
read_chunk('./graph.R')
@
<<child-demo, child='chapter1.Rnw'>>=
@
\end{document}
Note that you can also read the external .R
file from within the child document in this case, too.
So, assuming you had graph.R
and chapter1-mod.Rnw
from above in the same directory, then your main-mod.Rnw
file should be:
\documentclass{article}
\begin{document}
<<child-demo, child='chapter1-mod.Rnw'>>=
@
\end{document}
Best Answer
I just ran into the same issue. (It's really annoying when trying to produce print-quality preprint versions of the paper.) Poking around in pnastwo.cls, I found the following fix:
Find the first line in pnastwo.cls which says
Change this to
Alternatively, if you don't want to touch the class file, you can put the following into the preamble of your document:
One additional comment: once this bug is fixed, you'll almost certainly run into another issue which you'd want fixed if you use the PNAS two-column class to produce production-quality output: Unless you define floats with the h "here" placement, it loses the labels, so all cross-referencing of figures and tables breaks. Here is the fix, for direct pasting into the document preamble. You can also patch up the macro \DonormalEndcol pnastwo.cls, it's the same mistake 6 times over...