Does magnetic field depend on $z$ inside a toroidal coil? Imagine a circular toroid coiled with a wire through which some current $I$ is flowing. Everywhere it is stated that the magnetic field inside this toroid can be calculated as $$\vec{B} = \mu \frac{NI}{2\pi r} \ \hat{\phi}$$
where $\mu$ is the magnetic permeability of the toroid, $N$ the number of loops the coil presents, $r$ the distance to the center of the toroid and $\hat{\phi}$ the typical versor in cylindrical coordinates.
My cuestion is: why doesn't the magnetic field depend on $z$, the vertical position?
As I see it, there is no symmetry in $z$ that allows us to automatically discard this coordinate. Namely,  as we move radially (varying $r$), the field changes because the situation differs from one radius to another: we get closer to (or further away from) the wires, and that makes the field vary. If we moved along the $z$ direction, the case would be analogous. If we center the coordinate system such that the plane $z=0$ slices the toroid in two halves, we can see that at $z=0$ the current has just a component in the $\hat{z}$ direction, but if we analyze this for any other value of $z$ the current acquires other components as well. So I don't see why the magnetic field would not depend on $z$.
Does it depend on $z$ or not? If yes, how can one then calculate the actual magnetic field (the technique that would be used if the section was squared would no longer apply, I guess)?
 A: Yes, it does depend on $z$.
If you think about it, it must depend on $z$ to satisfy the boundary conditions when you are close to the wires. You expect a constant value with $z$ only in the middle of the torus, where you can ignore the edge effects.
Ampère's law only reduces to that simple formula if the path element $\mathrm{d}\boldsymbol{\ell}$ is parallel to magnetic field $\mathbf{B}$.
But anyway, I did the maths.
I have 20 current loops azimuthally distributed, so that the magnetic field magnitude in the $xy$ plance, at $z=0$, looks like this:

The radius of each loop is $3$, and the torus is "centred" at $10$, so that its inner and outer radii are $7$ and $13$.
Now let's look at the three components of the magnetic field, at $x=10, y=0$:

And then I plotted the only $B_{\phi}$, still at $y=0$ but now varying $x$:

You can see that actually the $B_\phi$ value is quite constant with $x$ provided that you are not too close to the edge (this time in the $x$ direction). This is wrong though, as you’d expect the field to go down $\propto 1/r$ — I suspect this is an artifact of a finite number of current loops.
Conclusion

*

*Away from the edges, the field is essentially independent of $z$.


*The field is always in the azimuthal $\phi$ direction, as suggested by @Christophe in the comment).
