Most ectotherms mature at a larger body size in colder conditions. This negative relationship between developmental temperature and final body size is termed the temperature-size rule. In this study, we investigated how dietary protein:carbohydrate (P:C) balance modulates the fundamental relationship between temperature and body size in the final-instar caterpillars of Spodoptera litura. The magnitude and sign of the thermal reaction norm for body size were altered by the dietary P:C balance of the food eaten by caterpillars. The slope of the reaction norm was flat for caterpillars raised on a nutritionally balanced food (P:C = 1:1) but was negative for those on imbalanced foods (1:5 or 5:1). When allowed to self-compose their preferred diet, caterpillars preferred carbohydrate-rich food at higher temperatures. The negative impact of high temperature on body size was mitigated by such a temperature-driven shift in nutrient preference. This study highlights the importance of macronutrient balance as a key factor modulating the relationship between temperature and body size in insects.