[Tex/LaTex] How to float box of text on the right side without leaving a gap throughout the rest of the document

floatswrapfigure

Problem

I am trying to create a document where a box of text will float on the right side. The rest of the text within the document should flow around the box. My searches have lead me to wrapfigure, but it doesn't seem to work the way I expected.

In my first example below I use wrapfigure without specifying a number of lines and the page doesn't wrap at all. It essentially creates two columns because there is a large gap for the rest of the document. The second page isn't showed, but it has a gap the whole way down.

The second example shows the same code except I specify the number of lines on wrapfigure. It only wraps for 3 lines which is what I expect, but it does it for every paragraph in the document. Again, the second page isn't shown.

I want all text to be the full width of the document except for the areas where the box is. This seams like it shouldn't be too difficult, but I haven't figured it out yet.

wrapfigure (default number of lines)

Code

\documentclass[10pt]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{framed}
\usepackage{lipsum} % for dummy text only
\usepackage[alpine,misc]{ifsym}
\textheight=9.0in
\pagestyle{empty}
\setlength{\tabcolsep}{0in}

\usepackage{hyperref}

\newcommand\invisiblesection[1]{%
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
  \sectionmark{#1}}


\begin{document}

\begin{wrapfigure}{r}{2.1in}

\footnotesize
\begin{framed}

\invisiblesection{\textit{Side Bar}}
\subsection*{Side Section A}

\lipsum[1]

\end{framed}
\end{wrapfigure}

{\Huge Title}\\
\textit{\small subtitle}

\pagebreak[1]
\section*{Section 1}

\lipsum[1-4]

\pagebreak[1]
\section*{Section 2}

\lipsum[1-4]
\end{document}

Example

Example with default number of lines page 1

wrapfigure (3 number of lines)

Code

\documentclass[10pt]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{framed}
\usepackage{lipsum} % for dummy text only
\usepackage[alpine,misc]{ifsym}
\textheight=9.0in
\pagestyle{empty}
\setlength{\tabcolsep}{0in}

\usepackage{hyperref}

\newcommand\invisiblesection[1]{%
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
  \sectionmark{#1}}


\begin{document}

\begin{wrapfigure}[3]{r}{2.1in}

\footnotesize
\begin{framed}

\invisiblesection{\textit{Side Bar}}
\subsection*{Side Section A}

\lipsum[1]

\end{framed}
\end{wrapfigure}

{\Huge Title}\\
\textit{\small subtitle}

\pagebreak[1]
\section*{Section 1}

\lipsum[1-4]

\pagebreak[1]
\section*{Section 2}

\lipsum[1-4]
\end{document}

Example

Example with 3 number of lines page 1

Best Answer

wrapfig works best if there is just plain text that is wrapping round the figure:

enter image description here

\documentclass[10pt]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{framed}
\usepackage{lipsum} % for dummy text only
\usepackage[alpine,misc]{ifsym}
\textheight=9.0in
\pagestyle{empty}
\setlength{\tabcolsep}{0in}

\usepackage{hyperref}

\newcommand\invisiblesection[1]{%
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
  \sectionmark{#1}}


\begin{document}

\part{Title}
\textit{\small subtitle}


\section*{Section 1}

\begin{wrapfigure}{r}{2.1in}
\vspace{-4cm}
\footnotesize
\begin{framed}

\invisiblesection{\textit{Side Bar}}
\subsection*{Side Section A}

\lipsum[1]

\end{framed}
\end{wrapfigure}
\lipsum[1-4]


\section*{Section 2}

\lipsum[1-4]
\end{document}