You are on page 1of 7

GÓI LỆNH titlesec.

sty

Nguyễn Hữu Điển


Khoa Toán - Cơ - Tin học
ĐHKHTN Hà Nội, ĐHQGHN

1 Giới thiệu
Gói lệnh quotchap.sty cho việc làm chương với chú thích bên cạnh. Gói titlesec.sty và
titletoc.sty cho ta cách làm lại các ttiêu đề đoạn, chương và mục lục theo ý muốn. Gói lệnh
được viết bởi Javier Bezos có tại địa chỉ
http://www.ctan.org/tex-archive/macros/latex/contrib/titlesec/
Bạn phải lấy về và đọc hướng dẫn lý giải và tùy chọn của gói lệnh. Tại đây tôi chỉ giới
thiệu một số ví dụ cụ thể cho người dùng mà họ đã làm.

2 Tùy chọn của gói lệnh


Giống như bất cứ gói lệnh nào đưa vào phần đầu

\documentclass{article}
\usepackage[sf,bf,compact,topmarks,calcwidth,pagestyles]{titlesec}
\usepackage{titletoc}
\usepackage[utf8]{vietnam}
\begin{document}

2.1 Định dạng tiêu đề và chương


1. rm sf tt md bf up it sl sc
Đặt lại phông tiêu đề theo family/series/shape. Mặc định là bf.
2. big medium small tiny
Đặt cỡ của tiêu đề. Mặc định là big.
3. raggedleft center raggedright
Sắp xếp tiêu đề căn lề trái phải.
4. \titlelabel{<label-format>}
Định dạng nhãn số của đoạn và chương, ví dụ thêm dấu chấm

\titlelabel{\thetitle.\quad}

4. \titleformat*{<command>}{<format>}
Định dạng lại các lệnh \section, \chapter, ... Ví dụ tiêu đề nghiêng

\titleformat*{\section}{\itshape}

2.2 Lệnh định dạng tổng quát


\titleformat{<command>}[<shape>]{<format>}{<label>}{<sep>}{<before>}[<after>]

• <command> là định nghĩa lại các lệnh là \part, \chapter, \section, \subsection,
\subsubsection, \paragraph hoặc \subparagraph.

1
• <shape>
hang là giá trị mặc định giống như các định dạng lệnh cơ bản.
block tạo tiêu đề thành khối, có thể định dạng lại tiêu đề và hình khung bao quanh
dạng đặc biệt.
display tiêu đề thành một đoạn riêng giống như tiêu đề chương.
runin tiêu đề cùng với nội dung liền nhau.
leftmargin đặt tiêu đề lề trái.
rightmargin đặt tiêu đề lề phải.
drop tiêu đề có thể ngắt được.
wrap giống như drop như khoảng cách giữa tiêu đề văn bản được tính đẹp hơn.
frame tiêu đề có khung.
• <format> định dạng cho cả số và văn bản tiêu đề.
• <label> có thể bỏ trống.
• <sep> Khoảng trrống nhãn tiêu đề và văn bản.
• <before> Khoảng trống trước tiêu đề.
• <after> Khoảng trống sau tiêu đề.

3 Ví dụ định dạng đoạn


Tiếp tục với mục trên bằng
4 Gói lệnh là gì

\titleformat{\section}[block]
{\normalfont\bfseries\filcenter}{\fbox{\itshape\thesection}}{1em}{}
\section[Ví dụ]{Gói lệnh là gì}

5 KẺ KHUNG SỐ
\titleformat{\section}[block]
{\normalfont\bfseries\filright}{\fbox{\itshape\thesection}}{1em}{}
\section[Ví dụ]{KẺ KHUNG SỐ}
PHẦN 6

KẺ KHUNG CẢ TIÊU ĐỀ

\titleformat{\section}[frame]
{\normalfont}
{\filright
\footnotesize
\enspace PHẦN \thesection\enspace}
{8pt}
{\Large\bfseries\filcenter}
\section[Ví dụ]{KẺ KHUNG CẢ TIÊU ĐỀ}

7. Tiêu đề kẻ trên
\titleformat{\section}
{\titlerule
\vspace{.8ex}%
\normalfont\itshape}
{\thesection.}{.5em}{}
\section[Ví dụ]{Tiêu đề kẻ trên}

2
8
Tiêu đề kẻ trên với số
\titleformat{\section}[block]
{\normalfont\sffamily}
{\thesection}{.5em}{\titlerule\\[.8ex]\bfseries}
\section[Ví dụ]{Tiêu đề kẻ trên với số}

