I've had to layoff direct reports during multiple layoff waves at a couple different companies. (Moreover, I myself have been laid off when a small company went out of business or when a business unit was eliminated.) I don't think it's difficult to avoid cruelty during a layoff, you just have to be very honest and make it clear that it is not personal. The announcement should be company-wide, but then talk to each person individually or in small teams if possible, and afterward go together offsite to a bar/restaurant and hang out with everyone who can join.
Honestly in many cases it's better for them to move on rather than go down with a sinking ship. In tech over the past couple decades there's always been jobs elsewhere for engineers, even after the dotcom bust. I have tried to help place people elsewhere using my network and told them I'd give them a good reference if they needed one. HR tends to discourage you from making an extra effort like this -- e.g. "you should only acknowledge that they worked at the company, don't give a recommendation" -- because a recommendation can become a liability, but I feel it's my recommendation as their direct manager and I am taking personal liability for it.
---
There's something else I'd add -- not about layoffs but related to firing people. Even if you're firing someone for performance reasons, IT DOESN'T HAVE TO BE CRUEL. I've seen so many people get fired in such a cruel manner, and it's totally unnecessary. There's absolutely no need for the manager to have any sense of anger or betrayal over a person's poor performance in a role.
Someone's performance in a particular role in a particular company has nothing to do with that person's worth as an employee. It was always just a bad fit, or a bad situation -- it doesn't mean that this is a bad person or even a bad worker, and should not reflect upon their self-worth. In my career, I've had to fire two people for performance reasons, and both times I made this difference clear, and thankfully we were able to actually maintain a friendship afterwards.