TransWikia.com

Exam package: How can I stick part and solutionbox together?

TeX - LaTeX Asked by Jens Metzner on January 7, 2021

I’m using the exam class and have the problem with the parts enviroment in combination with the solutionorbox enviroment. The part and the corresponding solutionorbox should be on the same page. Here is an example that demonstrate the problem:

documentclass{exam}
usepackage{blindtext}
begin{document}
begin{questions}
titledquestion{Farben}
begin{parts}
part[4] Question 1 blindtext
begin{solutionorbox}[16cm]
    blindtext
end{solutionorbox}
part[4] Question 2 blindtext
begin{solutionorbox}[10cm]
    blindtext
end{solutionorbox}
end{parts}
end{questions}
end{document}

I have tried to modify the part command by using etoolbox package but it does not work with:

preto{part}{parnobreakvfilpenalty 9999vfilnegvtopbgroup}

This is the part definition in the exam.cls:

defpart{%
  @bonusfalse
  process@part
}%

How can I add a newpage if needed that the question and the space for a solution is on the same page without adding the newpage?

One Answer

Probably not really a good solution, but it's a start.

First of all, you have to move you preto patch within the parts environment, because part is defined there. Then, because part now has a bgroup, you have to end your item with an egroup.

documentclass{exam}
usepackage{blindtext}
usepackage{etoolbox}
begin{document}
begin{questions}
titledquestion{Farben}
begin{parts}
preto{part}{parnobreakvfilpenalty 9999vfilnegvtopbgroup}
part[4] Question 1 blindtext
begin{solutionorbox}[16cm]
    blindtext
end{solutionorbox}
egroup
part[4] Question 2 blindtext
begin{solutionorbox}[10cm]
    blindtext
end{solutionorbox}
egroup
end{parts}
end{questions}
end{document}

enter image description here

Answered by Jesse op den Brouw on January 7, 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