Computer >> Hướng Dẫn Máy Tính >  >> Phần Mềm >> Office

Thành Thạo LaTeX & LyX: Mẹo & Thủ Thuật Cần Thiết

Nói 10 lần liên tiếp, nhanh, tôi thách bạn. Dù sao, hôm nay chúng ta tụ tập để tận hưởng tutorial ultra-geeky về việc document nên được viết, styled, formatted, prepared, presented, và tóm lại, viết như thế nào. Bạn có thể cám dỗ dùng office suite và gribble (ghiền viết) công việc trong word processor, nhưng tôi xin bạn, đừng. Có cả thế giới superior alternatives chờ bạn, nếu chỉ willing to take leap of faith (bước nhảy niềm tin) và hurl into the chasm of nerdiness (hư hố nerdiness).

Tuy nhiên, fan office suite sẽ nói LaTeX quá khó và chỉ tốt cho document khoa học. Aha! Well, đó đúng một phần. Có nhiều thứ bạn muốn trong LaTeX, nhưng không instantly apparent. Trong bài này, tôi muốn show common obstacles user Word gần đây có thể gặp và cách bypass nhanh, painless.


Lấy LaTeX của bạn

LaTeX là one true way (cách duy nhất đúng) viết document. Bạn dùng LaTeX từ command line hoặc frontend. Option 2 khuyến khích cho hầu hết. Popular options: LyX và Kile. LyX cross-platform, chạy cả Windows và Linux. Bài này, tôi dùng LyX như text processor, như bạn dùng office suite.

Lưu ý: Tất cả ví dụ based on MY taste (gu tôi), hãy hiểu principle trước khi dùng trick. Ok, dive in, earnestly.

Basics (Cơ bản)

Chèn LaTeX code vào LyX document: Ctrl + L. Thay đổi permanent ảnh hưởng toàn document chèn vào document preamble, một loại template section khai báo major stuff: header, footer, bookmark, color, v.v.

Bây giờ, xem vài trick phổ biến - hoặc annoyances (rắc rối) nếu bạn muốn. Tôi tackle issues normal person gặp khi dùng LaTeX như kỳ vọng document behave. Không thứ tự cụ thể:

Trick 1: Căn bullet/số sang lề trái trang

Mặc định, item indent một tab space. Có thể annoy bạn. No worries, solution cực simple. Trước itemize hoặc enumerate list đầu tiên trong document, thêm snippet code nhỏ. Hoặc dùng Preamble. Cho bullet và số, tương ứng.

\setitemize[0]{leftmargin=XXpt,itemindent=XXpt,labelwidth=XXpt}

\setenumerate[0]{leftmargin=XXpt,itemindent=XXpt,labelwidth=XXpt}

Margin chính xác phụ thuộc needs/style và font. Nhưng bạn hiểu ý. Chơi với giá trị khác xem hiệu ứng. Trong case tôi, như ảnh dưới, setting:

\setitemize[0]{leftmargin=15pt,itemindent=0pt,labelwidth=10pt}

Cũng cần package enumitem; khai báo trong Preamble:

\usepackage{enumitem}

Nếu package chưa cài, cần cài trước. Có thể để LaTeX software handle hoặc manual download/extract vào path đúng. Cá nhân tôi: đừng bother. Để software làm hard work. Ví dụ, Windows, MiKTeX làm giúp:

Trick 2: Footnote đẹp mắt

Nếu muốn footnote align đẹp, đây code làm nó. Ví dụ dưới include giá trị tôi nghĩ best. Dùng artistic judgment và adjust.

\usepackage[hang,splitrule]{footmisc}
\addtolength{\footskip}{0.5cm}
\setlength{\footnotemargin}{0.3cm}
\setlength{\footnotesep}{0.4cm}

Trick 3: Tách title dài

Bạn có thể có section/subsection title kéo dài, làm Table of Contents trông garbled (lộn xộn). Solution đơn giản: chèn newline symbol vào title line tại điểm mong muốn, như sau:

Kết quả:

Trick 4: Độ rộng ảnh

Nếu cần chèn nhiều ảnh, bạn muốn scale graphics để chúng trông giống nhau. Tuy nhiên, nếu ảnh khác width, height, aspect ratio, bạn gặp tricky math. May mắn, LyX cho set image width bằng column/page width percentage, làm việc đơn giản hơn.

Code cho ví dụ 100% Column Width:

\begin{figure}[H]
\caption{image title}
\includegraphics[width=1\columnwidth]{image-file-path}
\end{figure}

Caption optional, tất nhiên.

Trick 5: Padding/Spacing ô table

Nếu cảm thấy default cell padding LaTeX hơi spartan và xấu, bạn đúng. Solution: stretch table để có space hơn quanh item, trông less crowded, dễ đọc. Ví dụ, double cell spacing:

\renewcommand{\arraystretch}{2}

Kết quả:

Trick 6: Tạo page non-standard

