![章节样式修改错误](https://linux22.com/image/471840/%E7%AB%A0%E8%8A%82%E6%A0%B7%E5%BC%8F%E4%BF%AE%E6%94%B9%E9%94%99%E8%AF%AF.png)
在过去的几天里,我一直在尝试更改章节样式,但我使用的类出现了错误。这是我的代码:
\documentclass[a4paper,12pt]{extra/MyThesis}
\usepackage[margin=2.5cm,a4paper]{geometry}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tikz}
\usetikzlibrary{shadows.blur}
\usepackage{titletoc}
\usepackage{lipsum}
\usepackage{calc}
\definecolor{yourcolor}{HTML}{008bb2}
%define new chapter style (just for a nicer look)
\makechapterstyle{mystyle}{%
\chapterstyle{default}
\renewcommand*{\chapnumfont}{\normalfont\Huge\sffamily\bfseries}
\renewcommand*{\chaptitlefont}{\normalfont\huge\sffamily\itshape\color{yourcolor}}
\settowidth{\chapindent}{\chapnumfont 111}
\renewcommand*{\chapterheadstart}{}
\renewcommand*{\chapnamefont}{\hfill\color{yourcolor}\normalfont\Huge\sffamily\bfseries}
\renewcommand*{\printchapternum}{%
\begin{tikzpicture}[baseline={([yshift=-.6ex]current bounding box.center)}]
\node[fill=yourcolor,circle,text=white] {\thechapter};
\end{tikzpicture}\\[1ex]
\hrule height 1.5pt}
\renewcommand*{\printchaptertitle}[1]{%
{\chaptitlefont ##1}}
}
%use new chapter style
\chapterstyle{mystyle}
%\linespread{1.25}
%\setlength{\parskip}{16pt}
\begin{document}
\tableofcontents
\newpage
\listoffigures
\chapter{A chapter}
\startcontents[chapters]
%print minitoc
%\printmyminitoc
\section{Section}
\lipsum[1]
\section{Section 2}
\section{test}
\section{abc}
\lipsum
\chapter{Second chapter}
\startcontents[chapters]
%print minitoc
%\printmyminitoc
\section{Section 2}
\lipsum[1]
\section{test}
\lipsum[1]
\end{document}
.clc 类的代码:
\ProvidesClass{latex/MyThesis_}[2021/02/03 v1.0 MyThesis_ class]
\newif\ifCU@bookmode
\CU@bookmodetrue
\DeclareOption{report}{\CU@bookmodefalse}
\DeclareOption{book}{\CU@bookmodetrue}
\ProcessOptions\relax
\ifCU@bookmode
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}%
\ProcessOptions\relax%
\ifx\pdfoutput\undefined%
\LoadClass[dvips, a4paper]{book}%
\else%
\LoadClass[pdftex, a4paper]{book}%
\fi%
\else
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}%
\ProcessOptions\relax%
\ifx\pdfoutput\undefined%
\LoadClass[dvips, a4paper]{report}%
\else%
\LoadClass[pdftex, a4paper]{report}%
\fi%
\fi
\usepackage[english]{babel}
\usepackage{tocbibind}
\usepackage{setspace}
\usepackage{amssymb}
\usepackage{fancyhdr}
\usepackage{eucal}
\usepackage{ifthen}
\usepackage{ifpdf}
\usepackage{parskip}
\usepackage[perpage]{footmisc}
\usepackage[usenames, dvipsnames]{color}
\usepackage[square, sort, numbers]{natbib}
\setlength{\parindent}{15pt}
\usepackage[none]{hyphenat}
%\usepackage[left=1.5in, right=1in, top=1in, bottom=1in, includefoot, headheight=13.6pt]{geometry}%Added
\usepackage{blindtext}%Added
\sloppy
\renewcommand{\bibname}{References}
\usepackage{nomencl}
\makenomenclature
\renewcommand\nomgroup[1]{%
\ifthenelse{\equal{#1}{A}}{%
\item[\textbf{Roman Symbols}] }{% A - Roman
\ifthenelse{\equal{#1}{G}}{%
\item[\textbf{Greek Symbols}]}{% G - Greek
\ifthenelse{\equal{#1}{R}}{%
\item[\textbf{Superscripts}]}{% R - Superscripts
\ifthenelse{\equal{#1}{S}}{%
\item[\textbf{Subscripts}]}{{% S - Subscripts
\ifthenelse{\equal{#1}{X}}{%
\item[\textbf{Other Symbols}]}{{% X - Other Symbols
\ifthenelse{\equal{#1}{Z}}{%
\item[\textbf{Acronyms}]}% Z - Acronyms
{{}}}}}}}}}}
\usepackage[ pdftex, plainpages = false, pdfpagelabels,
pdfpagelayout = useoutlines,
bookmarks,
bookmarksopen = true,
bookmarksnumbered = true,
breaklinks = true,
linktocpage,
%% pagebackref,
colorlinks = true,
linkcolor = blue,
urlcolor = blue,
citecolor = red,
anchorcolor = green,
hyperindex = true,
hyperfigures
]{hyperref}
\usepackage[pdftex]{graphicx}
%%%%%%%%%%%%%
%%%%%%%
\DeclareGraphicsExtensions{.png, .jpg, .pdf}
\pdfcompresslevel=9
\graphicspath{{figures/}}
\ifpdf
\pdfpageheight=297mm
\pdfpagewidth=210mm
\else
\setlength{\paperheight}{297mm}
\setlength{\paperwidth}{210mm}
\fi
%\setlength{\hoffset}{0.00cm}
\setlength{\hoffset}{-1.00cm}
\setlength{\voffset}{-1.00cm}
\setlength{\topmargin}{1mm}
\setlength{\headheight}{1cm}
\setlength{\headsep}{1cm}
%\setlength{\textheight}{22cm}
\setlength{\textheight}{24cm}
%\setlength{\textwidth}{14cm}
\setlength{\textwidth}{15.5cm}
\setlength{\marginparsep}{1mm}
\setlength{\marginparwidth}{3cm}
%\setlength{\footskip}{1.36cm}
\setlength{\footskip}{0.86cm}
\newsavebox{\@linebox}
\savebox{\@linebox}[3em][t]{\parbox[t]{3em}{%
\@tempcnta\@ne\relax
\fontsize{12pt}{7mm}\selectfont
\loop{\scriptsize\the\@tempcnta}\\
\advance\@tempcnta by \@ne\ifnum\@tempcnta<25\repeat}}
\newif\ifdraft
\draftfalse
\pagestyle{fancy}
\fancyhf{}
\rhead{\small \leftmark}
\cfoot{\thepage}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\ifdraft
\fancyhead[L,L]{
\begin{picture}(0,0)
\put(-18,-25){\usebox{\@linebox}}
\end{picture}}
\fi
\fancypagestyle{plain}{
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
\ifdraft
\fancyhead[L]{%
\begin{picture}(0,0)%
\put(-18,-25){\usebox{\@linebox}}%
\end{picture}}
\fi}
\newcommand{\submittedtext}{{A thesis submitted for the degree of}}
\newcommand{\nth}{\textsuperscript{th}}
\def\degreedate#1{\gdef\@degreedate{#1}}
\def\degree#1{\gdef\@degree{#1}}
\def\collegeordept#1{\gdef\@collegeordept{#1}}
\def\university#1{\gdef\@university{#1}}
\def\crest#1{\gdef\@crest{#1}}
\newenvironment{alwayssingle}{%
\@restonecolfalse\if@twocolumn\@restonecoltrue\onecolumn
\else\newpage\fi}
{\if@restonecol\twocolumn\else\newpage\fi}
\renewcommand{\maketitle}{%
\begin{alwayssingle}
\renewcommand{\footnotesize}{\small}
\renewcommand{\footnoterule}{\relax}
\thispagestyle{empty}
\begin{center}
{ \Huge {\bfseries {\@title}} \par}
{\large \vspace*{18mm} {{\@crest} \par} \vspace*{18mm}}
{{\Large \@author} \par} \vspace*{8mm} {\large \vspace*{1ex}
{{\@collegeordept} \par} \vspace*{1ex}
{{\@university} \par} \vspace*{20mm}
{{\submittedtext} \par} \vspace*{1ex}
{\it {\@degree} \par} \vspace*{2ex}
{\@degreedate}}
\end{center}
\end{alwayssingle}}
\newenvironment{dedication}
{\begin{alwayssingle}
\pagestyle{empty}
\begin{center}
\vspace*{1.5cm}
{\LARGE }
\end{center}
\vspace{0.5cm}
\begin{quote} \begin{center}}
{\end{center} \end{quote} \end{alwayssingle}}
\newenvironment{acknowledgements}
{\pagestyle{empty}
\begin{alwayssingle}
\begin{center}
\vspace*{1.5cm}
{\Large \bfseries Acknowledgements}
\end{center}
\vspace{0.5cm}
\begin{quote}}
{\end{quote}\end{alwayssingle}}
\newenvironment{acknowledgementslong}
{\pagestyle{empty}
\begin{alwayssingle}
\begin{center}
\vspace*{1.5cm}
{\Large \bfseries Acknowledgements}
\end{center}
\vspace{0.5cm}\begin{quote}}
{\end{quote}\end{alwayssingle}}
\newenvironment{abstracts} {\begin{alwayssingle} \pagestyle{empty}
\begin{center}
\vspace*{1.5cm}
{\Large \bfseries Abstract}
\end{center}
\vspace{0.5cm}
\begin{quote}}
{\end{quote}\end{alwayssingle}}
\newenvironment{abstractslong} {\begin{alwayssingle} \pagestyle{empty}
\begin{center}
\vspace*{1.5cm}
{\Large \bfseries Abstract}
\end{center}
\vspace{0.5cm} \begin{quote}}
{\end{quote}\end{alwayssingle}}
\newenvironment{abstractseparate} {\begin{alwayssingle} \pagestyle{empty}
\vspace*{-1in}
\begin{center}
{ \Large {\bfseries {\@title}} \par}
{{\large \vspace*{1ex} \@author} \par}
{\large \vspace*{1ex}
{{\@collegeordept} \par}
{{\@university} \par}
\vspace*{1ex}
{{\it \submittedtext} \par}
{\it {\@degree} \par}
\vspace*{2ex}
{\@degreedate}}
\end{center}}
{\end{alwayssingle}}
\newenvironment{romanpages}
{\setcounter{page}{1}
\renewcommand{\thepage}{\roman{page}}}
{\newpage\renewcommand{\thepage}{\arabic{page}}}
\usepackage[utf8]{inputenc}
\usepackage{pdfpages}
\usepackage{listings}
\usepackage[toc,page,titletoc]{appendix}
我有一个错误的形式
! Undefined control sequence.
l.84 \makechapterstyle
答案1
这可以通过包轻松实现titlesec
。更多详细信息,您可以查看这。不太确定您期望的无编号章节标题的样式是什么(例如,目录、图表列表等)。我假设它们只是一条水平线,标题在下面。这是一个书籍类的示例。我相信它也会在您的案例中起作用。
\documentclass[a4paper,12pt]{book}
\usepackage{tikz}
\usepackage{lipsum}
\definecolor{yourcolor}{HTML}{008bb2}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\color{yourcolor}}%%This is the format code applied to the whole heading (label+title)
{\flushright\sffamily\Huge\textbf{\chaptername}\space%
\begin{tikzpicture}[baseline={([yshift=-.6ex]current bounding box.center)}]
\node[fill=yourcolor,circle,text=white] {\textbf{\thechapter}};
\end{tikzpicture}%
}%%The chapter label is defined in here
{0pt}%%This is the horizontal separation between label and title body and must be a length (it must not be empty)
{\vspace{1.5ex}\hrule height 1.5pt \vspace{1em}\itshape\huge\sffamily}%%This is the code preceding the title body
[]%%This is the code following the title body
\begin{document}
\tableofcontents
\listoffigures
\chapter{A chapter}
\section{Section}
\lipsum[1]
\section{Section 2}
\section{test}
\section{abc}
\lipsum[1]
\chapter{Second chapter}
\section{Section 2}
\lipsum[1]
\section{test}
\lipsum[1]
\end{document}