梅威瑟:

梅威瑟:

梅威瑟:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{amsfonts,amssymb,amsbsy,amsmath}
\usepackage{tocloft}
\usepackage{times}
\usepackage{titlesec, titleps titletoc}

%%\titleformat{command}[shape]{format}{label}{sep}{before-code}[after-code]
\titleformat{\paragraph}[runin]{\normalsize \rmfamily}{\theparagraph.}{1em}{}[]
\titleformat{\section}{\centering\normalsize}{ARTICLE \thesection}{1em}{\uppercase} %
\titleformat{\subsection}[runin]{\normalsize \rmfamily}{Section \thesubsection.}{1em}{\underline}[. \;]
\titleformat{\subsubsection}[runin]{\normalsize \rmfamily}{\thesubsubsection}{1em}{}[]

\renewcommand\cftsecfont{ARTICLE \uppercase}
\renewcommand\cftsubsecfont{Section }

\begin{document}

\tableofcontents % Breaks at this line

\section{Defined terms; rules of construction}
\section{Organization of partnership}
\subsection{Formation}
\subsection{Name}
\subsection{Certificates and licenses}
\subsubsection{Optional}

\end{document}

MWE 输出(使用 overleaf):

在此处输入图片描述

笔记:

根据编译错误,我认为问题就在这里。与缺少 {} 有关。

\titleformat{\section}{\centering\normalsize}{ARTICLE \thesection}{1em}{\uppercase} %
\titleformat{\subsection}[runin]{\normalsize \rmfamily}{Section \thesubsection.}{1em}{\underline}[. \;]

期望输出(使用 overleaf):

除非我尝试插入目录,否则我无法实现这一点。Overleaf 允许您查看带有编译错误的输出。但尝试通过 LyX 导出为 PDF 时,您会得到:There was an error opening this document. The file is damaged and could not be repaired

在此处输入图片描述

答案1

感谢@flav 和@Bernard,你们两个正确地指出了这个问题。我还发现我搞乱了命令的结构,\titleformat这是我在重新阅读titlesec软件包 PDF 后才弄清楚的:\titleformat{command}[shape]{format}{label}{sep}{before-code}[after-code]

MWE 解决方案应该可以创建第一个图像而没有任何编译错误:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{amsfonts,amssymb,amsbsy,amsmath}
\usepackage{times}
\usepackage{titlesec, titleps, titletoc}

%%\titleformat{command}[shape]{format}{label}{sep}{before-code}[after-code]
\titleformat{\paragraph}[runin]{\normalsize}{\theparagraph}{1em}{}[] %
\titleformat{\section}[display]{\centering\normalsize} 
{ARTICLE\space\thesection}{1em}{\uppercase}[] %
\titleformat{\subsection}[runin]{\normalsize}{Section\space\thesubsection}{1em}{\underline}[.\;] %
\titleformat{\subsubsection}[runin]{\normalsize}{\thesubsubsection}{1em}{\underline}[.\;] %

\usepackage{tocloft}
\renewcommand\cftsecfont{ARTICLE \uppercase}
\renewcommand\cftsubsecfont{Section }

\begin{document}

\tableofcontents

\section{Defined terms; rules of construction}
\section{Organization of partnership}
\subsection{Formation}
\subsection{Name}
\subsection{Certificates and licenses}
\subsubsection{Optional}

\end{document}

相关内容