我受到文章“使用 TikZ 制作精美章节标题”(非常感谢 Stefan Kottwitz)的启发,并创建了整个精美的章节。但我现在需要做的是将整个章节和章节代码导入到我的报告类中,因为我不想将这些代码放在我的项目中。例如,当我开始我的新项目并添加\documentclass[svgnames]{report}
并以 开始文档时,\section{bla bla}
报告类中编辑的章节将自动应用于\section{bla bla}
命令。
我寻求一些帮助,因为我从来没有玩过乳胶文件和类。
答案1
对于你的课程,我添加了一些有用的包和选项
\RequirePackage[utf8]{inputenc}
\RequirePackage[T1]{fontenc}
但如果你想的话你可以删除,我还添加了
\PassOptionsToPackage{dvipsnames,svgnames}{xcolor}
对...有用TikZ
最后
\RequirePackage{etex}
\RequirePackage{fixltx2e}
但您也可以删除这些包。您需要将下一个代码保存在名为 myreport.cls 的文件中。
\NeedsTeXFormat{LaTeX2e}[1995/12/01]% standard latex package works with this format
\ProvidesClass{myreport}% we give the name of the new class (here myreport) and we give
% some informations about date of creation and the aim of the document
[2012/03/27\space Version:\space 1.0\space myreport documentation class]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
% more complex We create a new class based on an existing class and we want to use the
options of report
\ProcessOptions\relax% this is the way to process the options, Stephan gave the good link
for clsguide.pdf
\LoadClass[]{report} % add options if necessarry , we can create personal options
\PassOptionsToPackage{dvipsnames,svgnames}{xcolor}
% To avoid clash with xcolor, \PassOptionsToPackage is the good macro to pass options
% tikz loads xcolor, and if you want some extra colors, you need to use xcolor with
% dvipsnames,svgnames ( see xcolor.pdf ). But you need to make before loading tikz.
\RequirePackage[utf8]{inputenc}
% I recommend to use utf8 but you can prefer latin1. You can adapt this line.
\RequirePackage[T1]{fontenc}
% personally I don't use this line because I work with fourier font and fourier.sty
% loads automatically [T1]{fontenc}.
\RequirePackage{tikz}
\RequirePackage{kpfonts}
\RequirePackage[explicit]{titlesec}
\RequirePackage{etex}
\RequirePackage{fixltx2e}
% colors
\definecolor{fHlavicky}{RGB}{124,252,0}
\definecolor{fPisma}{RGB}{0,0,0}
\definecolor{fCHaSEK}{RGB}{255,127,0}
\definecolor{fSSaSSS}{RGB}{0,191,255}
\newcommand*\chapterlabel{}
\newcommand*\sectionlabel{}
\newcommand*\subsectionlabel{}
\newcommand*\subsubsectionlabel{}
%CHAPTER
\titleformat{\chapter}
{\gdef\chapterlabel{}
\normalfont\sffamily\Huge\bfseries\scshape}
{\gdef\chapterlabel{\thechapter\ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-3.2cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\draw[fill=fHlavicky] (0,0) rectangle
(\paperwidth,3cm);
\node[anchor=west,xshift=.7,yshift=.07\paperwidth,rectangle,
rounded corners=20pt,inner sep=11pt,
fill=fCHaSEK]
{\color{fPisma}\chapterlabel#1};
\end{tikzpicture}
};
\end{tikzpicture}
}
%SEKCTION
\titleformat{\section}
{\gdef\sectionlabel{}
\normalfont\sffamily\LARGE\bfseries\slshape}
{\gdef\sectionlabel{\thesection\ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=west,xshift=.2\paperwidth,rectangle,
rounded corners=7pt,inner sep=3pt,
fill=fCHaSEK]
{\color{fPisma}\sectionlabel#1};
\end{tikzpicture}
}
%SUBSEC.
\titleformat{\subsection}
{\gdef\subsectionlabel{}
\normalfont\sffamily\large\bfseries\upshape}
{\gdef\subsectionlabel{\thesubsection\ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=west,xshift=.2\paperwidth,rectangle,
rounded corners=5pt,inner sep=2pt,
fill=fSSaSSS]
{\color{fPisma}\subsectionlabel#1};
\end{tikzpicture}
}
%SUBSUBSEC.
\titleformat{\subsubsection}
{\gdef\subsubsectionlabel{}
\normalfont\sffamily\large\bfseries\upshape}
{\gdef\subsubsectionlabel{\thesubsubsection\ }}{0pt}
{\color{fSSaSSS}\subsubsectionlabel#1}
\titlespacing*{\chapter}{0pt}{50pt}{-60pt}
\titlespacing*{\section}{-210pt}{5pt}{10pt}
\titlespacing*{\subsection}{-180pt}{5pt}{10pt}
\titlespacing*{\subsubsection}{-30pt}{5pt}{10pt}
\endinput
现在使用该类:
\documentclass{myreport}
\begin{document}
\section{Introduction}
\section{Suite}
\subsubsection{intro-suite}
\end{document}
答案2
最简单的解决方案:
myreport.cls
创建一个由您的代码组成的类文件。\LoadClass{report}
在开头添加。- 看着
clsguide.pdf
您应该添加更多管理内容\ProvidesClass
。 - 与 一起使用
\documentclass{myreport}
。