Is there a reason given as to why Trantor is completely underground? Seems like would be a huge waste of space for it. I know there are 40+ billion people there, but would think a planet sized city would be more like Coruscant in Star Wars. Tall buildings and underground.
Short answer, it's not all underground. "Trantor's buildings are all subterranean or under domes due to worsening weather conditions" as indicated by Wikipedia, sourced to Prelude to Foundation, pages 110 and 118. And, in the original trilogy, the city was described as being towers, closer to Coruscant's depiction.
The answer is given in Prelude to Foundation -- it's climate change. Trantor's climate deteriorated as it was developed and urbanised, to the extent that people preferred to live underground.
And Trantor itself is a bigger puzzle than almost any world. According to the records, it had a fairly normal weather pattern when it was first settled. Then, as the population grew and urbanization spread, more energy was used and more heat was discharged into the atmosphere. The ice cover contracted, the cloud layer thickened, and the weather got lousier. That encouraged the movement underground and set off a vicious cycle. The worse the weather got, the more eagerly the land was dug into and the domes built and the weather got still worse. Now the planet has become a world of almost incessant cloudiness and frequent rains - or snow when it's cold enough. The only thing is that no one can work it out properly. No one has worked out an analysis that can explain why the weather has deteriorated quite as it has or how one can reasonably predict the details of its day-to-day changes.
The opening to Foundation (where Gaal Dornick arrives on Trantor) states that everyone on Trantor is agoraphobic due to never seeing the open sky. The world-city is kilometers deep, and nobody wants windows. But its not exactly underground, its just that "ground level" has ceased to be a useful concept.
The only green space is around the Emperor's palace:
There was no green to be seen; no green, no soil, no life other than man. Somewhere on the world, he realized vaguely, was the Emperor's palace, set amid one hundred square miles of natural soil, green with trees, rainbowed with flowers. It was a small island amid an ocean of steel, but it wasn't visible from where he stood.
This implies that the climate is not so unpleasant as to prevent the Emperor from taking the air in his garden. On the other hand perhaps the garden has a transparent dome. And I wonder how he recruits gardeners, given the general agoraphobia. Perhaps he invites recalcitrant politicians out for a stroll and won't let them back in unless they agree with him.
Note: technically agoraphobia is not specifically a fear of big open spaces or open skies. The technical name for fear of falling into the sky is casadastraphobia.