There's one thing I always find impressive and moving when I see it in accounts of historical events or depicted well in fiction: gallows humour, when a person who is facing likely or certain death cracks a joke. I'd like to put a little of this in a story I'm writing, partly to give a (possibly last) glimpse of the more likeable side of a character who has not been acting admirably earlier in the story.
But I don't want the reader to laugh. At least not for more than a moment. Sorry, this is not a happy scene. I don't want to lose either the tension or the sadness of the characters' situation.
Do people have any tips on how to pull this off, and/or examples of stories where it is done well?