The energy-momentum tensor in scalar and gauge field theories