![LaTeX 错误!} 太多。\color@endbox ->\color@endgroup](https://linux22.com/image/286317/LaTeX%20%E9%94%99%E8%AF%AF%EF%BC%81%7D%20%E5%A4%AA%E5%A4%9A%E3%80%82%5Ccolor%40endbox%20-%3E%5Ccolor%40endgroup.png)
我正在尝试使用 listing 包输入 r 代码。但是,目前我的文件无法编译并返回以下错误:
! Too many }'s.
\color@endbox ->\color@endgroup \egroup
我回过头来想,发现只有当我使用部门提供的样式文件时才会出现错误。我复制了导致错误的 .sty 文件,并附上了一个显示错误示例。如果您删除 \usepackage[y4project]{edmaths},您会注意到错误会消失。
我已经搜索过但无法使以下修复起作用。http://www.latex-community.org/forum/viewtopic.php?f=45&p=18575
这是 MWE(如果运行它,将会产生错误):
\documentclass[12pt]{report}
\usepackage{amssymb,amsmath,amsthm}
\usepackage[y4project]{edmaths} %%%% REMOVE THIS TO FIX ERROR
\usepackage{listings}
\usepackage{color}
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\lstset{ %
backgroundcolor=\color{white}, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}
basicstyle=\footnotesize, % the size of the fonts that are used for the code
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
breaklines=true, % sets automatic line breaking
captionpos=b, % sets the caption-position to bottom
commentstyle=\color{mygreen}, % comment style
deletekeywords={...}, % if you want to delete keywords from the given language
escapeinside={\%*}{*)}, % if you want to add LaTeX within your code
extendedchars=true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
frame=single, % adds a frame around the code
keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
keywordstyle=\color{blue}, % keyword style
language=Octave, % the language of the code
morekeywords={*,...}, % if you want to add more keywords to the set
numbers=left, % where to put the line-numbers; possible values are (none, left, right)
numbersep=5pt, % how far the line-numbers are from the code
numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
rulecolor=\color{black}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
showstringspaces=false, % underline spaces within strings only
showtabs=false, % show tabs within strings adding particular underscores
stepnumber=2, % the step between two line-numbers. If it's 1, each line will be numbered
stringstyle=\color{mymauve}, % string literal style
tabsize=2, % sets default tabsize to 2 spaces
title=\lstname % show the filename of files included with \lstinputlisting; also try caption instead of title
}
% End of preamble
\author{TESTING }
\title{TEST FILE}
\begin{document}
\maketitle
\tableofcontents
\chapter{Introduction}
\begin{table}[h]
\centering
\begin{tabular}{clll}
Sig. level & 1$\%$ & 5$\%$ & 10$\%$ \\ \hline
$\tau$ & -3.90 & -3.34 & -3.04 \\ \hline
\end{tabular}
\end{table}
\begin{lstlisting}
#include <stdio.h>
#define N 10
/* Block
* comment */
int main()
\end{lstlisting}
\end{document}
这是 edmaths 的 .sty 文件:
%% Package `edmaths' (26.8.2008)
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{edmaths}[2007/02/05 Edinburgh maths thesis/report style v0.95]
\RequirePackage{calc,ifthen,setspace,amsmath,amsthm,amscd,amssymb}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set up the page size and margins %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setlength{\paperheight}{297mm} % A4 Paper
\setlength{\paperwidth}{210mm} %
\setlength{\oddsidemargin}{14.6mm} % Left/Inside: 4.0cm (rel. -1in)
\setlength{\evensidemargin}{-.4mm} % Right/Outside: 2.5cm (rel. -1in)
\setlength{\topmargin}{-17.4mm} % \
\setlength{\headheight}{6mm} % | Top: 2.0cm (rel. -1in), out of which 6mm for the header
\setlength{\headsep}{6mm} % /
\setlength{\textwidth}{145mm} % Margins: 2.5cm + 4cm
% Textheight delayed until we know the line spacing.
% The following is removed in favour of the `report' class options "oneside/twoside".
%\@twosidefalse \@mparswitchfalse % Single-sided by default
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Provide some fancy option %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newboolean{with-fourier} % Use the `fourier' package for Adobe Utopia font
\newboolean{with-hyperref} % Use the `hyperref' package for clickable links and bookmarks, all black
\newboolean{with-colour} % Add sane colours to the hyperref links
\newboolean{with-fancyhdr} % Use the `fancyhdr' package to provide header and footer
\ifthenelse{\isundefined{\degreetext}}{\newcommand{\degreetext}{Specify a degree option!}}{}
\ifthenelse{\isundefined{\stretchfactor}}{\newcommand{\stretchfactor}{1}}{}
\DeclareOption{fourier}{\setboolean{with-fourier}{true}}
\DeclareOption{hyperref}{\setboolean{with-hyperref}{true}}
\DeclareOption{colour}{\setboolean{with-colour}{true}}
\DeclareOption{fancyhdr}{\setboolean{with-fancyhdr}{true}}
\DeclareOption{phd}{\renewcommand{\degreetext}{Doctor of Philosophy}}
\DeclareOption{firstyear}{\renewcommand{\degreetext}{First-Year Report\\Graduate School of Mathematics}}
\DeclareOption{secondyear}{\renewcommand{\degreetext}{Second-Year Report\\Graduate School of Mathematics}}
\DeclareOption{thirdyear}{\renewcommand{\degreetext}{Third-Year Report\\Graduate School of Mathematics}}
\DeclareOption{y4project}{\renewcommand{\degreetext}{Year 4 Project\\School of Mathematics}}
\DeclareOption{masterph}{\renewcommand{\degreetext}{Master of Philosophy}}
\DeclareOption{mastersc}{\renewcommand{\degreetext}{Master of Science by Research}}
\DeclareOption{single}{\renewcommand{\stretchfactor}{1}}
\DeclareOption{onehalf}{\renewcommand{\stretchfactor}{1.5}}
\DeclareOption{double}{\renewcommand{\stretchfactor}{2}}
%\DeclareOption{oneside}{\@twosidefalse \@mparswitchfalse} % Single-sided by default
%\DeclareOption{twosides}{\@twosidetrue \@mparswitchtrue}
\ProcessOptions
\ifthenelse{\boolean{with-fourier}}
{ \RequirePackage{cmap}
\RequirePackage{fourier}
\RequirePackage[T1]{fontenc}
\RequirePackage{microtype}
} {}
\ifthenelse{\boolean{with-hyperref}}
{
\RequirePackage[dvipsnames]{xcolor}
\RequirePackage[pdftitle={\@title}, pdfauthor={\@author}, pdfcreator={PDFLaTeX with edmaths}, pdfpagelayout=OneColumn, colorlinks=true, linkcolor=black, urlcolor=black, citecolor=black]{hyperref}
\ifthenelse{\boolean{with-colour}}
{
\hypersetup{linkcolor=Sepia, urlcolor=NavyBlue, citecolor=Sepia}
} {}
} {}
\ifthenelse{\boolean{with-fancyhdr}}
{
\RequirePackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RO,LE]{\thepage}
\fancyfoot[RO,LE]{\thepage}
\fancyhead[LO]{\it\@title}
\fancyhead[RE]{\@author}
\fancyfoot[RE,LO]{}
} {}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set up the text body height %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% For the text height, we calculate the largest number of lines that gives us no more than 4cm bottom margin.
% This depends on the line spacing, which we need first.
\setstretch{\stretchfactor}
% Debug only: In the next line, \XXXfactor contains the number of lines on a text-only page.
%\newlength{\XXXunit}\setlength{\XXXunit}{1pt}\newlength{\XXXfactor}\setlength{\XXXfactor}{1pt + ((672pt - \topskip) / \baselineskip) * \XXXunit}
\newlength{\scratchlength}\setlength{\scratchlength}{\topskip + ((672pt - \topskip) / \baselineskip) * \baselineskip + \baselineskip}
\setlength{\textheight}{\scratchlength}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Make the title page etc %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand{\maketitle}{%
\begin{titlepage}
\singlespacing
\addtolength{\oddsidemargin}{-0.75cm}
\begin{center}
\null\vskip 4.1cm
\begin{minipage}[t][7.6cm]{10.5cm}
\begin{center}
{\LARGE\textbf{\@title}\par}\vfill
{\Large\textit{\@author}\par}
\end{center}
\end{minipage}
\vfill
{\Large\degreetext \par University of Edinburgh \par\@date \par}
\end{center}
\end{titlepage}
\if@twoside
\thispagestyle{empty}
\cleardoublepage
\else
\addtocounter{page}{1}
\fi
}
\newcommand{\declaration}{%
\chapter*{Declaration}
\begin{singlespace}
I declare that this thesis was composed by myself
and that the work contained therein is my own,
except where explicitly stated otherwise in the text.
\end{singlespace}
{\raggedleft\vspace{2cm}(\textit{\@author})
}
}
\renewenvironment{abstract}{\chapter*{\abstractname}}{\addcontentsline{toc}{chapter}{\abstractname}}
\newcommand{\dedication}[1]{%
\clearpage
\thispagestyle{plain}
\vspace*{7cm}
\begin{center}
\Large\it #1
\end{center}
}
%% A special declaration for Year 4 reports
\newcommand{\yfourdeclaration}[1]{%
\vfill
\noindent
This project report is submitted in partial fulfilment of the requirements for the degree of
\textit{#1}.
}
答案1
(不要投票,我稍后会删除,但评论太长了)
我没有收到任何错误。添加\listfiles
并检查运行结束时显示的列表中的文件日期。
*File List*
report.cls 2007/10/19 v1.4h Standard LaTeX document class
size12.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
amssymb.sty 2013/01/14 v3.01 AMS font symbols
amsfonts.sty 2013/01/14 v3.01 Basic AMSFonts support
amsmath.sty 2013/01/14 v2.14 AMS math features
amstext.sty 2000/06/29 v2.01
amsgen.sty 1999/11/30 v2.0
amsbsy.sty 1999/11/29 v1.2d
amsopn.sty 1999/12/14 v2.01 operator names
amsthm.sty 2004/08/06 v2.20
edmaths.sty 2007/02/05 Edinburgh maths thesis/report style v0.95
calc.sty 2007/08/22 v4.3 Infix arithmetic (KKT,FJ)
ifthen.sty 2001/05/26 v1.1c Standard LaTeX ifthen package (DPC)
setspace.sty 2011/12/19 v6.7a set line spacing
amscd.sty 1999/11/29 v2.0
listings.sty 2013/08/26 1.5b (Carsten Heinz)
keyval.sty 1999/03/16 v1.13 key=value parser (DPC)
lstmisc.sty 2013/08/26 1.5b (Carsten Heinz)
listings.cfg 2013/08/26 1.5b listings configuration
color.sty 2005/11/14 v1.0j Standard LaTeX Color (DPC)
color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty 2010/04/08 v1.3 Providing info/warning/error messages (HO)
ltxcmds.sty 2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
lstlang1.sty 2013/08/26 1.5b listings language file
supp-pdf.mkii
umsa.fd 2013/01/14 v3.01 AMS symbols A
umsb.fd 2013/01/14 v3.01 AMS symbols B
omlcmr.fd 1999/05/25 v2.5h Standard LaTeX font definitions
omscmr.fd 1999/05/25 v2.5h Standard LaTeX font definitions
***********