[Tex/LaTex] Align \sqrt with baseline of other mathematical input

math-modesymbolsvertical alignment

The following mathmatical expression is not being displayed the way I expect it to be.

\documentclass{article}
\usepackage{amsmath,amssymb}
\begin{document}
$3x\sqrt{y}-4-2\sqrt{y}+6x$
\end{document}

enter image description here

Note in the output above, the square root symbol is not "base aligned" (Don't know how to describe it better in LaTex language). I have tried the \smash command but haven't been successful. I know it shouldn't be anything hard to achieve, but seemingly I can't at the moment.

I know that there exists the \smash[b]{$math input$} and \smash[t]{$math input$}.

EDIT:


Is the code below sufficient? (The answer is NO and that is why I seeked clarification to understand the typographical effects explained below.)

$3x\mathord{\raisebox{0.5\depth}{$\sqrt{y}$}}-4-2\mathord{\raisebox{0.5\depth}{$\sqrt{y}$}}+6x$

which yields:

enter image description here

Best Answer

Square roots are often a cause for small, but annoying, problems. Something like

$\sqrt{a}+\sqrt{b}+\sqrt{y}$

will show a variety of ways the surd is typeset

enter image description here

Particularly problematic are the characters with a descender, but also "j":

$\sqrt{d}+\sqrt{j}+\sqrt{y}$

enter image description here

The decision about how to treat such a formula depends on the symbol involved; for example, if there are only characters with descenders, a \smash[b] (requires amsmath) can solve the problem:

$\sqrt{\smash[b]{g}}+\sqrt{\smash[b]{y}}$

enter image description here

One can see that the white space above the letter is not too much (and the lower angle of the surd is slighly below the baseline).

However this can't be the solution for the first formula, where there's a letter with an ascender: we need to pretend that the ascender is in all square roots, but the depth of y should be masked off

$\sqrt{\vphantom{b}a}+\sqrt{b}+\sqrt{\vphantom{b}\smash[b]{y}}$

enter image description here

Alternatively, one can use \mathstrut that inserts a "phantom parenthesis":

$\sqrt{\mathstrut a}+\sqrt{\mathstrut b}+\sqrt{\mathstrut y}$

enter image description here

but this uses a sligthly larger surd.

Beware of a related problem:

$\sqrt{\sin x}+\sqrt{\cos x}$

gives the wrong

enter image description here

If such formulas are possible in our document, I recommend to change the definition of \cos:

\let\cos\relax % to make LaTeX happy with the following line
\DeclareMathOperator{\cos}{cos\vphantom{i}}

so that the formula will by typeset correctly as

enter image description here

As it can be clearly seen, there's little hope to get an automatic solution, as a good treatment depends on what's in the formula, not only on the particular square root.

Related Question