I am using following method to display superscript and subscript at the same time but due to the length of for e.g., superscript, the text and the superscript is being overlapped.
\documentclass[aspectratio=169]{beamer}
\usepackage{fixltx2e}
\def\SPSB#1#2{\rlap{\textsuperscript{\textcolor{red}{\small #1}}}\SB{\small #2}}
\def\SP#1{\textsuperscript{\textcolor{red}{#1}}}
\def\SB#1{\textsubscript{\textcolor{blue}{#1}}}
\begin{document}
\begin{frame}
\frametitle{XYZ}
{\fontsize{18pt}{20}\selectfont
R\SPSB{k}{ij} = R\SPSB{k-1}{ij} + R\SPSB{k-1}{ik}(R\SPSB{k-1}{kk})* R\SPSB{k-1}{kj}.}
\end{frame}
\end{document}
Do I need to space the subexpressions manually or is there any elegant way to do it?