You can easily minimize gaps in a teacher's schedule.
Go to Timetable constraints > Minimize teacher gaps and ensure the constraint is set to Active.
Tip: Adjust the importance of this constraint according to your needs. A higher importance will reduce teacher gaps more effectively but may affect other constraints.