Does the landing gear compartment has to stick out like that? Why doesn't passenger jet don't look like this?
This is a subject close to my heart. The other two answers are true but not the whole story. The first to notice is the matter of high wing or low wing.
Most passenger aircraft have low wings among other reasons because the fuselage is higher in the water if you get into the drink which happens very rarely nowadays but we all remember that landing into the Hudson after a double engine failure. It enables you to mount the main undercarriage members further apart than the diameter of the fuselage without anything sticking out. In an aircraft with swept wings the undercarriage fits behind the main wing box which can be filled with fuel. But even in the Boeing 747 you see the main gear stowage exceeding the fusion of fuselage and wing.
But in smaller aircraft the fuselage gets to far above the ground because of the diameter of the diameter of the high bypass engines and military cargo aircraft have their own reasons. The last also often use large low pressure tires that cannot be fitted below the cargo floor. The distance between left and right main wheel is also important. Even so the drag of these large bulges is often much less than the drag due to the loading ramp.
And even this is only just scratching the surface.