When the section number is at least 10, then the subsection numbers get misaligned with the section titles in the TOC in a beamer presentation in LaTeX. Futhermore, the spacing between the (sub)subsection numbers and the (sub)subsection titles gets smaller. I am looking for a generic way to fix this regardless of whether the section number is at least 10, at least 100, or less than 10. In this case I would not have to tweak these things manually. Is there a way to do this?
\documentclass[9pt,trans,xcolor={table},envcountsect]{beamer} % Plain
\usefonttheme[onlymath]{serif}
\usetheme[shownavsym,right]{Aalborg}
\setbeamertemplate{navigation symbols}{\insertframenavigationsymbol \insertsectionnavigationsymbol \insertbackfindforwardnavigationsymbol} % Nav symbols
\setbeamertemplate{section in toc}[sections numbered] % Automatic enumeration of sections
%
\makeatletter
\newcommand{\ShiftSectionNumber}[1]{%
\beamer@tocsectionnumber=\numexpr#1+\beamer@tocsectionnumber}
\makeatother
%
\setbeamertemplate{subsection in toc}{\leavevmode\leftskip=3.14em\rlap{\hskip-2em\inserttocsectionnumber.\inserttocsubsectionnumber}\inserttocsubsection\par} % Automatic enumeration of subsections. WITH indentation of subsection numbers (\leftskip changed from 3.2em to 3.14em)
%
\setbeamertemplate{subsubsection in toc}{\leavevmode\leftskip=6.9em\rlap{\hskip-3em\inserttocsectionnumber.\inserttocsubsectionnumber.\inserttocsubsubsectionnumber}\inserttocsubsubsection\par} % Automatic enumeration of subsubsections. WITH indentation of subsubsection numbers (\leftskip changed from 3.14em to 6.9em, \hskip changed from -2em to -3em)
%
\begin{document}
%
\begin{frame}%[allowframebreaks]
\frametitle{Overview}
\tableofcontents
\end{frame}
%
\def \numbershift {0} % Increasing of enumeration of section numbers and theorems
\ShiftSectionNumber{\numbershift} % Increasing the enumeration of section numbers
\addtocounter{section}{\numbershift} % Theorem numbers follow section numbers
%
%
\section{First Section (1-digit section number)} %What happens if a very long section title is used?} % https://tex.stackexchange.com/questions/89708/indent-subsections-in-beamers-toc
\subsection{First Subsection}
\subsubsection{First Subsubsection}
\ShiftSectionNumber{8}
\section{Second Section (2-digit section number)} % https://imathworks.com/tex/tex-latex-beamer-how-to-get-subsection-indent-with-a-numbered-toc/
\subsection{Second Subsection}
\subsubsection{Second Subsubsection}
\ShiftSectionNumber{89}
\section{Third Section (3-digit section number)}
\subsection{Third Subsection}
\subsubsection{Third Subsubsection}
%
\begin{frame}[<+->]{Misaligned identation in TOC}
Hello.
\end{frame}
\end{document}
You could measure the width of the last section and align the numbers according to this width: