我的自定义样式不起作用

我的自定义样式不起作用

这是我第一次使用 LaTeX。这可能是某种愚蠢的问题。但无论如何。我在 Fedora 上花了一天时间使用 TeXLive。问题如下。我有一些文件 1:

\documentclass{book}
\usepackage{vit} % it's my own vit.sty file 
\usepackage[utf8]{inputenc}

\usepackage{vmargin}
\setpapersize{A4}
\setmarginsrb{2cm}{1.5cm}{1cm}{1.5cm}{0pt}{0mm}{0pt}{13mm}
\usepackage{indentfirst}
\sloppy

\begin{document}

\chapter{AutoSDK}

blabla

\end{document}

第二个文件是我自己风格的vit.sty

\NeedsTeXFormat{LaTeX2e}
\RequirePackage[loadonly]{titlesec}
\RequirePackage{color}
\definecolor{vit_black100}{cmyk}{0.0, 0.0, 0.0, 1}
\definecolor{vit_gray90}{cmyk}{0.0, 0.0, 0.0, 0.90} %can be used as background color
\definecolor{vit_gray70}{cmyk}{0.0, 0.0, 0.0, 0.70} %can be used as background color
\definecolor{vit_gray5}{cmyk}{0.0, 0.0, 0.0, 0.05} %can be used as background color
\definecolor{vit_snow}{cmyk}{0.0, 0.0, 0.0, 0.0} %can be used as background color
\definecolor{vit_whiteshadow}{cmyk}{0.50, 0.0, 0.0, 0.33}
\definecolor{vit_whitecolor}{cmyk}{0.25, 0.0, 0.0, 0.10}
\definecolor{vit_yolkshadow}{cmyk}{0.0, 0.60, 1, 0.10}
\definecolor{vit_yolkcolor}{cmyk}{0.0, 0.10, 1, 0}

\titleformat{\chapter} 
    {\Large\slshape\bfseries\sffamily\textcolor{vit_whiteshadow}} 
    {\textsc{\MakeTextLowercase{\thesection}}}%
    {1em}
    {\spacedlowsmallcaps}
    [{\color{vit_whitecolor}\titlerule[2.5pt]} 123]

LaTeX 返回以下错误:

This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012)
 restricted \write18 enabled.
entering extended mode
(./AutoSDK.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2012-05-30, ngerman-x-2012-05-30, afrikaans, ancientgreek, ibycus, arabi
c, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danis
h, dutch, ukenglish, usenglishmax, esperanto, estonian, ethiopic, farsi, finnis
h, french, friulan, galician, german, ngerman, swissgerman, monogreek, greek, h
ungarian, icelandic, assamese, bengali, gujarati, hindi, kannada, malayalam, ma
rathi, oriya, panjabi, tamil, telugu, indonesian, interlingua, irish, italian, 
kurmanji, latin, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk,
 polish, portuguese, romanian, romansh, russian, sanskrit, serbian, serbianc, s
lovak, slovenian, spanish, swedish, turkish, turkmen, ukrainian, uppersorbian, 
welsh, loaded.
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/book.cls
Document Class: book 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/bk10.clo)) (./vit.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/titlesec/titlesec.sty)
(/usr/local/texlive/2012/texmf-dist/tex/latex/graphics/color.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/latexconfig/color.cfg)
(/usr/local/texlive/2012/texmf-dist/tex/latex/graphics/dvips.def)
(/usr/local/texlive/2012/texmf-dist/tex/latex/graphics/dvipsnam.def)))
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/inputenc.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/utf8.def
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/t1enc.dfu)
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/ot1enc.dfu)
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/omsenc.dfu)))
(/usr/local/texlive/2012/texmf-dist/tex/latex/vmargin/vmargin.sty
Package: vmargin 2004/07/15 V2.5 set document margins (VK)
) (/usr/local/texlive/2012/texmf-dist/tex/latex/tools/indentfirst.sty)
(./AutoSDK.aux)
! Undefined control sequence.
\reserved@c ...abelfalse \fi \ifnum \ttll@chapter 
                                                  >\c@secnumdepth \ttl@label...
l.13 \chapter{
              AutoSDK}
?

答案1

删除;loadonly选项titlesec,即

\RequirePackage[loadonly]{titlesec}

使用

\RequirePackage{titlesec}

在 中vit.sty。如果您使用该loadonly选项,您将必须从头定义分段单元格式,并且根据您的定义\titleformat{\chapter}您不愿意这样做。

您还需要做以下修改\titleformat{\chapter}

\RequirePackage{textcase}
\titleformat{\chapter} 
    {\Large\slshape\bfseries\sffamily\color{vit_whiteshadow}} 
    {\textsc{\MakeTextLowercase{\thesection}}}%
    {1em}
    {}
    [{\color{vit_whitecolor}\titlerule[2.5pt]}123]
  • 您正在使用\textcolor{vit_whiteshadow}\textcolor 需要两个参数,因此我将其更改为\color{vit_whiteshadow}

  • 由于您正在使用\MakeTextLowercase,所以您需要该textcase 包;顺便问一下,您真的需要\MakeTextLowecase\thesection

  • 您正在使用的\spacedlowsmallcaps不是标准 LaTeX 命令,因此如果您想使用它,您还需要加载提供该命令的包;但是,我所知道的唯一提供该命令的包是,classicthesis加载该包将完全改变您的布局,这可能不是您想要的;如果您想单独使用此命令,您可以从中复制的\spacedlowsmallcaps定义classicthesis.sty

相关内容