2

I have a document where I changed the section and subsection format by creating my own environment

\newenvironment{Specification}{
    \renewcommand\thesubsection{SPEC\_\padzeroes[3]{\decimal{subsection}}}
    \renewcommand\thesubsubsection{SPEC\_\padzeroes[3]{\decimal{subsubsection}}}}{}

This works fine but now in the table of contents the section number and the title overlap enter image description here

I am able to change the space between the number and the title by using the tocloft package and

\setlength\cftsubsecnumwidth{70pt}
\setlength\cftsubsubsecnumwidth{70pt}

But the problem is that now also the section without this special format is with that large width and therefore it looks ugly

enter image description here

Is there a way to dynamically changing the numwidth for every entry? Maybe in the environment?

Here a sample code:

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{german,longtable}
\usepackage{multirow}
\usepackage{fmtcount}
\usepackage{tocloft}

\newenvironment{Specification}{% begin
    \renewcommand\thesubsection{SPEC\_\padzeroes[3]{\decimal{subsection}}}
    \renewcommand\thesubsubsection{SPEC\_\padzeroes[3]{\decimal{subsubsection}}}}
{% end
}

%\setlength\cftsubsubsecnumwidth{70pt} 
%\setlength\cftsubsecnumwidth{70pt}

\begin{document}

\tableofcontents

\section{System Requirements}
\subsection{Battery Characteristics}
\begin{Specification}
    \subsubsection{Battery pack configuration} 
    The BMS shall be able to operate on a battery
    \subsubsection{Pack voltage}
    The BMS shall be able to operate up to X V
\end{Specification}

\section{Mechanical Requirements}
\begin{Specification}
    \subsection{Maximum BMS Outline}
    The BMS shall not exceed the outline:\\
    \subsection{Maximum Height above PCB}
    The BMS shall not exceed the height
\end{Specification}

\end{document}

1 Answer 1

1

Thank you for the MWE. Here is a slightly revised version where the Specification environment makes, and reverts, local changes to the layout of the ToC.

% tocspaceprob.tex  SE 638884

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{german,longtable}
\usepackage{multirow}
\usepackage{fmtcount}
\usepackage{tocloft}

%% PW added
\newlength{\shiftit}
\setlength{\shiftit}{50pt}

\newenvironment{Specification}{% begin
    \renewcommand\thesubsection{SPEC\_\padzeroes[3]{\decimal{subsection}}}
    \renewcommand\thesubsubsection{SPEC\_\padzeroes[3]{\decimal{subsubsection}}}
    %% PW added
 \addtocontents{toc}{\addtolength{\cftsubsubsecnumwidth}{\shiftit}}
 \addtocontents{toc}{\addtolength{\cftsubsecnumwidth}{\shiftit}}
}
{% end  %% PW added
 \addtocontents{toc}{\addtolength{\cftsubsubsecnumwidth}{-\shiftit}}
 \addtocontents{toc}{\addtolength{\cftsubsecnumwidth}{-\shiftit}}
}

%\setlength\cftsubsubsecnumwidth{70pt} 
%\setlength\cftsubsecnumwidth{70pt}

\begin{document}

\tableofcontents

\section{System Requirements}
\subsection{Battery Characteristics}
\begin{Specification}
    \subsubsection{Battery pack configuration} 
    The BMS shall be able to operate on a battery
    \subsubsection{Pack voltage}
    The BMS shall be able to operate up to X V
\end{Specification}

\section{Mechanical Requirements}
\begin{Specification}
    \subsection{Maximum BMS Outline}
    The BMS shall not exceed the outline:\\
    \subsection{Maximum Height above PCB}
    The BMS shall not exceed the height
\end{Specification}

\end{document}

enter image description here

1
  • Thank you very much Peter, this helped me!
    – Wuizl
    Commented Mar 30, 2022 at 6:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .