how to write an onomatopoeia in a short story?

You can do just about anything in fiction, as long as it works. (Caveat - if you're taking a course, do what the teacher says.) And yes, you'd probably either underline (which is typewriter formatting to indicate italics) or italicize the word.

That is, I'm assuming you mean something along the lines of

Bang! Sinaid jumped. Was that a gunshot?

or, perhaps,

Charlie listened carefully. Pee-yert! Pee-yert! That high, squeaky call was a northern beardless tyrannulet. Evidently he'd been dumped somewhere in northern Mexico, or perhaps southeastern Arizona.

On the other hand, you would not italicize or underline it here:

Sinaid heard a bang. She jumped. Was that a gunshot?

And if Charlie was talking, the format probably would be "I heard the 'pee-yert' of a northern beardless tyrannulet, and knew I was in northern Mexico -- maybe southeastern Arizona."

Looking for some sources, I find http://blog.janicehardy.com/2010/06/did-you-hear-that.html , which includes an example very like my first.

http://literarydevices.net/onomatopoeia/

includes, from a song in Shakespeare's "The Tempest," Hark, hark! I hear / The strain of strutting chanticleer / Cry, ‘cock-a-diddle-dow!'

(I put slashes in because, for some reason, I couldn't get the lines of the song to drop down to new lines)

You'll note that there's no itals there or in that page's next example, because the sounds are being described rather than transcribed, as it were.

He saw nothing and heard nothing but he could feel his heart pounding and then he heard the clack on stone and the leaping, dropping clicks of a small rock falling. -- For Whom the Bell Tolls by Ernest Hemingway

FWIW, good places online to talk about writing fiction include forums.compuserve.com/discussions/Books_and_Writers_Community/ws-books? Membership is free.