# How to add table and figure label to table number and figure number in list of figures and list of tables?

When I use overleaf by following code:

\usepackage{tocbasic}

\DeclareTOCStyleEntry[
entrynumberformat=\entrynumberwithprefix{\figurename},
dynnumwidth,
numsep=1em
]{tocline}{figure}

\DeclareTOCStyleEntry[
entrynumberformat=\entrynumberwithprefix{\tablename},
dynnumwidth,
numsep=1em
]{tocline}{table}
\newcommand\entrynumberwithprefix[2]{#1\enspace#2\hfill}


It generates :

But when I used same code in TexStudio I got following errors:

How can I solve this problem for TexStudio?

EDIT

After first comment's code also , same error

• Your Error just says, that you are missing \begin{document} and \end{document}, which ist also missing in your Examplecode. DId you just forgot to add them? – DonFangzahn May 25 at 2:22
• I have added them before \begin{document} in Overleaf and Texstudio. Doesnt work in Texstudio – Himal Acharya May 25 at 3:01

\newpage
\renewcommand{\baselinestretch}{1.5}
\newlength\figurelen
\settowidth\figurelen{Figure}
\renewcommand{\cftfigindent}{0em}
\renewcommand\cftfigpresnum{Figure }

\newpage
\newlength\tablelen
\settowidth\tablelen{Table}
\renewcommand{\cfttabindent}{0em}
\renewcommand\cfttabpresnum{Table }
\newpage


Using this, it generates in TexStudio as described in question.

So, this is my MWE:

\documentclass[12pt,a4paper]{article}

\usepackage{tocbasic}

\DeclareTOCStyleEntry[
entrynumberformat=\entrynumberwithprefix{\figurename},
dynnumwidth,
numsep=1em
]{tocline}{figure}

\DeclareTOCStyleEntry[
entrynumberformat=\entrynumberwithprefix{\tablename},
dynnumwidth,
numsep=1em
]{tocline}{table}
\newcommand\entrynumberwithprefix[2]{#1\enspace#2\hfill}

\begin{document}

\begin{figure}
\begin{center}
\begin{tabular}{|c|c|}
\hline
a & b \\
\hline
c & d \\
\hline
\end{tabular}
\end{center}
\caption{Hi}
\end{figure}