我有一个文档,我通过创建自己的环境更改了章节和小节的格式
\newenvironment{Specification}{
\renewcommand\thesubsection{SPEC\_\padzeroes[3]{\decimal{subsection}}}
\renewcommand\thesubsubsection{SPEC\_\padzeroes[3]{\decimal{subsubsection}}}}{}
我可以通过使用包来更改数字和标题之间的空格tocloft
,
\setlength\cftsubsecnumwidth{70pt}
\setlength\cftsubsubsecnumwidth{70pt}
但问题是,现在没有这种特殊格式的部分也有那么大的宽度,因此看起来很丑
有没有办法动态更改每个条目的数字宽度?也许在环境中?
下面是一个示例代码:
\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
感谢 MWE。这是一个略微修改的版本,其中Specification
环境对 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}