xiaolong70701
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
1
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
--- disqus: yueswater --- {%hackmd @themes/orangeheart %} <style> .likecoin-button { position: relative; width: 100%; max-width: 485px; max-height: 240px; margin: 0 auto; } .likecoin-button > div { padding-top: 49.48454%; } .likecoin-button > iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } .markdown-body{ word-wrap:break-word; color:#000; font-family:Optima-Regular,Optima,PingFangSC-light,PingFangTC-light,PingFang SC,Cambria,Cochin,Georgia,Times,Times New Roman,serif; font-size:16px; letter-spacing:0; line-height:1.6;max-width:860px; padding:5px 20px; text-align:left; word-break:break-word; word-spacing:0}.markdown-body p{ color:#000; font-size:16px; line-height:26px; margin:0; padding-bottom:8px; padding-top:8px } .markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6{ color:#000; font-weight:700; margin-bottom:15px; margin-top:30px; padding:0 } .markdown-body h1{ font-size:2.5rem } .markdown-body h2{ border-bottom:2px solid #61679e; font-size:2.1rem } .markdown-body h2 span{ background:#61679e; border-top-left-radius:5px; border-top-right-radius:5px; color:#fff; display:inline-block; font-weight:700; margin-right:0; padding:5px 10px 1px } .markdown-body h3{ font-size:1.8rem } .markdown-body h4{ font-size:1.65rem } .markdown-body h5, .markdown-body h6{ font-size:1.5rem } .markdown-body ol, .markdown-body ul{ color:#000; margin-bottom:8px; margin-top:8px; padding-left:25px } .markdown-body ul{ list-style-type:disc } .markdown-body ul ul{ list-style-type:square } .markdown-body ol{ list-style-type:decimal } .markdown-body li section{ color:#010101;font-weight:500; line-height:26px; margin-bottom:5px; margin-top:5px; text-align:left } .markdown-body blockquote{ overflow-scrolling:touch; background:#eff0f5; border-left:3px solid #61679e !important; color:#6a737d; display:block; font-size:.9em; margin-bottom:10px; margin-top:10px; overflow:auto; padding:5px 10px 5px 20px } .markdown-body blockquote p{ color:#000; line-height:26px;margin:0 } .markdown-body a{ word-wrap:break-word; border-bottom:0 solid #61679e; color:#61679e; font-weight:700; text-decoration:none } .markdown-body a:hover { color: #c0c2d8; /* 設定您想要的 hover 顏色 */ } .markdown-body a:visited { color: #61679e; /* 設定您想要的 visited 顏色 */ } .markdown-body li code, .markdown-body p code{ word-wrap:break-word; background-color:rgba(27,31,35,.05); border-radius:4px; color:#61679e; ont-family:Operator Mono,Consolas,Monaco,Menlo,monospace; font-size:14px; margin:0 2px; padding:2px 4px; word-break:break-all } .markdown-body table{ display:table; text-align:left } .markdown-body tbody{ border:0 } .markdown-body table tr{ background-color:#fff; border:0; border-top:1px solid #ccc } .markdown-body table tr:nth-child(2n){ background-color:#f8f8f8 } .markdown-body table tr td, .markdown-body table tr th{ border:1px solid #ccc; font-size:16px; padding:5px 10px; text-align:left } .markdown-body table tr th{ background-color:#f0f0f0; font-weight:700 } .markdown-body li code, .markdown-body span code{ color:#61679e } .markdown-body mark{ background-color:#61679e; border-radius:2px; border-radius:4px; color:#fff; font-weight:500; margin:0 2px; padding:2px 4px } .markdown-body .anchor{ margin-left:-40px } .octicon-link{ border-radius:3px; color:#fff!important; padding:5px 10px!important } .gallery { display: flex; gap: 16px; justify-content: center; } .gallery-item { width: 300px; border: 1px solid #ddd; border-radius: 8px; overflow: hidden; background-color: #fff; /* box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); */ display: flex; flex-direction: column; align-items: center; } .gallery-item img { width: 100%; height: 180px; object-fit: cover; } .gallery-content { padding: 16px; flex: 1; display: flex; flex-direction: column; justify-content: space-between; width: 100%; } .gallery-title { font-size: 14px; font-weight: bold; margin-bottom: 8px; text-align: center; } .gallery-description { font-size: 14px; color: #666; margin-bottom: 12px; } .gallery-details { display: flex; justify-content: space-between; align-items: center; font-size: 14px; color: #888; margin-bottom: 8px; } .gallery-tag { background-color: #eee; border-radius: 4px; padding: 2px 6px; font-size: 12px; color: #666; } .gallery-duration { font-size: 12px; color: #666; } .gallery-date { font-size: 12px; color: #aaa; text-align: right; } </style> ###### tags: `LaTeX` 相信一定不少人在學生時期或出社會工作之後,都面臨著撰寫報告的地獄需求。不過,經常使用 Microsoft Word、PowerPoint 的人一定會發現,插入圖片並且讓它在正確的位置上似乎是一件很費時的任務,一方面是因為將圖片導入文件後,還要調整大小,且每一張圖片的大小都不相同;另一方面是 Word、PPT 在文字與圖片排列稍顯的不聰明一點。[^1] 這一系列文章介紹的語言——LaTeX,不僅可以解決上述關於圖片排版的問題,更提供了在數學公式、表格、程式碼嵌入、簡報製作等方面的優良功能。 # LaTeX 的前世今生 LaTeX 是一種強大的排版系統,廣泛應用於科學、技術、工程及數學(也就是俗稱的 STEM)領域的文件編輯。LaTeX 的前身是 Donald Knuth 於1978年發明的 TeX 系統。Knuth 是一位著名的計算機科學家,他為了解決當時排版系統的不足,親自設計了 TeX,以便創作高品質的文件和書籍。 然而,TeX 雖然功能強大,但對於一般用戶來說並不友好(必須撰寫許多程式碼、前置設定等)。因此,為了解決這個問題,Leslie Lamport 於1984年在 TeX 的基礎上開發了 LaTeX。LaTeX 簡化了文件編寫的流程,使用者只需關注所輸入的內容,而不必操心具體的排版細節,這正是 LaTeX 最引以為傲的功能:**所得即所見**(What You See Is What You Get)。 # 前置作業:編譯器與編輯器 「工欲善其事、必先利其器。」 從學生時期撰寫撰寫作文,到出社會撰寫公司業務報告,都需要一些硬體工具(例如紙筆、電腦、平板等),以及既有的知識。LaTeX 的撰寫也是一樣,編輯一份 LaTeX 文件需要兩個重要的工具:編譯器和編輯器。這邊簡單解釋一下兩者的差異:編輯器用於編寫和管理 LaTeX 程式碼,提供便捷的編寫環境;編譯器則負責將這些程式碼轉換為最終輸出的文件。 ![圖 1:LaTeX 編譯流程圖](https://i-blog.csdnimg.cn/direct/8b204085b978426b8552a93eb1be5d2c.png#pic_center) 選擇 LaTeX 編譯器時,不同系統的使用者可以選擇適合自己的編譯器,但是請注意:請先安裝編譯器之後再安裝編輯器!如果你是 Windows 使用者,推薦[MikTeX](https://miktex.org/)與[TeXLive](https://tug.org/texlive/),但如果你很不幸地使用搞排擠的 macOS 系統,那麽就建議你使用[MacTeX](https://www.tug.org/mactex/)。 至於編輯器的選擇就沒有那麼多限制,只要你覺得編輯器好看、好用,電腦預設的記事本也可以成為你撰寫 LaTeX 的工具。好用的編輯器大概有[TeXmaker](https://www.xm1math.net/texmaker/)、[TeXstudio](https://www.texstudio.org/)、[Visual Studio Code](https://code.visualstudio.com/)。[^3] 如果你想要擁有跟 Google 文件一樣的共同編輯功能,那麼推薦使用[Overleaf](https://www.overleaf.com/)。Overleaf 是一個完全免費的平台,好處是不用下載編譯器(網站內建),而且可以邀請別人一起編輯、查看原始碼;但是壞處是 Overleaf 時不時就會維修,所以個人建議還是要學一下如何在本機安裝編譯器與編輯器。 # LaTeX 語法概說 在正式開始進入 LaTeX 語法教學之前,我們先來看一下底下的範例。 ```tex !TeX xelatex \documentclass[12pt]{article} \title{My First Document} \author{Author} \date{\today} \begin{document} \maketitle \end{document} ``` 細心的你肯定有發現,LaTeX 的指令是以反斜線(backslash) `\` 開頭的,也就是如果你需要使用一些指令,那麼就必須用 `\` 告訴 LaTeX 編譯器你需要使用該指令,否則電腦無法判讀。常見的 LaTeX 指令符如下: | 符號 | 功能 | | ---- | ---- | | `\` | 下排版命令 | | `%` | 註解 | | `#` | 定義巨集 | | `~` | 產生空白 | | `$` | 進入/離開數學模式 | | `^` | 數學模式中的上標字 | | `_` | 數學模式中的下標字 | | `&` | 分隔符號 | ## 決定美醜的關鍵:參數 我們可以注意到 `\documentclass` 後面有兩個不一樣的東西:一個是 `[12pt]`,另一個則是 `{article}`。這兩個東西有什麼不一樣呢?在 LaTeX 中,參數的傳遞方式有兩種,一種是選擇參數,也就是以方括號 `[我是選擇參數]` 包住的,使用者可以留空,不會影響排版,也可以輸入設定指令調整排版。另一種則是必要參數,以花括號 `{我是必要參數}` 包住,只要使用者沒有輸入內容留空,電腦就不清楚目前需要做什麼[^4]。關於參數的設定,有幾點需要注意的事情: - 不同於Word,LaTeX 文稿中,空一個與多個英文空白的意思是一樣的,LaTeX 會認作一個空白。 - 按下Enter 鍵不代表換行,換行必須要使用雙斜線(`\\`,Windows 使用者可以同時按下 Ctrl 與 Enter 鍵;masOS 使用則可同時按下 ⌘ 與 ↩︎ 鍵),或是以 `\newline`、`\linebreak` 進行換行。 ## 使用指令 LaTeX 的指令是從反斜線後第一個字母開始,到第一個非字母符號為止 (包含空白、標點符號及數字)。因此: `This is my first \LaTeX typesetting example.` 這樣的話,由於空白屬於指令的一部分,因此會印出如下面輸出範例的結果。若要避免上述情況,就必須使用以下三種方法: 1. `This is my first {\LaTeX} typesetting example.` 2. `This is my first \LaTeX{} typesetting example.` 3. `This is my first \LaTeX\ typesetting example.` ```tex % !TeX xelatex \documentclass[12pt]{article} \title{My First Document} \author{Author} \date{\today} \begin{document} \maketitle This is my first \LaTeX typesetting example. This is my first {\LaTeX} typesetting example. This is my first \LaTeX{} typesetting example. This is my first \LaTeX\ typesetting example. \end{document} ``` ## 使用註解 註解符號(`%`) 可以放在一行的任何地方,`%` 之後的文字會被忽略掉,特定的編譯器在註解之後文字會變色。而註解功能最大的好處是,在微調一些參數或設定時,可以使用註解,將更改的地方註解起來或取消註解,並編譯出結果比較前後的差異。 ## 開啟環境 LaTeX 有一種巨集結構,稱為環境(environment),主要是讓作用範圍能 擴大至較大的範圍。所有的環境都起於`\begin{環境名稱}`,止於`\end{環境名稱}`。這兩個指令之間的文稿都會被作用,而且,環境之內還可以套用其他不同的環境。LaTeX 文稿的內文,就是包在一個 ```tex \begin{環境名稱} ... \end{環境名稱} ``` 這個 document 環境當中。以下就是所有 LaTeX 必須具備的文稿大結構: ```tex \documentclass[]{} %這裡是preamble 區 \begin{document} ... \end{document} ``` ## 前言區(preamble) 這裡可以引用巨集(macro),而且會影響整篇文稿的指令,例如一些事先 定義好的指令,想在整篇文稿中使用,就可以置放在 preamble 區。例如: ```tex !TeX xelatex \documentclass[12pt]{article} \usepackage{xcolor} \begin{document} The text will be \textcolor{blue}{blue}. \end{document} ``` ## 章節標題設定 在 LaTeX 的文件裡,章節標題的形成都是由同樣的指令來控制的,這樣有一個好處,臨時插入章節標題及其內文時,我們不必去理會標題編號及目錄的問題,也不必去理會要用什麼字型、及字型大小要多大,LaTeX 會自動計算處理,字型大小也會和內文使用的字型大小互相配合調整,使用者就專心在內文構思、寫作即可。以下由列表來瞭解整個章節結構: | 深度編號 | 指令 | 作用及注意事項 | | -------- | -------- | -------- | | -1 | `part{}` | 部| | 0 | `chapter{}` | 章,在 article 沒有章| | 1 | `section{}` | 節| | 2 | `subsection{}` | 小節| | 3 | `subsubsection{}` | 次小節| | 4 | `paragraph{}` | 段落| | 5 | `subparagraph{}` | 次段落| 你肯定會問:「深度編號是什麼?」要知道背後的原理,還有很長的路要走。所以在這邊我就留下一個伏筆,待後續之分解。 [^1]: 此處的不聰明並不是指「文繞圖」(wrap text around a picture)的功能,而是指圖片時常不會在正確的位置上,容易因為文字的多寡而跑版。 [^3]: 關於 LaTeX 在 VS code 上的設定,可以參考這篇文章:[https://hackmd.io/@DextinChen/VSCode-LaTeX-setting?utm\_source\=preview-mode&utm\_medium=rec](https://hackmd.io/@DextinChen/VSCode-LaTeX-setting?utm_source=preview-mode&utm_medium=rec),裡面有詳盡的解說。 [^4]: 但有時某些指令中,必要參數可以不必填寫,例如 `\date{}`,不填寫的話,則標題頁的日期就不會顯示,而是會留一行空白,直接跳到下一行的作者列。

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully