跳轉到內容

LaTeX/主題

來自華夏公益教科書

LaTeX

入門
  1. 簡介
  2. 安裝
  3. 安裝額外的包
  4. 基礎
  5. 如何獲得幫助

常用元素

  1. 文件結構
  2. 文字格式
  3. 段落格式
  4. 顏色
  5. 字型
  6. 列表結構
  7. 特殊字元
  8. 國際化
  9. 旋轉
  10. 表格
  11. 標題建立
  12. 頁面佈局
  13. 自定義頁面頁首和頁尾‎
  14. 匯入圖形
  15. 浮動體、圖形和標題
  16. 腳註和邊注
  17. 超連結
  18. 標籤和交叉引用
  19. 首字母

機制

  1. 錯誤和警告
  2. 長度
  3. 計數器
  4. 盒子
  5. 規則和撐高

技術文字

  1. 數學
  2. 高階數學
  3. 定理
  4. 化學圖形
  5. 演算法
  6. 原始碼清單
  7. 語言學

特殊頁面

  1. 索引
  2. 詞彙表
  3. 參考文獻管理
  4. 更多參考文獻

特殊文件

  1. 科學報告(學士報告、碩士論文、博士論文)
  2. 信函
  3. 簡報
  4. 教師專欄
  5. 簡歷
  6. 學術期刊(MLA、APA 等)

建立圖形

  1. 介紹過程圖形
  2. MetaPost
  3. 圖片
  4. PGF/TikZ
  5. PSTricks
  6. Xy-pic
  7. 建立 3D 圖形

程式設計

  1. 純 TeX
  2. 建立包
  3. 建立包文件
  4. 主題

其他

  1. 模組化文件
  2. LaTeX 文件的協作寫作
  3. 匯出到其他格式

幫助和建議

  1. 常見問題解答
  2. 提示和技巧

附錄

  1. 作者
  2. 連結
  3. 包參考
  4. LaTeX 文件示例
  5. 索引
  6. 命令詞彙表

編輯此框編輯目錄

LaTeX 新手經常會因為該系統缺乏視覺自定義功能而感到失望。實際上,這是有意為之:LaTeX 的理念是專注于格式化,而讓作者專注於內容。

在本節中,我們將展示透過一些努力可以實現的目標。

簡介

[edit | edit source]

接下來,我們將編寫主題,一個只改變文件外觀的包,這樣我們的文件就可以使用或不使用主題。

請注意,雖然它可能看起來很美觀,但這絕對不是排版的典範。你不應該在嚴肅的出版物中使用這種主題。這更多的是一個技術示例,展示 LaTeX 的功能。

包配置

[edit | edit source]

這裡沒有什麼好說的。這直接應用了建立包一章的內容。

我們載入所需的包。

  • needspace 用於防止在分節命令後立即出現分頁符。
  • tikz 用於繪製花哨的素材。

我們定義了一個顏色選項,你可以根據需要使用任意數量的選項。使用特定名稱定義顏色使其非常靈活。我們還使用了一個選項來切換花哨的反射效果,這可能有點過分

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{theme-fancy}[2013/01/13 v1.0 fancy theme]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Packages

\RequirePackage{geometry}
\RequirePackage{needspace}
\RequirePackage[svgnames]{xcolor}

\RequirePackage{hyperref}
\hypersetup{colorlinks=true}

\RequirePackage{fancyhdr}

