[Tex/LaTex] wrapfig and rotating place figure at end of document

rotatingtableswrapfigure

With the packages wrapfig and rotating and calls to wraptable, sideways and tabular, I get a document where the table is placed at the end of the document. For instance, in a two page document defined by \pagebreak, my table gets placed on the second page, or at the end of the document, and not where I want it, on the first page where it is declared. Anyone know why this happens or have a work around?

\documentclass[12pt,letterpaper]{article}
\usepackage[american]{babel}
\usepackage{rotating}
\usepackage{wrapfig}

\begin{document}

\section{Test page 1}

\begin{wraptable}{r}{.5\textwidth}
\begin{sideways}
\begin{tabular}{l}
1 \\
2 \\
3 \\
4
\end{tabular}
\end{sideways}
\end{wraptable}

\pagebreak

\section{Test page 2}

\end{document}

Basically, I want to rotate a (sizable) table on a page that also has horizontal text.

Best Answer

wraptable is meant to be used along with text such that it wraps along. You just add text before and after wraptable, then things are set right.

\documentclass[12pt,letterpaper]{article}
\usepackage[american]{babel}
\usepackage{rotating}
\usepackage{wrapfig,lipsum}

\begin{document}

\section{Test page 1}
\lipsum[1]
\begin{wraptable}{r}{.5\textwidth}
\caption{A wrapped table will not float if there is enough text surrounding it.}\label{wrap-tab:1}
\begin{sideways}
\begin{tabular}{l}\\
1 \\
2 \\
3 \\
4
\end{tabular}
\end{sideways}
\end{wraptable}
\lipsum[2] %%% This provides text.
\pagebreak

\section{Test page 2}

\end{document}

enter image description here