[Tex/LaTex] How to highlight a specific section in beamer ToC

beamertable of contents

I have a ToC with 5 sections, and I want 5 frames where there is on each one a table of contents with the ith section highlighted, and the other are shaded.

What I have so far is the following :

\documentclass{beamer}
\usetheme{Madrid}

\begin{document}
\begin{frame}{Overview} 
  \only<1>{
    \tableofcontents[sections={1}]
    \tableofcontents[sections={2-5},sectionstyle=shaded,subsectionstyle=shaded]
  }
  \only<2>{
    \tableofcontents[sections={1},sectionstyle=shaded,subsectionstyle=shaded]
    \tableofcontents[sections={2}]
    \tableofcontents[sections={3-5},sectionstyle=shaded,subsectionstyle=shaded]
  }
  \only<3>{
    \tableofcontents[sections={1,2},sectionstyle=shaded,subsectionstyle=shaded]
    \tableofcontents[sections={3}]
    \tableofcontents[sections={4-5},sectionstyle=shaded,subsectionstyle=shaded]
  }
  \only<4>{
    \tableofcontents[sections={1-3},sectionstyle=shaded,subsectionstyle=shaded]
    \tableofcontents[sections={4}]
    \tableofcontents[sections={5},sectionstyle=shaded,subsectionstyle=shaded]
  }
  \only<5>{
    \tableofcontents[sections={1-4},sectionstyle=shaded,subsectionstyle=shaded]
    \tableofcontents[sections={5}]
  }
\end{frame}

\section{Section 1}
\begin{frame}{Frame 1}
\end{frame}

\section{Section 2}
\begin{frame}{Frame 2}
\end{frame}

\section{Section 3}
\begin{frame}{Frame 3}
\end{frame}

\section{Section 4}
\begin{frame}{Frame 4}
\end{frame}

\section{Section 5}
\begin{frame}{Frame 5}
\end{frame}

\end{document}

I wonder whether there is a better way to do that ?

Thanks

Best Answer

After your \begin{document} put this code. It shall do it:

\begin{frame}
\titlepage
\end{frame}

\begin{frame}
\frametitle{Plan}
\tableofcontents[pausesections]
\end{frame}

\AtBeginSection[]{

\begin{frame}
\frametitle{Plan}
\tableofcontents[currentsection]
\end{frame}}