For a while, I haven't been able to set up my TOC well. I have shown it here in 3 images and it doesn't look good because the chapters vary in the number of subheadings.
Is there some way to set this up well in Indesign?
Are you saying that you don't like that the chapter listings are breaking across a page? You're aligning every item to a baseline grid and you're really dealing with a simple math problem. InDesign can't fix this for you. Honestly the only way I can see to fix this is to have a separate chapter on each page which is going to take up a lot more pages.
It looks a bit messy to me, yes.
I agree that one chapter per page will be a bad solution.
I didn't expect Indesign to have a magic solution, but there could possibly be some tool that would make it easier.
Again, you're dealing with a basic math problem. The content either fits in the area or it doesn't. No tool is going to be able to change that for you unfortunately.
Well, any inputs welcome if someone has been in the same situation.
I don't think I can make it smaller in the font size.
The inconsistent subheadings in the chapters means it's not going to look balanced, whatever you do. You mention not being able to reduce font size, but even a small amount might help to approach this with 2 columns. You could span the main heading and the chapter names, and have two chapters per page, with the final chapter and appendix on the final page. You'd use 5 pages using this approach as opposed to 6. But as I say, it's still going to look a little unbalanced other than the fact that there will be two chapters per page. Personally I don't mind what you have, so long as there are no single lines anywhere which is never desirable.