\RequirePackage{tikz}
\usetikzlibrary{
  calc,
  decorations.pathmorphing,
  fadings,
  shadows,
  shapes.geometric,
  shapes.misc,
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Options

%% Toggle reflection.
\newif\if@mirrors\@mirrorsfalse
\DeclareOption{mirrors}{
  \@mirrorstrue
}

%% Colors.
\newif\if@red\@redfalse
\DeclareOption{red}{
  \@redtrue
}

\ExecuteOptions{}
\ProcessOptions\relax

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Configuration

\renewcommand{\familydefault}{\sfdefault}
\setlength{\parskip}{0.5\baselineskip}

%% Colors
\colorlet{toctitle}{DarkGray!50!black}
\colorlet{titlebg}{MidnightBlue}
\colorlet{titlefg}{LightBlue}
\colorlet{titletxt}{MidnightBlue}
\colorlet{sectionfg}{MidnightBlue}
\colorlet{subsectionfg}{SteelBlue}
\colorlet{subsubsectionfg}{LightSteelBlue!60!black}

\if@red
\colorlet{toctitle}{DarkGray!50!black}
\colorlet{titlebg}{DarkRed}
\colorlet{titlefg}{FireBrick!50}
\colorlet{titletxt}{DarkRed}
\colorlet{sectionfg}{DarkRed}
\colorlet{subsectionfg}{Crimson!50!black}
\colorlet{subsubsectionfg}{LightSteelBlue!60!black}
\fi
[edit | edit source]

我們使用 TikZ 繪製一個填充的半圓。

fancyhdr 用於設定頁首和頁尾。我們注意使用 fancy 樣式,並透過 \fancyhf{} 從頭開始擦除之前的頁首和頁尾。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Header and Footer

\tikzstyle{foliostyle}=[fill=Lavender, text=MidnightBlue, inner sep=5pt, semicircle]

\pagestyle{fancy}
\fancyhf{}
\fancyfoot[C]{
  \vskip 3pt
  \begin{tikzpicture}
    \node[foliostyle]
    {\bfseries\thepage};
  \end{tikzpicture}
}

\renewcommand{\headrulewidth}{0.8pt}
\addtolength{\headheight}{\baselineskip} 
\renewcommand{\headrule}{\color{LightGray}\hrule}
\fancyhead[LE]{ \textcolor{gray}{\slshape \rightmark} } 
\fancyhead[RO]{ \textcolor{gray}{\slshape \leftmark} }

目錄

[edit | edit source]

我們重新定義了 \tableofcontents 所使用的命令。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Table of contents

\newcommand{\sectiontoccolor}{sectionfg}
\newcommand{\subsectiontoccolor}{subsectionfg}
\newcommand{\subsubsectiontoccolor}{subsubsectionfg}

\renewcommand*\l@section{\color{\sectiontoccolor}\def\@linkcolor{\sectiontoccolor}\@dottedtocline{1}{1.5em}{2.3em}}
\renewcommand*\l@subsection{\color{\subsectiontoccolor}\def\@linkcolor{\subsectiontoccolor}\@dottedtocline{1}{2.3em}{3.1em}}
\renewcommand*\l@subsubsection{\color{\subsubsectiontoccolor}\def\@linkcolor{\subsubsectiontoccolor}\@dottedtocline{1}{3.1em}{3.9em}}
\def\contentsline#1#2#3#4{%
  \ifx\\#4\\%
  \csname l@#1\endcsname{#2}{#3}%
  \else
  \csname l@#1\endcsname{\hyper@linkstart{link}{#4}{#2}\hyper@linkend}{%
    \hyper@linkstart{link}{#4}{#3}\hyper@linkend
  }%
  \fi
}

