使用包 tcolorbox 和 titleformat 发生冲突

使用包 tcolorbox 和 titleformat 发生冲突

我正在尝试使用 tcolorbox 突出显示论文中的某些单词,因此我使用这个:

\usepackage{tikz,lipsum,lmodern}
\usepackage[most]{tcolorbox}
\tcbuselibrary{listings,breakable}
\newtcbox{\mybox}[2][]{nobeforeafter,tcbox raise base,colframe=#2,colback=#2!10!white,top=0.8pt,bottom=0.8pt, left=0.8pt, right=0.8pt,before upper=\strut}
% part of speech tagging
\newtcbox{\pstag}[2][]{nobeforeafter,tcbox raise base,colframe=#2,colback=#2,top=0.8pt,bottom=0.8pt, left=0.8pt, right=0.8pt,before upper=\strut}

这在另一个文档中运行良好\mybox{WildStrawberry}{her \pstag{WildStrawberry}{\scriptsize PRONOMINAL}}

在此处输入图片描述

当我尝试将其集成到另一个文档中时,由于 titleformat 命令,我收到一些错误。!缺失数字,视为零。} \chapter{简介}

\usepackage{textcase}
\usepackage[titletoc, title]{appendix}
\usepackage{titlesec}
\titleformat{\chapter}{\large\bfseries\MakeUppercase}{\thechapter}{2ex}{}[\vspace*{-1.5cm}]
\titleformat*{\section}{\large\bfseries}
\titleformat*{\subsection}{\large\bfseries}
\titleformat*{\subsubsection}{\large\bfseries}

因此,如果我评论说“\titleformat我没有错误”,我可以使用彩色框。但我需要这些标题格式。有人可以提供不同的解决方案吗?

编辑 - 为导致错误的文档添加了代码。有些部分缺失,因为这是我的学士论文(但模板定义是完整的)

\documentclass[12pt,a4paper,dvipsnames]{report}

\usepackage[utf8]{inputenc} 
\usepackage[romanian]{babel} 
\renewcommand\familydefault{\sfdefault} % sans serif

\usepackage[margin=2.54cm]{geometry}    
\usepackage{graphicx} % support the \includegraphics command and options


\usepackage{tikz,lipsum,lmodern}
\usepackage[most]{tcolorbox}
\tcbuselibrary{listings,breakable}
\newtcbox{\mybox}[2][]{nobeforeafter,tcbox raise base,colframe=#2,colback=#2!10!white,top=0.8pt,bottom=0.8pt, left=0.8pt, right=0.8pt,before upper=\strut}
% part of speech tagging
\newtcbox{\pstag}[2][]{nobeforeafter,tcbox raise base,colframe=#2,colback=#2,top=0.8pt,bottom=0.8pt, left=0.8pt, right=0.8pt,before upper=\strut}


% formatting sections and subsections
\usepackage{textcase}
\usepackage[titletoc, title]{appendix}
\usepackage{titlesec}
%\titleformat{\chapter}{\large\bfseries\MakeUppercase}{\thechapter}{2ex}{}[\vspace*{-1.5cm}]
%\titleformat*{\section}{\large\bfseries}
%\titleformat*{\subsection}{\large\bfseries}
%\titleformat*{\subsubsection}{\large\bfseries}

\usepackage{chngcntr}
\counterwithout{figure}{chapter} % no chapter number in figure labels
\counterwithout{table}{chapter} % no chapter number in table labels
\counterwithout{equation}{chapter} % no chapter number in equation labels

\usepackage{booktabs} % for much better looking tables
\usepackage{url} % Useful for inserting web links nicely
\usepackage[bookmarks,unicode,hidelinks]{hyperref}

\usepackage{array} % for better arrays (eg matrices) in maths
\usepackage{paralist} % very flexible & customisable lists (eg. enumerate/itemize, etc.)
\usepackage{verbatim} % adds environment for commenting out blocks of text & for better verbatim
\usepackage{subfig} % make it possible to include more than one captioned figure/table in a single float
\usepackage{enumitem}
\setlist{noitemsep}

%%%%%%%%%%%%%%

%%% HEADERS & FOOTERS
\usepackage{fancyhdr}
\pagestyle{empty}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\lhead{}\chead{}\rhead{}
\lfoot{}\cfoot{\thepage}\rfoot{}



\newcommand{\HeaderLineSpace}{-0.5cm}
\newcommand{\UniTextRO}{UNIVERSITATEA POLITEHNICA DIN BUCUREȘTI \\[\HeaderLineSpace] 
FACULTATEA DE AUTOMATICĂ ȘI CALCULATOARE \\[\HeaderLineSpace]
DEPARTAMENTUL CALCULATOARE\\}
\newcommand{\DiplomaRO}{PROIECT DE DIPLOMĂ}
\newcommand{\AdvisorRO}{Coordonator științific:}
\newcommand{\BucRO}{BUCUREȘTI}

\newcommand{\UniTextEN}{UNIVERSITY POLITEHNICA OF BUCHAREST \\[\HeaderLineSpace]
FACULTY OF AUTOMATIC CONTROL AND COMPUTERS \\[\HeaderLineSpace]
COMPUTER SCIENCE DEPARTMENT\\}
\newcommand{\DiplomaEN}{DIPLOMA PROJECT}
\newcommand{\AdvisorEN}{Thesis advisor:}
\newcommand{\BucEN}{BUCHAREST}

\newcommand{\frontPage}[6]{
\begin{titlepage}
\begin{center}
{\Large #1}  % header (university, faculty, department)
\vspace{50pt}
\begin{tabular}{p{6cm}p{4cm}}
\includegraphics[scale=0.8]{pics/upb-logo.jpg} &
    \includegraphics[scale=0.5,trim={14cm 11cm 2cm 5cm},clip=true]{pics/cs-logo.pdf}
\end{tabular}

\vspace{105pt}
{\Huge #2}\\                           % diploma project text
\vspace{40pt}
{\Large #3}\\ \vspace{0pt}  % project title
{\Large #4}\\                          % project subtitle
\vspace{40pt}
{\LARGE \Name}\\                   % student name
\end{center}
\vspace{60pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}p{6cm}r}
&{\large\textbf{#5}}\vspace{10pt}\\      % scientific advisor
&{\large \Advisor}                                    % advisor name
\end{tabular*}
\vspace{20pt}
\begin{center}
{\large\textbf{#6}}\\                                % bucharest
\vspace{0pt}
{\normalsize \Year}
\end{center}
\end{titlepage}
}

\newcommand{\frontPageRO}{\frontPage{\UniTextRO}{\DiplomaRO}{\ProjectTitleRO}{\ProjectSubtitleRO}{\AdvisorRO}{\BucRO}}
\newcommand{\frontPageEN}{\frontPage{\UniTextEN}{\DiplomaEN}{\ProjectTitleEN}{\ProjectSubtitleEN}{\AdvisorEN}{\BucEN}}

\linespread{1.5}
\setlength\parindent{0pt}
\setlength\parskip{.28cm}

%% Abstract macro
\newcommand{\AbstractPage}{
\begin{titlepage}
\textbf{\large SINOPSIS}\par
\AbstractRO\par\vfill
\textbf{\large ABSTRACT}\par
\AbstractEN \vfill
\end{titlepage}
}

%% Thank you macro
\newcommand{\ThanksPage}{
\begin{titlepage}
{\noindent \large\textbf{MULȚUMIRI}}\\
\Thanks
\end{titlepage}
}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%%
%%          End of template definitions
%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\frontPageRO
\frontPageEN

\begingroup
\linespread{1}
\tableofcontents
\endgroup

\AbstractPage

\chapter{Introducere}\pagestyle{fancy}


 I: Mrs. \mybox{WildStrawberry}{\mybox{YellowGreen}{Robinson \pstag{YellowGreen}{\scriptsize PROPER}}'s phone
 \end{document}

答案1

您放置的\MakeUppercase位置错误:

\titleformat{\chapter}{\large\bfseries}{\thechapter}{2ex}{\MakeUppercase}[\vspace*{-1.5cm}]

相关内容