# Latex [數學公式編輯網站](https://latex.codecogs.com/eqneditor/editor.php) [數學公式網站](http://mohu.org/info/symbols/symbols.htm) [教學](https://www.cs.pu.edu.tw/~wckuo/doc/latex123/node6.html) [相關教學](https://texdoc.org/serve/caption/0) ## Installation ### Linux 1. 安裝latex ```shell sudo apt-get install texlive-latex-base ``` 2. 安裝中文環境cjk包 (想像成library) ```shell sudo apt-get install latex-cjk-all ``` 3. 補充安裝.sty 檔案 ```shell sudo apt-get install texlive-latex-extra ``` 4. 如果不想用vim(強烈建議,因爲可以裝逼)的話就用texmaker (想像成IDE) ```shell sudo apt-get install texmaker ``` 5. install texlive-publishers ```sehll sudo apt-get install texlive-publishers ``` 6. 安裝xeletex (想像成gcc或g++那一類的東東) ```shell sudo apt-get install texlive-xetex ``` 7. 最後就是字體啦!!!本篇論文因爲需要用到 __Times New Roman__ 以及 __標楷體__ ,所以就要下載對應的字體,然後呢這時候 __Windows__ 就非常好用了,因爲Windows灌完系統會自動灌一些預設字體(本人到現在發現除了PowerPoint以外,唯二讓我無話可說的地方),所以就從它灌的那顆硬碟幹那些字體(應該在`C:\Windows\System\Fonts\`裏)過來Linux這邊用,所以說這時候Windows是不是很好用啊(簡單來說就是工具人啦!)!但如果覺得這樣很麻煩的話,你不用擔心,如果本人 __繼群大帥哥__ 還在的話,你可以直接跟我要,但是如果我已經畢業了那也只能跟你說抱歉了。那些字體在Windows那邊的名稱分別爲Times New Roman (`TIMES.TTF`,`TIMESBI.TTF`,`TIMESBD.TTF`,`TIMESI.TTF`)、標楷體(`KAIU.TTF`)。拿到這些字體放入`/usr/local/share/fonts/`的目錄中。 ```shell sudo mv TIMES.TTF TIMESBI.TTF TIMESBD.TTF TIMESI.TTF KAIU.TTF /usr/local/share/fonts/ sudo fc-cache -f -v #更新字體 ``` ### overleaf [overleaf字體設字](https://cookeylinux.bluesmile.net/2016/03/overleafcom-cjk.html) ### windows #### 安裝texlive [下載地址](https://tug.org/texlive/acquire-netinstall.html) 解壓縮安裝包 ![](https://i.imgur.com/Dli5VcP.png) 點擊安裝包,進行安裝 ![](https://i.imgur.com/t9QE3Gn.png) ![](https://i.imgur.com/QWyZXkX.png) #### 安裝編輯器 [vscode 下載](https://code.visualstudio.com/download) 在vscode 安裝編寫latex的套件,如果有興趣用vim來進行latex文件的編輯可以來找我討論,畢竟能在終端寫文件比較酷一點哈哈哈!當然所要付出的學習成本也不少,可是如果習慣了就回不去了。但看到大家好像比較能適應vscode,而且往後也可以是用它來寫python,所以還是建議使用vscode吧!啊vscode更細節的部分我就不清楚了,可以問承佑。 #### 下載latex套件 ![](https://i.imgur.com/x1YlSuE.png) #### 調整套件的設定 在 VSCode 界面下按下 F1,然后键入`setjson`。 ![](https://i.imgur.com/s809JIy.png) 接著會跳出設定檔的畫面,並將以下的設定檔輸入即可進行編譯、正向與逆向搜尋 ```json= { "latex-workshop.latex.tools": [ { // 编译工具和命令 "name": "xelatex", "command": "C:/texlive/2022/bin/win32/xelatex", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "-pdf", "%DOCFILE%" ] }, { "name": "pdflatex", "command": "C:/texlive/2022/bin/win32/pdflatex", "args": [ "-synctex=1", "-interaction=nonstopmode", "-file-line-error", "%DOCFILE%" ] }, { "name": "bibtex", "command": "C:/texlive/2022/bin/win32/bibtex", "args": [ "%DOCFILE%" ] } ], "latex-workshop.latex.recipes": [ { "name": "xelatex", "tools": [ "xelatex" ], }, { "name": "pdflatex", "tools": [ "pdflatex" ] }, { "name": "xe->bib->xe->xe", "tools": [ "xelatex", "bibtex", "xelatex", "xelatex" ] }, { "name": "pdf->bib->pdf->pdf", "tools": [ "pdflatex", "bibtex", "pdflatex", "pdflatex" ] } ], "latex-workshop.view.pdf.external.synctex.command": "C:/.../SumatraPDF.exe", "latex-workshop.view.pdf.external.synctex.args": [ "-forward-search", "%TEX%", "%LINE%", "-reuse-instance", "-inverse-search", "\"C:/.../Microsoft VS Code/Code.exe\" \"C:/.../Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"", "%PDF%", ], } ``` ## 圖片 [reference link](https://blog.csdn.net/xovee/article/details/109378160) ## tizk ### 畫流程圖 [reference link](https://zhuanlan.zhihu.com/p/82435856) [reference link](https://blog.csdn.net/weixin_44420912/article/details/86486485) ## vimtex [github](https://github.com/lervag/vimtex) 這個套件必須要有`latexmk`這個套件,所以使用之前必須先下載這個套件。 ```shell= sudo apt install latexmk ``` 且必須設定一些功能才能順利使用`xelatex`進行編譯 ```.latmkrc= $pdf_mode = 5; $dvi_mode = 0; $postscript_mode = 0; ``` ### Map 這個套件有很多的Mapping以下提供它的教學 [reference link](https://ejmastnak.github.io/tutorials/vim-latex/vimtex.html) ## cheat sheet ![](https://i.imgur.com/7Hj90zo.png) ![](https://i.imgur.com/DM2vzPU.png) ## footnote [reference link](https://www.latexstudio.net/archives/51620.html) 如同以下效果 ![](https://i.imgur.com/qjBSSZh.png) ## 頁邊配置 發現使用geometry 宏包可以方便地調整頁邊距 ```tex \usepackage{geometry} \geometry{a4paper,scale=0.8} ``` 上面命令設置了紙張為a4 紙,並且版心佔頁面長度的比例為80%;scale也可以改為ratio,表示版面邊距佔頁面長度的比例。該宏包還可以設置頁面的上下左右邊距,例如: ```tex \geometry{a4paper,left=2cm,right=2cm,top=1cm,bottom=1cm} ``` ## 表格換行 使用: ```tex \usepackage{makecell} ``` 用法: ```tex \makecell[居中情况]{第1行内容 \\ 第2行内容 \\ 第3行内容 ...} ``` ## 表格居中 Method1; ```tex { \centering \begin{tabular} ... \end{tabular} } ``` Method2 ```tex \begin{center} \begin{tabular} ... \end{tabular} \end{center} ``` ## 換行不縮排 ```tex \noindent ``` ## 變更figure的預設名字爲“圖” ```tex \renewcommand{\figurename}{图} ``` ## 頁面置中 ```tex= \vspace*{\fill} \begin{center} \fontsize{24}{18pt} \LARGE 筆記 \\ \end{center} \vspace*{\fill} ``` ## enumerate [參考網站](https://latex-tutorial.com/tutorials/lists/) # 圖 ## 子圖堅排 [參考網站](https://www.cxymm.net/article/cdpxc/109894147) 以上網站還有很多圖片的排列教學 ```latex= \begin{figure}[htbp!] \centering \subfigure[Balance]{ \includegraphics[width=8cm]{pic/Mxrc4anf.png} %\caption{fig1} } % \quad \subfigure[G-Measure]{ \includegraphics[width=8cm]{pic/JmIpjiQ2.png} } \caption{Results for Balance, G-Measure, G-mean, MCC} \label{Fig: O2O_RF_MCC3} \end{figure} ``` 效果如下 ![](https://i.imgur.com/HnOGuZk.png) ## 加入圖片出處 [reference](https://tex.stackexchange.com/questions/102516/note-below-figure-as-long-as-the-figure-all-centered-but-note-left-aligned) ```tex= \begin{figure}[htbp] \centering \centerline{\includegraphics[height=7cm]{pic/rbf_struct.png}} \begin{minipage}{.7\linewidth} \footnotesize \emph{圖片來源:}取自Function approximation using artificial neural networks \end{minipage} \caption{RBF網路架構圖} \label{fig:rbf_network} \end{figure} ``` ![](https://i.imgur.com/464HaQB.png) ## 改用頓號分格 ```tex= \DeclareCaptionLabelSeparator{comma}{、} \captionsetup[figure]{labelsep=comma} ``` 如同以下效果: ![](https://i.imgur.com/rbqJdxR.png) # 問題 ## 目錄標題怪怪 ![](https://i.imgur.com/TQcISjb.png) 問題出在使用錯誤的中文套件包 `ctex` 解決方法 ```tex= \uspackage{xeCJK} ```