TransWikia.com

Wrapfig environment doesn't wrap

TeX - LaTeX Asked on September 2, 2021

[1]: https://i.stack.imgur.com/L7Fuh.png

enter image description here

My image is leaving a gap through the whole page, here is my code:

documentclass[12pt,a4paper,notitlepage]{book}

usepackage{wrapfig}
usepackage{float}
usepackage{graphicx}
newcommandfixedalign{hspace{0.5linewidth} & hspace{0.5linewidth} nonumber [-baselineskip]}

begin{document}
begin{wrapfigure}{R}{0.4textwidth}
includegraphics[width=0.4textwidth]{examples-examples.jpg}
    label{fig:example_graph}
    caption{dfxdxkjfrgbdxjhb  guijchbg jrcb g dxhjgmhbjfbgdm xg dxjgbjmdxbx jgexmdgjx ymgsjdxuygh esjdrg ddjshx ujsegyrj hgxddj ghsmdx djx ygsjdxy gmesjy gaku esr aeyr aerhkjaekrit iea urhuarhku}
end{wrapfigure}
subsection*{hjbmbjbjj kiihiki,l}
subsubsection*{iiihkihuhi 827883} % make a command
kbhhfj:
$$3233 31 4 331 32  2313$$

zxdfg, ahgvcsgdc 3 gyg uu tgff jkfddvfxjn,d xfk j kjfskjsbkfdjdbs z bj sfkjzkdnkzjjn k zj ks  form fhddz hbdjazs,bhszzszj

begin{align*} %fixedalign
3232434242  3142 4321 14324&31 
5353253235 53 & 4353425234234
4221244 423421412 4213412 &424421 1212 
4421424121423 4123142 &4324424343432432
end{align*}

3241412332 tgfgfd gx nfhfdg gfgfx bgfc gf gfb ccgf cvcbbcvbbcvvbbfrgf fs dg sfgafygagyregryvc craywkcrjscr
$$32413243421 42 42142143 333 3 43 43 3 3$$

subsubsection*{Example 1.1.2}
rggdd:
$$fgfggfg324342313421$$

begin{align*}fixedalign
424224 &234343233 
2342414124v  5412412  & 22312332413412 
3234342 & 4224142 3241314132  1122121 
end{align*}
32414gd gh g hfgsh ghg shghd sg  asgh g shsg hgh hgfs
sh gshsg  hghsghs 
g shgshhgsgsh tswhhhhhhhhhhhgggggggggggggggggggggggggshfg
end{document}

One Answer

The most important problem is that wrapfig assumes every line, equation, and box takes precisely baselineskip of space. The easiest solution is to manually adjust the optional argument of wrapfigure to fit the text. The second problem is that @afterheading (used by section and subsection) messes with everypar, hense the WFclear.

I replaced some of the random characters so that I could tell whether of not it was working without doing a letter by letter check. label should go after caption.

documentclass[12pt,a4paper,notitlepage]{book}

usepackage{wrapfig}
usepackage{float}
usepackage{graphicx}
usepackage{mathtools}
newcommandfixedalign{hspace{0.5linewidth} & hspace{0.5linewidth} nonumber [-baselineskip]}

usepackage{lipsum}

begin{document}
begin{wrapfigure}[5]{R}{0.4textwidth}
includegraphics[width=0.4textwidth]{example-image}
    caption{Figure capton here.}label{fig:example_graph}
end{wrapfigure}
subsection*{An intelligible strng}
subsubsection*{Some more identifiable text} % make a command
Start of paragraphe:
$$3233 31 4 331 32  2313$$

LipsumPar{2}

WFclear% not sure why this is needed - proabably @afterheading
begin{align*} %fixedalign
3232434242  3142 4321 14324&31 
5353253235 53 & 4353425234234
4221244 423421412 4213412 &424421 1212 
4421424121423 4123142 &4324424343432432
end{align*}

3241412332 tgfgfd gx nfhfdg gfgfx bgfc gf gfb ccgf cvcbbcvbbcvvbbfrgf fs dg sfgafygagyregryvc craywkcrjscr
$$32413243421 42 42142143 333 3 43 43 3 3$$

subsubsection*{Example 1.1.2}
rggdd:
$$fgfggfg324342313421$$

begin{align*}fixedalign
424224 &234343233 
2342414124v  5412412  & 22312332413412 
3234342 & 4224142 3241314132  1122121 
end{align*}
32414gd gh g hfgsh ghg shghd sg  asgh g shsg hgh hgfs
sh gshsg  hghsghs 
g shgshhgsgsh tswhhhhhhhhhhhgggggggggggggggggggggggggshfg
end{document}

Correct answer by John Kormylo on September 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP