The difference between the picture of the liquids all nicely layered on top of each other and an ice cube in water is that the liquids can change their shape to fit the shape of the container while the ice cannot. If the ice could change its shape and flow to fill the container, you would see exactly what your intuition predicts: the ice sits fully on top of the water. In fact, if you visualize a lake that has frozen over, that's exactly what you get! However, your ice cube cannot flow like that. So, instead, it follows Archimedes's principle, as others have suggested, and "displaces" an amount of water equal to its mass. Since it is less dense than water, that amount of displacement will lead the ice cube to rest partially submerged.
As for the marbles shaking to the top, that's slightly different. It's the same principle, just with a twist. In the case of the container of marbles being shaken, it's a stochastic process. The statistical expectation is that the average shake will cause the less-dense objects to rise to the top and more dense objects to sink. However, we rarely shake them enough to fully separate the marbles into distinct crisp layers. Compare this to liquids. The equivalent case for a liquid would be lots and lots of little marbles, and you're shaking them continuously really really fast. Naturally, we see more stratification in liquids than we do in solids, simply because of this.
Note: there is also a second effect in the case of the marbles. The above example occurs only if every object is of the same size. In the case of mixed media (such as a container of mixed nuts), this effect is overshadowed by another effect. Small objects can pile in underneath large ones, so in general the large ones (such as the macadamia nuts) rise to the top.
Even in this case, with an effect which is more pronounced than density, we don't see a perfect stratification of the mixed nuts. There's always a small number of them that are not in the "right place," such as a peanut that manages to get thrown on top of a sea of walnuts. So when you compare three cases, the stratified liquids, the ice on top of water, and the container of marbles, you actually don't see the stratified liquids and marbles "acting the same" and ice acting strange. You really see the liquids being most stratified, then ice on top of water, and the marbles actually provide the least stratification of the three examples. If your intuition tells you otherwise, that may suggest that your intuition is accounting for some of these random factors for you, and biasing your results.