为什么我在格式化标题时会在 \ttlf@chapter/* 的定义中得到非法参数编号?

为什么我在格式化标题时会在 \ttlf@chapter/* 的定义中得到非法参数编号?

我正在尝试使用该包来格式化文档的标题titlesec

总的来说我想要:

  • 罗马书章节编号、内联章节编号和章节名称前面带有“Capítulo”
  • 章节、小节等采用正常字体大小
  • 章节、小节……带有阿拉伯数字的图表和方程式

到目前为止,我有以下代码块

\documentclass{report}
\usepackage{titlesec}
\titleformat*{\section}{\normalsize\bfseries}
\titleformat*{\subsection}{\normalsize\bfseries}
\titleformat*{\subsubsection}{\normalsize\bfseries}
\titleformat*{\paragraph}{\normalsize\bfseries}
\titleformat*{\subparagraph}{\normalsize\bfseries}
\titleformat{name=\chapter,numberless}[hang]{\normalfont \bfseries\centering\scshape\LARGE}{}{1pt}{#1}[] 
\titleformat{\chapter}[hang]{\normalfont \bfseries\centering\scshape\LARGE}{}{1pt}{Capítulo \thechapter. #1}{}
\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}
\renewcommand{\thefigure}{\arabic{chapter}.\arabic{figure}}
\renewcommand{\theequation}{\arabic{chapter}.\arabic{equation}}
\renewcommand{\thetable}{\arabic{chapter}.\arabic{table}}
\begin{document}
\chapter{Test chapter}
\section{Test section}
\subsection{Test section}
\subsubsection{Test section}
\paragraph{Test section}
\subparagraph{Test section}

这会返回一个Illegal parameter number in definition of \ttlf@chapter/*错误,设置 titlesec 包中的选项[explicit]会使章节格式和章节编号起作用,但如果我添加部分,则会返回一堆错误\titleformat*

答案1

除非使用该选项,否则该\titleformat命令不需要任何参数(#1) 。通过从代码中删除两者(并添加一行),我得到了预期的结果,没有任何错误: explicit#1\end{document}

如果您确实想使用该explicit选项,则可以使用以下代码获得相同的输出。

\documentclass{report}
\usepackage[explicit]{titlesec}
\titleformat{\section}{\normalsize\bfseries}{}{0pt}{\thesection\quad#1}[]
\titleformat{\subsection}{\normalsize\bfseries}{}{0pt}{\thesubsection\quad#1}[]
\titleformat{\subsubsection}{\normalsize\bfseries}{}{0pt}{#1}[]
\titleformat{\paragraph}{\normalsize\bfseries}{}{0pt}{#1}[]
\titleformat{\subparagraph}{\normalsize\bfseries}{}{0pt}{#1}[]
\titleformat{name=\chapter,numberless}[hang]{\normalfont \bfseries\centering\scshape\LARGE}{}{1pt}{#1}[] 
\titleformat{\chapter}[hang]{\normalfont \bfseries\centering\scshape\LARGE}{}{1pt}{Capítulo \thechapter. #1}{}
\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}
\renewcommand{\thefigure}{\arabic{chapter}.\arabic{figure}}
\renewcommand{\theequation}{\arabic{chapter}.\arabic{equation}}
\renewcommand{\thetable}{\arabic{chapter}.\arabic{table}}
\begin{document}
\chapter{Test chapter}
\section{Test section}
\subsection{Test section}
\subsubsection{Test section}
\paragraph{Test section}
\subparagraph{Test section}
\end{document}

相关内容