我必须说我使用 LaTeX 才几个月,所以你可以说我还是个初学者。
我有一个大项目,其中有许多修改。每次我想更改文档的外观和感觉时,我都会在互联网上搜索并将其复制粘贴到文档中。因此,您可以说它已经变得非常大,我很好奇这是否是一件坏事,以及是否有优化的空间(例如:我使用包做了一些事情,但我可以使用我已经包含的另一个包来完成它)。基本上,我想看看比我更有 LaTeX 经验的人对我所做的事情有什么看法,以及任何建议、改进、更好的组织方式等。
以下是我所做的修改:
\documentclass[
12pt, % Font size
a4paper % Paper type
]{book}
% Packages
\usepackage[
margin=2.7cm, % Margin size
marginparwidth=2cm, % Margin note size
marginparsep=3mm, % Space between margin and text
headheight=15pt % Header height (fix that stupid warn from fancyhdr)
]{geometry}
\usepackage[romanian]{babel} % Romanian characters support
\usepackage{indentfirst} % Add paragraph indentation even after a section
\usepackage{marginnote} % Notes on the margins of a document (more advanced \marginpar)
\usepackage{titlesec} % Customize titles
\usepackage{hyperref} % Hyperlink support
\usepackage{graphicx} % Image support
\usepackage{xcolor} % Custom colors
\usepackage{fancyhdr} % Custom headers
\usepackage[titles]{tocloft} % Customize ToC
% Image path
\graphicspath{ {../img/} }
% Hyperlink configuration
\hypersetup{
colorlinks=true,
urlcolor=black,
linkcolor=black % ToC links color
}
% Colors (for chapter)
\definecolor{gray75}{gray}{0.75}
% Custom format for titles, sections etc.
\titleformat{\part}[display]
{\Huge\scshape\filright}
{\partname~\thepart:}
{20pt}
{\thispagestyle{empty}}
\titleformat{\chapter}[hang]
{\Large}
{\thechapter \ifnum\value{chapter} > 9 {\hspace{7pt}}\else{\hspace{15pt}}\fi \textcolor{gray75}{|}\hspace{15pt}}
{0pt}
{\thispagestyle{chapterfancystyle}\Large}
\renewcommand{\thesection}{\arabic{section}}
\titleformat*{\section}
{\large\bfseries}
\titleformat{\subsection}
{\normalfont\normalfont\bfseries}
{}
{1.5em}
{}
% Custom commands
% Format: \newcommand{\command}[variable]{action #variable}
\newcommand{\rom}[1]{\uppercase\expandafter{\romannumeral #1\relax}} % Roman numerals
\newcommand{\textbfit}[1]{\textbf{\textit{#1}}} % combine bold and italic
\newcommand{\operatitle}{} % to not get errors
\newcommand{\operaauthor}{} % to not get errors
% Customize \marginnote font
\renewcommand\marginfont{\ttfamily\footnotesize}
% Make \ttfamily hyphenate words for the margin notes
\DeclareFontFamily{OT1}{cmtt}{\hyphenchar\font=-1}
\DeclareFontFamily{\encodingdefault}{\ttdefault}{\hyphenchar\font=`\-}
\DeclareFontFamily{T1}{cmtt}{\hyphenchar\font=45}
% ToC customization
\setcounter{tocdepth}{0} % Make only chapters appear in ToC
\renewcommand{\cftdot}{} % Remove ToC dots
% Disable bold in ToC
\addtocontents{toc}{\string\renewcommand{\protect\cftchappagefont}{\protect\normalfont}}
\addtocontents{toc}{\string\renewcommand{\protect\cftchapfont}{\protect\normalfont}}
\addtocontents{toc}{\string\renewcommand{\protect\cftchapleader}{\protect\normalfont\protect\cftdotfill{\protect\cftsecdotsep}}}
% Custom fancy styles
\fancypagestyle{chapterfancystyle}{
\fancyhf{}
\fancyfoot[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}
}
\fancypagestyle{plain}{
\fancyhf{}
\fancyhead[LE]{\small\textsc{Esee pentru bacalaureat}}
\fancyhead[RO]{
\begingroup
\small
\let\textbfit\relax % smart thing to use \textsc in header but keep it bfit everywhere else
\textsc{\operatitle\ -- \operaauthor}
\endgroup
}
\fancyfoot[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{1pt}
}
% Use empty pagestyle on blank pages between chapters
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}\thispagestyle{empty}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
\begin{document}
\input{titlepage.tex} % Import the title page
% Use empty pagestyle for the entirety of the ToC
\addtocontents{toc}{\protect\thispagestyle{empty}}
\clearpage
{
\pagestyle{empty}
\fancypagestyle{plain} % create temporary plain pagestyle
{
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
\tableofcontents % actually generate the ToC
\thispagestyle{empty}
}
\pagestyle{plain} % revert to plain pagestyle
[...]
\end{document}
另外,这是整个 TeX 文档,如果需要更多背景信息
编辑:感谢大家的建议,我做了一些小改动,并将所有内容都放入我自己的自定义文档类中。这样实际文档就只剩下:
\documentclass{eseuri_bac_romana}
\begin{document}
\maketitle % Insert the custom title page
\CustomToC % Insert the custom ToC
[...]
\end{document}
文件如下.cls
:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{eseuri_bac_romana}[2022/03/25 My custom class for the essay book]
\LoadClass[
12pt, % Font size
a4paper % Paper type
]{book}
% Packages
\RequirePackage[
margin=2.7cm, % Margin size
marginparwidth=2cm, % Margin note size
marginparsep=3mm, % Space between margin and text
headheight=15pt % Header height (fix that stupid warn from fancyhdr)
]{geometry}
\RequirePackage[romanian]{babel} % Romanian characters support
\RequirePackage{indentfirst} % Add paragraph indentation even after a section
\RequirePackage{marginnote} % Notes on the margins of a document (more advanced \marginpar)
\RequirePackage{titlesec} % Customize titles
\RequirePackage{graphicx} % Image support
\RequirePackage{xcolor} % Custom colors
\RequirePackage{fancyhdr} % Custom headers
\RequirePackage[titles]{tocloft} % Customize ToC
\RequirePackage{hyperref} % Hyperlink support, keep last in package list!
% Image path
\graphicspath{ {../img/} }
% Hyperlink configuration
\hypersetup{
colorlinks=true,
urlcolor=black,
linkcolor=black % ToC links color
}
% Colors (for chapter)
\definecolor{gray75}{gray}{0.75}
% Custom format for titles, sections etc.
\titleformat{\part}[display]
{\Huge\scshape\filright}
{\partname~\thepart:}
{20pt}
{\thispagestyle{empty}}
\newcommand{\DetermineHSpaceSize}{\ifnum\value{chapter} > 9 {\hspace{7pt}}\else{\hspace{15pt}}\fi} % Make the hspace that goes between chapter number and line smaller if number is past 10
\titleformat{\chapter}[hang]
{\Large}
{\thechapter\DetermineHSpaceSize\textcolor{gray75}{|}\hspace{15pt}}
{0pt}
{\thispagestyle{chapterfancystyle}\Large}
\renewcommand{\thesection}{\arabic{section}} % Remove chapter number from section
\titleformat*{\section}
{\large\bfseries}
\titleformat{\subsection}
{\normalfont\normalfont\bfseries}
{}
{1.5em}
{}
% Custom commands
% Format: \newcommand{\command}[variable]{action #variable}
\newcommand{\rom}[1]{\uppercase\expandafter{\romannumeral #1\relax}} % Roman numerals
\newcommand{\textbfit}[1]{\textbf{\textit{#1}}} % combine bold and italic
\newcommand{\operatitle}{} % to not get errors
\newcommand{\operaauthor}{} % to not get errors
\newcommand{\CustomToC} % command to generate ToC with empty pagestyle
{
\addtocontents{toc}{\protect\thispagestyle{empty}}
\clearpage % new page to ensure it switched to empty pagestyle
{
\pagestyle{empty}
\fancypagestyle{plain} % create temporary plain pagestyle
{
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
\tableofcontents % actually generate the ToC
\thispagestyle{empty}
}
\pagestyle{plain} % revert to plain pagestyle
}
% Customize \marginnote font
\renewcommand\marginfont{\ttfamily\footnotesize}
% Make \ttfamily hyphenate words for the margin notes
\DeclareFontFamily{OT1}{cmtt}{\hyphenchar\font=-1}
\DeclareFontFamily{\encodingdefault}{\ttdefault}{\hyphenchar\font=`\-}
\DeclareFontFamily{T1}{cmtt}{\hyphenchar\font=45}
% ToC customization
\setcounter{tocdepth}{0} % Make only chapters appear in ToC
\renewcommand{\cftdot}{} % Remove ToC dots
\addtocontents{toc}{\string\renewcommand{\protect\cftchappagefont}{\protect\normalfont}}
\addtocontents{toc}{\string\renewcommand{\protect\cftchapfont}{\protect\normalfont}}
\addtocontents{toc}{\string\renewcommand{\protect\cftchapleader}{\protect\normalfont\protect\cftdotfill{\protect\cftsecdotsep}}} % Disable bold in ToC
% Custom fancy styles
\fancypagestyle{chapterfancystyle}{
\fancyhf{}
\fancyfoot[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}
} % style for chapter page
\fancypagestyle{plain}{
\fancyhf{}
\fancyhead[LE]{\small\textsc{Eseuri pentru bacalaureat}}
\fancyhead[RO]{
\begingroup
\small
\let\textbfit\relax % smart thing to use \textsc in header but keep it bfit everywhere else
\textsc{\operatitle\ -- \operaauthor}
\endgroup
}
\fancyfoot[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{1pt}
} % style for the rest of the document
% Use empty pagestyle on blank pages between chapters
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}\thispagestyle{empty}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
% Create custom title
\renewcommand{\maketitle}
{
\begin{titlepage}
[...]
\end{titlepage}
}