Nếu muốn bỏ qua một page khỏi default styling? Cần formatting đặc biệt, extra indentation, màu mới? Để làm vậy, dùng thispagestyle command. Ví dụ, làm page không style:

\thispagestyle{empty}

Hữu ích cho front page, không muốn header, footer, numbering. Command dưới đặt heading lên page, dựa trên definition trong Preamble.

\thispagestyle{headings}

Trick 7: Caption đẹp

Muốn caption fancy, bold declaration, nice wrapping, giống footnote? Sure. Default figure float caption hơi boring, nhưng bạn dễ dàng pimpify (làm sang) với code:

\usepackage{caption}
\captionsetup{labelfont=bf,format=plain,indention=0cm,
justification=raggedright,singlelinecheck=false}

Đây vào Preamble:

Cần package caption để dùng setting này.

Trick 8: Chèn code programming language với syntax highlighting

Đây real hardcore, nhưng bạn sẽ thích. Thay vì manual tạo block text trông như code, dùng package listings cho kết quả excellent, immediate.

listings cung cấp syntax highlighting cho wide range languages, text wrapping, line numbering, cool things. Không thể explain mọi detail, nhưng real-life case:

\lstset{tabsize=2,breaklines=true,numbers=left,basicstyle=
footnotesize,xleftmargin=30pt}
\lstinputlisting[language=C,]{null-pointer.c}

Chúng ta đọc file null-pointer.c, identify là C. Default tab size 2 spaces. Break lines cho code dài. Numbers bên trái, 30 points từ page margin, styled footnote size. Simple? Humble example:

Kết quả cuối:

Trick 9: Watermark (Chữ mờ/Nhãn nước)

Transparent image logo và fancy watermark? No problem. Dễ dàng và flair. Trước hết, dùng package watermark, khai báo trong Preamble.

\usepackage{watermark}

Tiếp, đặt watermark vị trí mong muốn. Dùng \put command chỉ exact location ảnh. Cho best effect, nên low-contrast, transparent image. Ví dụ:

\thiswatermark{\centering \put(0,-660){\includegraphics[width=
\textwidth]{tux.png}}}

Command này đặt watermark dựa trên tux.png, single page, vertical offset 660pt, centered to text width. Bạn có thể wild với vertical/horizontal positioning, scaling. Cũng dùng same watermark all pages nếu thích. Ví dụ tôi không đẹp, nhưng demo concept:

Bạn cũng dùng package draftcopy cho DVI/PS output hoặc pdfdraftcopy cho PDF để đặt DRAFT chéo trang. Ví dụ:

\usepackage{draftcopy}

Trick 10: Khoảng trống ngang và dọc

Bình thường, bạn không nên thay đổi styling page. LaTeX sẽ smartly parcel paragraph và ảnh across page, achieve best fit và clarity, kể cả tăng/giảm line spacing hoặc shift block text.

Vẫn, nếu phải, dùng \vspace{} và \hspace{} tạo artificial gaps trong text flow. Luôn check final output đảm bảo trông như kỳ vọng. Exempli gratia:

\vspace{1cm}

Vertical spacing hữu ích nếu dùng multiple columns và muốn column khác nhau ragged bottom. Kết hợp \raggedbottom và clear page, vspace làm element align với greatest compactness, nhất là nếu image/table break flow.

Trick 11: Article nhiều cột

Nói đến multiple columns, tạo article 2, 3 hoặc nhiều cột dễ dàng. Dùng package multicol. Khai báo Preamble, rồi bất kỳ đâu body, switch giữa single và multiple columns:

\begin{multicols}{<number>}
content goes here as usual ...
\end{multicols}

Bạn alternate giữa single/multiple columns. Ví dụ, muốn span image/table across page, nhưng dùng 2 block text. Nhớ text span left-right trong block, không break vào multi-column section thứ 2 bên dưới.

Mẹo hay nhất: xem source

LyX code vẫn chỉ text. LaTeX, với vài special tag. Bạn luôn mở file trong text editor, examine special declaration bạn vừa làm qua GUI. Vậy nếu wonder gì behind float element, table, formatting cool, just look at source. Giống examine HTML file.

Ví dụ Linux:

Đọc thêm

Resource LaTeX tips hữu ích khác:

LaTeX | Rob Oakes

Kết luận

Đây là thermonuclear geek device, nhưng tôi nghĩ useful. Dù personal experience có thể không dùng cho bạn, nhất là chưa thử LaTeX, tôi hy vọng bài này intrigue (gợi mở) bạn và prompt (thúc đẩy) bạn thử.

Bài học quan trọng hôm nay: LaTeX có thể pimp vào bất kỳ style, đôi khi tự do và elegance hơn office suite điển hình. LaTeX vast và rich, package cho hầu như mọi thứ. Bạn có thể clone baby koala dùng package đúng; nó unto text như repository unto Linux. Cuối cùng, bạn có simple, quick answers cho common issues nảy sinh LaTeX escapades.

Nếu bạn có case khác useful/worthy, hoặc question chưa answered, mail me, có thể có sequel.

Chào.