Search code examples
latexoverleaf

How to decrease header level in Overleaf for table of figures + tables?


I'm trying to figure out how to change my list of figures and tables so it refers to figures and tables on a section level. My document type is article in overleaf. My current code looks as follows:

\documentclass{article}
\begin{document}

\maketitle
\section{Abstract}
\newpage
\tableofcontents
\newpage
\addcontentsline{toc}{section}{\listfigurename}
\listoffigures
\newpage
\addcontentsline{toc}{section}{\listtablename}
\listoftables
\newpage
\section{Introduction}
\section{3}
\section{4}

\begin{table}[H]
\renewcommand{\arraystretch}{2}
\centering
\begin{tabular}{ p{6cm}p{6cm}}
\toprule
\textbf{Variables}                              & \textbf{Description}                                      \\ \midrule
\textit{F\_27608, R\_27730}                     & The amount of cheese and yogurt ordered weekly.           \\
\textit{Year}                                   & Year of the observation.                                  \\
\textit{Winter, Spring, Summer, Autumn} & Season of the observation.                                \\
\textit{Week}                                   & Week of the observation.                                  \\
 \textit{Lag1, Lag2, Lag3, Lag4, Lag5}           &  Lagged order amounts for prior periods.                   \\
\textit{Price}                                  & Mean price of the product for the specific observation.   \\
\textit{Fut1, Fut2, Fut3, Fut4, Fut5}           & Future price of the product.                              \\
\textit{PromoScale}                             & Level of expected increase in orders caused by promotion. \\
\textit{PromoScale(L1, L2, L3)}                 & Lagged PromoScale values for prior periods                \\
\textit{PromoScale(F1, F2, F3)}                 & Future PromosSale values.                                 \\ \bottomrule
\end{tabular}
\caption{Feature space cheese and yogurt}
\end{table}

See picture: List of tables

How do i make it so that these tables say 4.1 and 4.2 in the list of tables? (the code only shows one table for reference)


Solution

  • You can use \counterwithin{figure}{section} to number a counter within a section:

    \documentclass{article}
    
    \counterwithin{figure}{section}
    \counterwithin{table}{section}
    
    \begin{document}
    
    \section{Abstract}
    \newpage
    \tableofcontents
    \newpage
    \addcontentsline{toc}{section}{\listfigurename}
    \listoffigures
    \newpage
    \addcontentsline{toc}{section}{\listtablename}
    \listoftables
    \newpage
    
    \section{Introduction}
    \section{3}
    \section{4}
    
    \begin{table}[htbp]
    \caption{Feature space cheese and yogurt}
    \end{table}
    
    \end{document}
    

    enter image description here