0

I am using wrapfig to have text cleanly flow around an image. I have a block of text with an image to the right, then a fillwithlines followed by more text. I cannot get the second block of text to fill the page width.

I tried the suggestions in this question, which work to some extent, but don't work for the second section of text below the fillwithlines. Changing the image style to float makes no difference, but adding \vspace{-70pt} to the wrapfig block does allow the first block of text to resume taking the full width of the page, but the text after the fillwithlines has the whitespace associated with the wrapfig.

This picture shows that vspace can allow the text to fill the page width after the wrapfig, but I don't know why this doesn't persist for the second block of text.

Here is a MWE: I also tried to use adjustwidth around the misbehaving text to force it to fill the page, but it doesn't respond. The adjustwidth commands can be commented out with no change to the displayed page. img_fibre.jpeg is a 300x145 pixel image.

\documentclass[11pt]{exam}
\RequirePackage{adjustbox}
\usepackage{changepage}
\usepackage{wrapfig}
\usepackage[margin=0.4in]{geometry}

\parindent 0ex

\begin{document}

\begin{wrapfigure}{R}{0.45\textwidth}
    \adjustimage{scale=0.8}{img_fibre.jpeg}
    \vspace{-70pt} % use -60pt to clear image
\end{wrapfigure}

\section*{Applications of Total Internal Reflection}

Fibre optic cables use a core glass with high refractive index, surrounded by cladding with low refractive index. Data can be sent though the fibre as pulses of light, the same way that data is encoded in electricity as varying voltage levels. Fibre optic cables are often more fragile than electrical cables. List the advantages that fibre optics offers. 

\vspace{1cm}

\fillwithlines{3cm}

\begin{adjustwidth}{0pt}{-\dimexpr\wrapoverhang+\columnsep\relax}
    In addition to common uses in data transfer and computing, applications of fibre optics include endoscopic surgery, lighting, and situations where electronic data transfer is impossible, such as underwater, or where the is strong electromagnetic interference.         
\end{adjustwidth}   

\end{document}

sideways8
  • 3
  • 2
  • adjustwidth is a 1 item list and as documented you can not use wrapfig with lists – David Carlisle Mar 20 '24 at 07:21
  • 1
    It seems a bit extreme to use exam class just to have \fillwithlines. See https://tex.stackexchange.com/questions/24512/can-latex-be-used-to-make-a-sheet-of-blank-lines – John Kormylo Mar 20 '24 at 16:30
  • I have a larger document that I am using this in, I just removed everything else to show a minimal working example. – sideways8 Mar 21 '24 at 00:59

2 Answers2

1

This shows a paracol solution. Paracol is far more robust than wrapfig, although it may require manual paragraph breaking.

Note that exam class is not compatible with the geometry package, even though the problems can be subtle.

\documentclass[11pt]{exam}
%\usepackage[margin=0.4in]{geometry}% not compativble with exam class
\RequirePackage{adjustbox}
\usepackage{changepage}
\usepackage{paracol}
\globalcounter*

\parindent 0ex \extrawidth{1.2in}% how exam class sets margins

\begin{document}

\begin{paracol}{2} \section*{Applications of Total Internal Reflection}

Fibre optic cables use a core glass with high refractive index, surrounded by cladding with low refractive index. Data can be sent though the fibre as pulses of light, the same way that data is encoded in electricity as varying voltage levels. Fibre optic cables are often more fragile than electrical cables. List the advantages that fibre optics offers. 

\switchcolumn \begin{figure}% only needed with captions \adjustimage{width=\linewidth}{example-image} \end{figure} \end{paracol}

\fillwithlines{3cm}

In addition to common uses in data transfer and computing, applications of fibre optics include endoscopic surgery, lighting, and situations where electronic data transfer is impossible, such as underwater, or where the is strong electromagnetic interference.         

\end{document}

enter image description here

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • This also works in some situations, but not in every situation. Elsewhere in my document, wrapfig works and this doesn't - when I have a figure alongside an enumerate, and the first two items are wrapped around the figure, but the remaining ones fill the width. My compiler doesn't allow a \begin{paracol} \begin{enumerate} \end{paracol} \end{enumerate} in that order. – sideways8 Mar 21 '24 at 02:55
  • With the enumitem package you can end and restart a list. See \restartlist{enumerate} in section 8,.2. – John Kormylo Mar 21 '24 at 17:26
0

You need to place the wrapfigure environment after the section command

And for the vertical adjustment, you can use the optional parameter of wrapfig environment to change the height of the wrapbox as a workaround.

\documentclass[11pt]{exam}
\RequirePackage{adjustbox}
\usepackage{changepage}
\usepackage{wrapfig2}
\usepackage[margin=0.4in]{geometry}

\parindent 0ex

\begin{document}

\section*{Applications of Total Internal Reflection}

\begin{wrapfigure}[6]{R}{0.45\textwidth}
    \vspace*{-\baselineskip}
    \adjustimage{width=0.43\textwidth,height=3cm}{example-image}
\end{wrapfigure}

Fibre optic cables use a core glass with high refractive index, surrounded by cladding with low refractive index. Data can be sent though the fibre as pulses of light, the same way that data is encoded in electricity as varying voltage levels. Fibre optic cables are often more fragile than electrical cables. List the advantages that fibre optics offers. 

\vspace{1cm}

\fillwithlines{3cm}


In addition to common uses in data transfer and computing, applications of fibre optics include endoscopic surgery, lighting, and situations where electronic data transfer is impossible, such as underwater, or where the is strong electromagnetic interference.

\end{document}

enter image description here

Mane32
  • 1,252
  • Great, this works for this section of my document. But trying it in other sections, having the wrapfigure after the section heading causes the image to clear all the text that is written after the wrapfigure in that section. Can I edit my question to show that situation below the original question? – sideways8 Mar 20 '24 at 06:21