9 TIÊU ĐỀ RẤT DÀI CÓ THỂ NGẮT XUỐNG DÒNG


VÀ QUY TÂM VÀO GIỮA

10 TIÊU ĐỀ NGẮN
\titleformat{\section}[block]
{\filcenter\large
\addtolength{\titlewidth}{2pc}%
\titleline*[c]{\titlerule*[.6pc]{\tiny\textbullet}}%
\addvspace{6pt}%
\normalfont\sffamily}
{\thesection}{1em}{}
\titlespacing{\section}
{5pc}{*2}{*2}[5pc]
\section[Ví dụ]{Tiêu đề rất dài có thể ngắt xuống dòng và quy tâm vào giữa}

section 
Đây là ví dụ tiêu đề và nội dung thành một khối

\titleformat{\section}[display]
{\normalfont\fillast}
{\scshape section \oldstylenums{\thesection}}
{1ex minus .1ex}
{\small}
\titlespacing{\section}
{3pc}{*3}{*2}[3pc]
\section[Ví dụ]{Đây là ví dụ tiêu đề và nội dung thành một khối}

PHẦN TIÊU ĐỀ LIỀN ngay với nội dung ở đây. . .

\titleformat{\section}[runin]
{\normalfont\scshape}
{}{0pt}{}
\titlespacing{\section}
{\parindent}{*2}{\wordsep}
\section*{PHẦN TIÊU ĐỀ LIỀN}
ngay với nội dung ở đây\ldots

12. Tiêu đề ở một góc văn bản Dùng soạn thảo văn bản bằng LaTeX là dùng các lệnh để
tuy có hơi dài điều khiển cho ta kết quả cuối cùng sản phẩm chế bản.
Để mở rộng khả năng sử dụng LaTeX và đáp ứng nhu cầu
đa dạng với kết quả chuyên nghiệp, người ta đã thiết kế cho người sử dụng tạo các gói lệnh
dùng chung.

\titleformat{\section}[wrap]

3
{\normalfont\fontseries{b}\selectfont\filright}
{\thesection.}{.5em}{}
\titlespacing{\section}
{12pc}{1.5ex plus .1ex minus .2ex}{1pc}

\section[Ví dụ]{Tiêu đề ở một góc văn bản tuy có hơi dài}

13. Tiêu đề ở một góc ngắn Dùng soạn thảo văn bản bằng LaTeX là dùng các lệnh để
điều khiển cho ta kết quả cuối cùng sản phẩm chế bản. Để
mở rộng khả năng sử dụng LaTeX và đáp ứng nhu cầu đa dạng với kết quả chuyên nghiệp,
người ta đã thiết kế cho người sử dụng tạo các gói lệnh dùng chung.

\titleformat{\section}[wrap]
{\normalfont\fontseries{b}\selectfont\filright}
{\thesection.}{.5em}{}
\titlespacing{\section}
{12pc}{1.5ex plus .1ex minus .2ex}{1pc}
\section[Ví dụ]{Tiêu đề ở một góc ngắn}

§ 14. Tiêu đề chạy liên tục.—Dùng soạn thảo văn bản bằng LaTeX là dùng các lệnh
để điều khiển cho ta kết quả cuối cùng sản phẩm chế bản. Để mở rộng khả năng sử dụng
LaTeX và đáp ứng nhu cầu đa dạng với kết quả chuyên nghiệp, người ta đã thiết kế cho
người sử dụng tạo các gói lệnh dùng chung.

\titleformat{\section}[runin]
{\normalfont\bfseries}
{\S\ \thesection.}{.5em}{}[.---]
\titlespacing{\section}
{\parindent}{1.5ex plus .1ex minus .2ex}{0pt}

\section[Ví dụ]{Tiêu đề chạy liên tục}

Tiêu đề ở Dùng soạn thảo văn bản bằng LaTeX là dùng các lệnh để điều khiển cho ta kết quả cuối
ngoài lề cùng sản phẩm chế bản. Để mở rộng khả năng sử dụng LaTeX và đáp ứng nhu cầu đa dạng
văn bản với kết quả chuyên nghiệp, người ta đã thiết kế cho người sử dụng tạo các gói lệnh dùng
chung.

