Thanks for this Steven, it works.
But when inserting the tables using the [toc] code some of the internal links do not work. What I mean by that is that you click the internal link in the table, but it doesn’t scroll down to that part.
This problem doesn’t happen when the table is automatically inserted, just when inserted via the shortcode.
What may be the reason?