[Tex/LaTex] Text not spanning full page after wraptable

tableswidthwrapwrapfigure

I wonder why latex doesn't go back to full textwidth after a table that was added in a wraptable?

The actual code where I experience this problem is here: http://pastebin.com/CRjHMZdT

I would expect, that after the table has been rendered to the right side of the page, the then following text is able to span the whole width of the page. Instead, this is what happens:

output

((On the following page, the text is set across the whole width again.))*
I compile using

latex "${FILE}.tex"
dvips -Ppdf -o "${FILE}-pics.ps" "${FILE}.dvi"
ps2pdf -dAutoRotatePages=/None "${FILE}-pics.ps" "${FILE}-pics.pdf"
pdflatex "${FILE}.tex"

EDIT Ok, this* is not true, on the following pages, the text can't take up full textwidth, too.

EDIT 2
Ok, I tried to make a MWE from my original code which shows the same problem.
This code now shows the same problem (and another one, something seems to be really wrong)

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{wrapfig}
\begin{document}
\begin{wraptable}{r}{5cm}
  \centering
  \begin{tabular}{|c|c|c|c|}
    \hline
    $i$ & $NW_{i1}$ & $NW_{i2}$ & $NW_{i3}$ \\\hline\hline
    0 & 0 & 0 & 0 \\\hline
    1 & 0 & 0 & 1 \\\hline

  \end{tabular}
  \caption{Some table}
\end{wraptable}

\section*{A section}
\subsection*{subsections are nice}
Some text.

\begin{wraptable}{l}{5cm}
  \centering
  \begin{tabular}{|c|c|}
    \hline
    $NW_i$ & $CW_i$ \\\hline\hline
    000 & 00000 \\\hline
    001 & 10111 \\\hline
    010 & 10010 \\\hline
    011 & 00101 \\\hline
    100 & 01100 \\\hline
    101 & 11011 \\\hline
    110 & 11110 \\\hline
    111 & 01001 \\\hline
  \end{tabular}
  \caption{table two}
\end{wraptable}


\subsection*{the next subsection}
text.

\begin{wraptable}{r}{8cm}
  \centering
  %\renewcommand\arraystretch{1.3}% (MyValue=1.0 is for standard spacing) 
  \begin{tabular}{|c|c|}
    \hline
    $w$ & $A(w)$ \\\hline\hline
    0 & $\frac{0}{8}$ \\\hline
    1 & $\frac{4}{8}$ \\\hline

  \end{tabular}
  \caption{table 3}
\end{wraptable}


\subsection*{another subsection}
even more text.

\subsection*{yeah}
i want more more more more more more more more more more more more more more
more more more more more more more more more more more more more more more more
more and even more more more more more more more more more more more more more
more more more text.




\section*{another section in the wall}
text

\subsection*{yeah}
i want more more more more more more more more more more more more more more
more more more more more more more more more more more more more more more more
more and even more more more more more more more more more more more more more
more more more text.
\end{document}

(Pasting code here is not much fun, btw)

It doesn't matter if I change the tables ordering, e.g. moving the second table to the third tables position and the third table up the the former second tables position doesn't change anything.

EDIT 3
Ok, making the example more minimal (stripping out math mode, babel package, centering, caption) is possible, too. Also compiling with pdflatex AND latex gives the same result. What is wrong here?

EDIT 4
Not using the star version of section and subsection "solves" the issue. I don't think that this is a feature, it seems more like a bug to me?

Best Answer

wrapfigure/wraptable works inside section* also. But one should note the following from wrapfig manual` enter image description here

Hence you should add enough text just below the wraptable environment.

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{wrapfig,lipsum}
\begin{document}
\begin{wraptable}{r}{5cm}
  \centering
  \begin{tabular}{|c|c|c|c|}
    \hline
    $i$ & $NW_{i1}$ & $NW_{i2}$ & $NW_{i3}$ \\\hline\hline
    0 & 0 & 0 & 0 \\\hline
    1 & 0 & 0 & 1 \\\hline

  \end{tabular}
  \caption{Some table}
\end{wraptable}
\lipsum[4-5]

\section*{A section}
\subsection*{subsections are nice}
Some text.

\begin{wraptable}[13]{r}{5cm}
  \centering
  \begin{tabular}{|c|c|}
    \hline
    $NW_i$ & $CW_i$ \\\hline\hline
    000 & 00000 \\\hline
    001 & 10111 \\\hline
    010 & 10010 \\\hline
    011 & 00101 \\\hline
    100 & 01100 \\\hline
    101 & 11011 \\\hline
    110 & 11110 \\\hline
    111 & 01001 \\\hline
  \end{tabular}
  \caption{table two}
\end{wraptable}
\lipsum[1-2]


\subsection*{the next subsection}
text. 

\begin{wraptable}[7]{r}{8cm}
  \centering
  %\renewcommand\arraystretch{1.3}% (MyValue=1.0 is for standard spacing)
  \begin{tabular}{|c|c|}
    \hline
    $w$ & $A(w)$ \\\hline\hline
    0 & $\frac{0}{8}$ \\\hline
    1 & $\frac{4}{8}$ \\\hline

  \end{tabular}
  \caption{table 3}
\end{wraptable}
\lipsum[3-4]


\subsection*{another subsection}
even more text.

\subsection*{yeah}
i want more more more more more more more more more more more more more more
more more more more more more more more more more more more more more more more
more and even more more more more more more more more more more more more more
more more more text.




\section*{another section in the wall}
text

\subsection*{yeah}
i want more more more more more more more more more more more more more more
more more more more more more more more more more more more more more more more
more and even more more more more more more more more more more more more more
more more more text.
\end{document}

enter image description here

Please read the first three pages of the wrapfig manual.