\titleformat{\section}[leftmargin]
{\normalfont
%\titlerule*[.6em]{\bfseries .}%
\vspace{6pt}%
\sffamily\bfseries\filleft}
{\thesection}{.5em}{}
\titlespacing{\section}
{4pc}{1.5pc plus .1ex minus .2ex}{1pc}

\section*{Tiêu đề ở ngoài lề văn bản}

4 Ví dụ định dạng chương


Ví dụ định dạng chương tương tự

4
CHƯƠNG 5

TIÊU ĐỀ CỦA CHƯƠNG


\titlespacing{\chapter}{0pt}{*4}{*4}
\titleformat{\chapter}[display]
{\normalfont\Large\filcenter\sffamily}
{\titlerule[1pt]%
\vspace{1pt}%
\titlerule
\vspace{1pc}%
\LARGE CHƯƠNG \thechapter}
{1pc}
{\titlerule
\vspace{1pc}%
\Huge}

\chapter[Ví dụ]{TIÊU ĐỀ CỦA CHƯƠNG}

CHƯƠNG VI

TIÊU ĐỀ CỦA CHƯƠNG

\def\thesection{\Roman{chapter}}
\titleformat{\chapter}[display]
{\bfseries\Large}
{\filleft CHƯƠNG \Huge\thechapter}
{4ex}
{\titlerule
\vspace{2ex}%
\filright}
[\vspace{2ex}%
\titlerule]

\chapter[Ví dụ]{TIÊU ĐỀ CỦA CHƯƠNG}

5 Ví dụ định dạng đầy đủ


\documentclass[twoside]{report}
\usepackage[sf,sl,outermarks]{titlesec}

% \chapter, \subsection...: no additional code

5
\titleformat{\section}
{\LARGE\sffamily\slshape}
{\thesection}{1em}{}
\titlespacing{\section}
{-6pc}{3.5ex plus .1ex minus .2ex}{1.5ex minus .1ex}

\titleformat{\paragraph}[leftmargin]
{\sffamily\slshape\filright}
{}{}{}
\titlespacing{\paragraph}
{5pc}{1.5ex minus .1 ex}{1pc}

% 5+1=6, ie, the negative left margin in section

\widenhead{6pc}{0pc}

\renewpagestyle{plain}{}

\newpagestyle{special}[\small\sffamily]{
\headrule
\sethead[\usepage][\textsl{\chaptertitle}][]
{}{\textsl{\chaptertitle}}{\usepage}}

\newpagestyle{main}[\small\sffamily]{
\headrule
\sethead[\usepage][\textsl{\thechapter. \chaptertitle}][]
{}{\textsl{\thesection. \sectiontitle}}{\usepage}}

\pagestyle{special}

\begin{document}

---TOC

\pagestyle{main}

---Body

\pagestyle{special}

---Index
\end{document}

6 Các lớp chuẩn cũ được định nghĩa


Ta định nghĩa các đoạn và chương như chuẩn cũ như sau.

\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titleformat{\section}
{\normalfont\Large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\large\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}
\titleformat{\paragraph}[runin]
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}

6
\titleformat{\subparagraph}[runin]
{\normalfont\normalsize\bfseries}{\thesubparagraph}{1em}{}

\titlespacing*{\chapter} {0pt}{50pt}{40pt}
\titlespacing*{\section} {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{\subsection} {0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\paragraph} {0pt}{3.25ex plus 1ex minus .2ex}{1em}
\titlespacing*{\subparagraph} {\parindent}{3.25ex plus 1ex minus .2ex}{1em}

7 Chương với hình


Ta có thể vẽ hình ở tiêu đề bằng ( gói lệnhPSTricks)

\usepackage[dvips]{color}
\usepackage[rigidchapters,explicit]{titlesec}

\DeclareFixedFont{\chapterfont}{T1}{phv}{bx}{n}{11cm}

\titlespacing{\chapter}{0pt}{0pt}{210pt}
% Most of titles have some depth. The total space is
% a bit larger than the picture box.

\titleformat{\chapter}[block]
{\begin{picture}(330,200)}
{\put(450,80){%
\makebox(0,0)[rb]{%
\chapterfont\textcolor[named]{SkyBlue}{\thechapter}}}
\put(0,230){%
\makebox(0,0)[lb]{%
\Huge\sffamily\underline{Chapter \thechapter}}}}
{0pt}
{\put(0,190){\parbox[t]{300pt}{%
\Huge\sffamily\filright#1}}}
[\end{picture}]

You might also like