I've noticed before that when I ask InDesign to vertically center text in a box, it's never quite perfect, usually a bit too low. On what measure is this vertical justification based? Here is an example of what I mean:
The short answer is: InDesign centers the text in a way that the top of the text is equally far apart from the center as the text's baseline.
The long answer and how this leads to the text not looking centered in many cases:
What is the top of the text?
As Janus Bahs Jacquet pointed out in his comment, the placement depends on the baseline options settings for your text frame. Basically those determine how far the top of your text is from the baseline. There are 6 different options:
The top of the text is determined by the ascender height, which is in turn defined by the type designer. The ascender is usually a bit above the cap height even, see this screenshot of a Minion Pro
T which I opened in a type design tool.
The top of the text is determined by the height of the font's capital letters. Note that this does not refer to the highest point of any capital letter, but to the height of the vertical stem, so you can usually use a
H to visually check the cap height. In InDesign this looks like this. Notice that this is slightly shifted up compared to Ascent Offset, because the top of the font is a bit lower.
This considers the top of the font whatever value you have set for the text's leading currently. That means if your text size is
12pt and therefor has a leading value of
14.4pt, the top of the text will be 14.4pt above the baseline and the text as a whole will look like it's shifted down (the green box visualizes the leading).
Em Box Height
Fun fact: this one is only usable via InDesign scripting, it is not exposed to you in the UI.
The top of the text has the distance of an Em space from the baseline. I have no idea why you would ever need this. Actually, I just measured it, that's not what it does, I have no idea what it does. We can see the text is shifted down a bit, but the top is still closer to the baseline as an em space, I still don't know what this could be used for.
This one considers the x height as the top of the font. In most fonts this would be, surprise, surprise, the height of the letter
x. This one is quite useful for centering text, see below for the explanation.
With this one you can set the value that is considered the text top for yourself via the
Min setting right next to it. With the default of
0 that would mean that the text has no height and therefor the baseline is right at the top of the text frame.
What does this mean for vertical text centering?
Your observation that text is not visually centered very well is true for most of the baseline settings, but most likely it refers to the
Ascent setting, as this is the default one. The reason why it is not looking centered is that text is not measured from the top to the very bottom of the text (the descenders) but to the baseline. That means the baseline is just as far apart from the text frame's center as is the text's top. Here's an image visualizing this. The baseline and the text top are red the actual center of the text frame is marked green and you can see it is exactly in the center of the two red lines.
But since we have the descenders even going below the lower red line the whole text looks like it is set too low to be in the center. Also you can see the visual center of text is always between the baseline and the x height as pretty much every character fills this space, but only much fewer fill the ascender space and the descender space. From this we can also figure out a way to center the text much better: If we choose
x Height as our baseline setting then the text frame's center is in the center of our x height and the centering is much more visually pleasing.