TeX - LaTeX Asked on January 11, 2021
For the following, why does setlength{intextsep}{#5}
inside NewDocumentEnvironment{mywrapfigure}
not have any effect on the output, which makes me have to use setlength{intextsep}{0pt}
locally before every use of wrapfigure
? For example, image-b
doesn’t get affected by setlength{intextsep}{#5}
.
Additionally, why is the space below image-a
narrower than that below image-c
?
documentclass{exam}
usepackage{graphbox,wrapfig,duckuments}
usepackage{xparse}
% https://tex.stackexchange.com/a/266431/2288
NewDocumentEnvironment{mywrapfigure}{O{}mO{wrapoverhang}mO{0pt}}{%
setlength{intextsep}{#5}% <<< has no effect
wrapfigure[#1]{#2}[#3]{#4}%
}{%
endwrapfigure%
}
begin{document}
{% https://tex.stackexchange.com/a/365764/2288
setlengthintextsep{0pt}
begin{mywrapfigure}{r}{0.3linewidth}
includegraphics[width=linewidth]{example-image-a}
end{mywrapfigure}
blindduck[1-2]
}
bigskip
begin{questions}
begin{minipage}[t][][t]{linewidth}
question
{% https://tex.stackexchange.com/a/365764/2288
%setlengthintextsep{0pt}
begin{mywrapfigure}{r}{0.3linewidth}[0pt]
includegraphics[width=linewidth]{example-image-b}
end{mywrapfigure}
blindduck[1-2]
}
end{minipage}
bigskip
begin{parts}
begin{minipage}[t]{linewidth}
part[4]
{% https://tex.stackexchange.com/a/365764/2288
setlengthintextsep{0pt}
begin{mywrapfigure}{r}{0.3linewidth}[0pt]
includegraphics[width=linewidth]{example-image-c}
end{mywrapfigure}
blindduck[1-2]
}
end{minipage}
end{parts}
end{questions}
end{document}
Compiling the following with lualatex
documentclass{exam}
usepackage{graphbox,wrapfig,duckuments,blindtext}
usepackage{xparse}
NewDocumentEnvironment{mywrapfigure}{O{}mO{wrapoverhang}mO{1pt}}{%
setlength{intextsep}{#5}% <<< has no effect
wrapfigure[#1]{#2}[#3]{#4}%
}{%
endwrapfigure%
}
begin{document}
begin{mywrapfigure}{r}{0.3linewidth}
includegraphics[width=linewidth]{example-image-a}
end{mywrapfigure}
blindduck[1]
bigskip
begin{questions}
begin{minipage}[t]{dimexpr linewidth}
question%theeverypar
begin{mywrapfigure}{r}{0.3linewidth}
vskip-baselineskip
includegraphics[width=linewidth]{example-image-b}
end{mywrapfigure}
blindtext[1]
end{minipage}
bigskip%hrule
begin{parts}
begin{minipage}[t]{linewidth}
part[4]%theeverypar
begin{mywrapfigure}{r}{0.3linewidth}
vskip-baselineskip
includegraphics[width=linewidth]{example-image-c}
end{mywrapfigure}
blindduck[1]
end{minipage}
end{parts}
end{questions}
end{document}
I get this
Every time you put wrapfigure immediately after item
(which is used by question
and part
), it gets pushed down one line. (Interestingly rlap{...}
gets pushed up one line.) The only way to fix this is to manually add vskip-baselineskip
inside wrapfigure. It has nothing to do with intextsep
.
documentclass{exam}
usepackage{graphbox,wrapfig,duckuments}
usepackage{xparse}
NewDocumentEnvironment{mywrapfigure}{O{}mO{wrapoverhang}mO{1pt}}{%
setlength{intextsep}{#5}% <<< has no effect
wrapfigure[#1]{#2}[#3]{#4}%
}{%
endwrapfigure%
}
begin{document}
begin{mywrapfigure}{r}{0.3linewidth}
includegraphics[width=linewidth]{example-image-a}
end{mywrapfigure}
blindduck[1-2]
bigskip
begin{questions}
begin{minipage}[t]{dimexpr linewidth}
question%theeverypar
begin{mywrapfigure}{r}{0.3linewidth}
vskip-baselineskip
includegraphics[width=linewidth]{example-image-b}
end{mywrapfigure}
blindduck[1-2]
end{minipage}
bigskip%hrule
begin{parts}
begin{minipage}[t]{linewidth}
part[4]%theeverypar
begin{mywrapfigure}{r}{0.3linewidth}
vskip-baselineskip
includegraphics[width=linewidth]{example-image-c}
end{mywrapfigure}
blindduck[1-2]
end{minipage}
end{parts}
end{questions}
end{document}
Update 1
You should always use WFclear
if you run out of text before wrapfigure is done. Note the use of the optional argument [9] for the second image. Also note that linewidth
keeps getting smaller, making the images smaller as well.
documentclass{exam}
usepackage{graphbox,wrapfig,duckuments,blindtext}
usepackage{xparse}
NewDocumentEnvironment{mywrapfigure}{O{}mO{wrapoverhang}mO{1pt}}{%
setlength{intextsep}{#5}% <<< has no effect
wrapfigure[#1]{#2}[#3]{#4}%
}{%
endwrapfigure%
}
begin{document}
begin{mywrapfigure}{r}{0.3linewidth}
includegraphics[width=linewidth]{example-image-a}
end{mywrapfigure}
There once was a very smart but sadly blind duck. When it was still a small duckling it was renowned for
its good vision. But sadly as the duck grew older it caught a sickness which caused its eyesight to worsen.
It became so bad, that the duck couldn't read the notes it once took containing much of inline math. Only
displayed equations remained legible. That annoyed the smart duck, as it wasn't able to do its research any
longer. It called for its underduckling and said: Go, find me the best eye ducktor there is. He shall heal
me from my disease!"
%blindduck[1]par
bigskip
WFclear
begin{questions}
begin{minipage}[t]{dimexpr linewidth}
question
begin{mywrapfigure}[9]{r}{0.3linewidth}
vskip-baselineskip
includegraphics[width=linewidth]{example-image-b}
end{mywrapfigure}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis
facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent
imperdiet mi nec ante. Donec ullamcorper, felis non sodales commodo,
lectus velit ultrices augue, a dignissim nibh lectus placerat pede.
Vivamus nunc nunc, molestie ut, ultricies vel, semper in, velit. Ut porttitor.
Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Duis fringilla tristique neque. Sed interdum libero ut metus.
Pellentesque placerat. Nam rutrum augue a leo. Morbi sed elit sit
amet ante lobortis sollicitudin. Praesent blandit blandit mauris. Praesent lectus tellus, aliquet aliquam,
luctus a, egestas a, turpis. Mauris lacinia lorem sit amet ipsum. Nunc quis urna dictum turpis accumsan
%blindtext[1]
end{minipage}
bigskip%hrule
begin{parts}
begin{minipage}[t]{linewidth}
part[4]%theeverypar
begin{mywrapfigure}{r}{0.3linewidth}
vskip-baselineskip
includegraphics[width=linewidth]{example-image-c}
end{mywrapfigure}
There once was a very smart but sadly blind duck. When it was still a small duckling it was renowned for
its good vision. But sadly as the duck grew older it caught a sickness which caused its eyesight to worsen.
It became so bad, that the duck couldn't read the notes it once took containing much of inline math. Only
displayed equations remained legible. That annoyed the smart duck, as it wasn't able to do its research any
longer. It called for its underduckling and said: Go, find me the best eye ducktor there is. He shall heal
me from my disease!"
WFclear
end{minipage}
end{parts}
end{questions}
end{document}
Correct answer by John Kormylo on January 11, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP