Sensitivity to input voltage for temperature sensor

I made a temperature sensor with my Arduino, but noticed that the measured temperature is sometimes a few degrees too high.

What I think happens is that in the conversion from the analog reading to a voltage, I multiply by 5 V / 1023 steps .
However, what if the supply is not exact 5 V? Say it's 4,8V (when using a longer USB cable) ? The 5/1023 should actually be 4,8/1023...

The 5/1023 is hardcoded in the program, so the output is off when the input voltage isn't exact 5 V.

What are ways to get rid of this dependency? Battery operated sensors must face the same issue, with the battery voltage dropping over time?

Thanks for any ideas!

You can measure the power voltage relative to the internal voltage reference but since the internal reference is between 1.0V and 1.2V (and temperature sensitive) you won't be able to measure the power with better than 10% accuracy.

You could add a precision external voltage reference.

An alternative is to use a digital temperature sensor like the OneWire DS18B20. Then you don't have to rely on the Arduino A/D accuracy.