So the gravitational force is, in the proper coordinates, $-mg~\hat y$ where $\hat y$ is a unit vector in the upward direction. Let us also say that $\hat x$ is a unit vector pointing right.
Now with constrained motions you might not want to use $\hat y$ as it neither clearly obeys the constraints (in-line with the surface) nor clearly violates them (by being perpendicular to the surface). Instead you might want to use coordinates which either point up along the ramp in the direction that motion can occur, let's call that $\hat m$, or normal to the surface, let's call that $\hat n.$ Then it does not take too much effort to see that if $\alpha$ is measured in radians that,$$\hat m = \cos\alpha~\hat x + \sin\alpha~\hat y\\\hat n = -\sin\alpha~\hat x + \cos\alpha~\hat y.$$We can also solve these for $\hat y$ remembering that the Pythagorean theorem for trigonometry says that $\sin^2\alpha + \cos^2\alpha = 1.$ So then we find that $$\hat y = \sin\alpha~\hat m + \cos\alpha~\hat n.$$Then when we want $-mg~\hat y$ in these coordinates we can simply substitute to find that its component in the normal direction is, in fact, $-mg\cos\alpha,$ just as your textbook says it is.
By the way, there is a trick that seasoned physicists use to solve these sorts of problems. Sometimes, like now, you know the magnitude of a force ($mg$) but do not know how it varies with some angle. Well, since that usually comes down to a rotation, it's generally a sine or cosine. The trick that we physicists use is that we think first about what happens when $\alpha = 0$ and then we think about increasing $\alpha$ a tiny bit.
Here you can see clearly that when $\alpha = 0$ then the whole force must be normal, and so the normal component must go like $\cos \alpha$ because $\sin \alpha = 0$ when $\alpha = 0.$ And that's also an easy way to see why $1/\cos\alpha$ must be excluded immediately: then you are saying that the normal component of any gravitational force becomes infinite as the surface gets less and less tilted, which is obviously not how gravity works (it would make your trip to the bathroom scale interesting though!).
The little change in $\alpha$ allows us to figure out whether it's $+\sin$ or $-\sin$, by saying "and when $\alpha$ starts to increase this thing starts to point in the negative direction so it must be $-\sin\alpha.$" So take a second maybe and look back at the equation above and think why the $\hat x$ component of $\hat n$ must go like $-\sin\alpha$, it is because as you increment the angle it has to start pointing to the left.