%% New title format -- 'section' is used by default.
\newcommand{\tocformat}[1]{{\Huge\bf#1}}

\renewcommand\tableofcontents{%
  \tocformat{
    \textcolor{toctitle}{\contentsname}
    \@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}
  }%
  \@starttoc{toc}%
}

分節

[edit | edit source]

這絕對是最複雜的部分。它並不難,因為 \section\subsection\subsubsection 的程式碼幾乎相同。

我們使用 \needspace 來確保在分節命令後不會出現換行符。我們將命令包含在一個組中,在該組中設定字型大小,因為我們需要的是 \baselineskip,它取決於字型大小。

帶星號的命令不會設定計數器(LaTeX 的預設行為)。你可以選擇透過重置計數器來以不同的方式處理帶星號的命令。

我們在列印部分之前使用 \noindent。我們確保使用 \par 命令結束列印部分,以確保後面的文字能夠正確列印。

對於 \subsection,我們使用 mirrors 選項來相應地更改外觀。

為了正確處理 PDF 書籤,我們需要在定義的末尾新增以下幾行。

\phantomsection
\addcontentsline{toc}{section}{\thesection~#1}

最後,僅對於 \section,我們希望它在頁首中列印,因此我們呼叫 \sectionmark 命令。在這裡,我們改變了帶星號命令的行為,使其與原始 LaTeX 版本不同,因為我們定義並使用了 \sectionmarkstar 命令。


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Section style

\renewcommand\section{
  \@ifstar
  \my@sectionstar
  \my@section
}

%% Note: to justify, text width must be set to \textwidth - 2*(inner sep).
\tikzstyle{sectionstyle}=[
  inner sep=5pt,
  text width=\textwidth-10pt,
  left color=sectionfg!100!white,
  right color=sectionfg!50!white,
  rounded corners,
  text=Ivory,
  rectangle
]

\newcommand\my@section[1]{
  \stepcounter{section}
  {\Large\needspace{\baselineskip}}
  \noindent
  \begin{tikzpicture}
    \node[sectionstyle] {\bfseries\Large\thesection\quad#1};
  \end{tikzpicture}
  \par
  \phantomsection
  \addcontentsline{toc}{section}{\thesection~#1}
  \sectionmark{#1}
}

\newcommand{\sectionmarkstar}[1]{\markboth{\MakeUppercase{#1}}{}}

\newcommand\my@sectionstar[1]{
  {\Large\needspace{\baselineskip}}
  \noindent
  \begin{tikzpicture}
    \node[sectionstyle] {\bfseries\Large#1};
  \end{tikzpicture}
  \par
  \phantomsection
  \addcontentsline{toc}{section}{#1}
  \sectionmarkstar{#1}
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Subsection style

\renewcommand\subsection{
  \@ifstar
  \my@subsectionstar
  \my@subsection
}

\tikzstyle{subsectionstyle}=[
  left color=subsectionfg!50!white,
  right color=subsectionfg!100!white,
  text=Ivory,
  ellipse,
  inner sep=5pt
]

\newcommand\my@subsection[1]{
  \stepcounter{subsection}
  {\Large\needspace{\baselineskip}}
  \noindent  
  \begin{tikzpicture}
    \node[subsectionstyle,anchor=west] (number) at (0,0) {\bfseries\Large\thesubsection};
    \if@mirrors
    \node[above right,subsectionfg,anchor=south west] at ($(number.east)+(0.1,-0.1)$) {\large\bfseries#1};
    \node[yscale=-1, scope fading=south, opacity=0.4, above, anchor=south west, subsectionfg] at ($(number.east)+(0.1,0.1)$) {\large\bfseries#1};
    \else
    \node[above right,subsectionfg,anchor=west] at ($(number.east)+(0.1,0)$) {\large\bfseries#1};
    \fi
  \end{tikzpicture}
  \par
  \phantomsection
  \addcontentsline{toc}{subsection}{\thesubsection~#1}
}

\newcommand\my@subsectionstar[1]{
  {\Large\needspace{\baselineskip}}
  \noindent
  \begin{tikzpicture}
    \node[subsectionstyle,anchor=west] (number) at (0,0) {\bfseries\Large\phantom{1}};
    % 
    \if@mirrors
    \node[above right,subsectionfg,anchor=south west] at ($(number.east)+(0.1,-0.1)$) {\large\bfseries#1};
    \node[yscale=-1, scope fading=south, opacity=0.4, above, anchor=south west, subsectionfg] at ($(number.east)+(0.1,0.1)$) {\large\bfseries#1};
    \else
    \node[above right,subsectionfg,anchor=west] at ($(number.east)+(0.1,0)$) {\large\bfseries#1};
    \fi
  \end{tikzpicture}
  \par
  \phantomsection
  \addcontentsline{toc}{subsection}{#1}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Subsubsection style

\renewcommand\subsubsection{
  \@ifstar
  \my@subsubsectionstar
  \my@subsubsection
}

\tikzstyle{subsubsectionstyle}=[
  left color=subsubsectionfg!50!white,
  right color=subsubsectionfg!100!white,
  text=Ivory,
  shape=trapezium,
  inner sep=5pt
]

\newcommand\my@subsubsection[1]{
  \stepcounter{subsubsection}
  \noindent  
  \begin{tikzpicture}
	\node[subsubsectionstyle] (number) {\bfseries\large\thesubsubsection};
	\node[subsubsectionfg, right of=number, anchor=west] {\large\bfseries#1};
  \end{tikzpicture}
  \par
  \phantomsection
  \addcontentsline{toc}{subsubsection}{\thesubsubsection~#1}
}

\newcommand\my@subsubsectionstar[1]{
  \noindent
  \begin{tikzpicture}
	\node[subsubsectionstyle] (number) {\bfseries\large\vphantom{1}};
	\node[subsubsectionfg, right of=number, anchor=west] {\large\bfseries#1};
  \end{tikzpicture}
  \par
  \phantomsection
  \addcontentsline{toc}{subsubsection}{#1}
}

\endinput


註釋和參考文獻

[edit | edit source]


上一個:建立包 索引 下一個:模組化文件
華夏公益教科書