Square root and nth root in LaTeX (sqrt)
\sqrt{x} draws a square root over its argument. The optional argument in square brackets sets the index: \sqrt[3]{x} is a cube root. Both need math mode.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{amsmath}Square root
The root sign grows in width and height with its content, so fractions and further roots fit inside. The braces are needed as soon as the content is longer than one character: \sqrt 2x puts only the 2 under the root.
The diagonal has length $\sqrt{2}$.
\[
c = \sqrt{a^2 + b^2}
\qquad
\sqrt{\frac{a}{b}}
\qquad
\sqrt{1 + \sqrt{x}}
\]Cube root and nth root
Write the index in square brackets before the braces: \sqrt[n]{x}. The index can be a number, a letter or a short expression.
\[
\sqrt[3]{27} = 3
\qquad
\sqrt[n]{x^m} = x^{m/n}
\]Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Move the index
A tall index such as a Greek beta can touch the root sign. With amsmath, \leftroot{2} moves the index two small steps to the left and \uproot{2} two steps up; negative numbers move it right or down.
\[
\sqrt[\beta]{k}
\qquad
\sqrt[\leftroot{-2}\uproot{2}\beta]{k}
\]Roots of equal height
The root signs over a and b end at different heights because b is the taller letter. \mathstrut is an invisible character with the height and depth of a parenthesis; placed in each root, it makes the signs equal.
\[
\sqrt{a} + \sqrt{b}
\qquad
\sqrt{\mathstrut a} + \sqrt{\mathstrut b}
\]Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Pitfalls
\sqrtin normal text stops with Missing $ inserted. Wrap it in$...$.\surdprints the root sign alone, without the bar over the content.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
amsmath - How-to Exponents and subscripts in LaTeX
- How-to Fractions in LaTeX
- Error Missing $ inserted