8

I need to enumerate \sqrt signs as shown in the picture below but have no idea how to do it. I wonder if anyone could help. Thanks

enter image description here

1 Answer 1

12
\documentclass{article}
\usepackage{stackengine,mathtools}
\stackMath
\renewcommand\stackalignment{l}
\setstackgap{S}{0pt}
\newcounter{sqrti}
\newcommand\esqrt[2][\litsqrti]{%
  \ifx\litsqrti#1%
    \stepcounter{sqrti}%
    \edef\litsqrti{\thesqrti}%
  \fi
  \stackunder{\displaystyle\sqrt{#2}}{\smash{%
  \belowbaseline[3pt]{\scriptscriptstyle~\mathclap{#1}}}}
}
\newcommand\resetesqrt{\setcounter{sqrti}{-1}}
\begin{document}
\[
\resetesqrt
\esqrt{p\pm\esqrt{p\pm\dots\pm\esqrt[n-2]{p}}}
\]

\end{document}

enter image description here

SUPPLEMENT

In the prior code, there is a 3pt gap set between the bottom of the surd and the index. As the surd depth changes, so will the depth of the index.

The OP asks if the indices can be aligned vertically. The answer is yes; however, here, the depth must be defined relative to the baseline. Choosing the proper depth could vary with each use case, depending on the depth of the associated square-root surds.

Thus, I provide \esqrtdp to define that depth, set here to 13pt.

\documentclass{article}
\usepackage{stackengine,mathtools}
\stackMath
\renewcommand\stackalignment{l}
\setstackgap{L}{0pt}
\renewcommand\stacktype{L}
\newcounter{sqrti}
\newcommand\esqrt[2][\litsqrti]{%
  \ifx\litsqrti#1%
    \stepcounter{sqrti}%
    \edef\litsqrti{\thesqrti}%
  \fi
  \stackunder{\displaystyle\sqrt{#2}}{\smash{%
  \belowbaseline[\esqrtdp]{\scriptscriptstyle~\mathclap{#1}}}}%
}
\newcommand\resetesqrt{\setcounter{sqrti}{-1}}
\newcommand\esqrtdp{13pt}
\begin{document}
\[
\resetesqrt
\esqrt{p\pm\esqrt{p\pm\dots\pm\esqrt[n-2]{p}}}
\]

\end{document}

enter image description here

2
  • Could it be possible to align vertically the enumerating numbers 0, 1, ... ?
    – projetmbc
    Commented Jul 1, 2022 at 15:33
  • 2
    @projetmbc Please see my SUPPLEMENT Commented Jul 1, 2022 at 15:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .