Q. What is the correct way to format this sentence? When she cried, “That’s not fair!,” he merely shrugged. Where would the comma go? Both inside and outside the quotation marks look wrong, as does omitting it altogether.
A. The punctuation in your example makes sense, but the comma after the exclamation point is omitted in dialogue as a matter of convention, even when the sentence structure would seem to require one:
When she cried, “That’s not fair!” he merely shrugged.
But if that looks a little uneven, note also that words that are described or reported as having been said (When she cried) rather than being presented directly as dialogue (She cried) don’t always need an introductory comma—especially in fiction, a subtle but useful distinction explained in more detail by Amy Schneider on pages 164 and 165 of her book The Chicago Guide to Copyediting Fiction (University of Chicago Press, 2023).
Accordingly, you can omit commas entirely from your example, which reads like dialogue but isn’t quite direct discourse:
When she cried “That’s not fair!” he merely shrugged.
Either approach is fine, but if the context is creative and the prose casual, you may want to choose the comma-free second option. See also CMOS 13.14 and 13.15 and, for scenarios in which a comma would follow an exclamation point, 6.125.