日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

latex的基本使用

發布時間:2025/3/15 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 latex的基本使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

LaTeX使用

  • LaTeX使用
    • 基本使用
    • 源文件的基本結構
    • 中文處理辦法
    • 字體字號設置
    • 文章基本結構
    • 特殊字符處理
    • 圖片的使用
    • 表格的使用Texstduio的導入表格功能會更快
    • 浮動體的使用
    • 數學公式初步
    • 矩陣的使用TexStudio里面的矩陣模板功能
    • 參考文獻使用BibTex
    • 定義自己的命令

基本使用

  • sublime使用latex格式來編輯文件,使用command+B來編譯文件,這時候通過skim來瀏覽生成的PDF文件。
  • 終端里面通過使用latex demo.tex來編譯latex生成包括demo.dvi在內的許多文件,這個時候用dvipdfmk demo.dvi命令轉成PDF。
  • 終端里面通過使用xelatex demo.tex直接生成PDF文件。還支持中文
    支持中文需要xelatex,utf-8編碼,導入ctex包
  • 使用TexStudio來使用Latex

源文件的基本結構

  • Latex里面有文稿區,正文區
  • Latex里面不用顯示的內容默認用注釋而不是刪除
  • \后面跟的都是關鍵字
  • 一個$包圍表示行內數學公式
  • 兩個$包圍表示行間數學公式
  • 文檔類里面有book,report,letter,ctexreport,ctexbook等文檔類
%導言區 \documentclass{article} %book,report,letter \usepackage{ctex} \title{Latex Introduction} \author{Shu Kai} \date{\today} %文稿區 \begin{document}\maketitle你好 \LaTeX.Here is a formula$f(x)=x^2+2x+1$Here is an another formula$$f(x)=2x$$which $x$ denote independent variable. \end{document}

中文處理辦法

  • 命令行中使用texdoc ctex可以查看ctex的使用方法,或者使用texdoc lshort-zh來查看latex的簡短的中文介紹。
  • 使用\heiti,\kaishu來選擇不同的字體
  • 使用eqution來產生具有序號的數學公式
  • 使用\newcommand\yourcmd{xxxcmd}來定義自己的command
  • 使用ctex開頭的文檔類,可以不用引入ctex包
%導言區 \documentclass{ctexart} %book,report,letter %\usepackage{ctex} %or use \documentclass{ctexart} \title{Latex Introduction} \newcommand\degree{^\circ} \author{\heiti 舒凱} \date{\today} %文稿區 \begin{document}\maketitle你好 \LaTeX.$C=90\degree$\begin{equation}AB=BC=CA\end{equation} \end{document}

字體字號設置

下圖是Latex的字體屬性

* 字體族,對于latex中的字體可以使用不同的字體族,比如說有羅馬字體,san serif字體(無襯線字體),typerwriter字體。
* 對于字體的使用可以用命令或者用定義。對于命令有一個括號作為限定范圍,對于定義可以有括號也可以沒有括號,沒有括號表示接下去的內容全部是該字體。
* 我們可以在引言區用newcommand設置自己的字體。

\documentclass{article} \usepackage{ctex} \newcommand{\myfont}{\textbf{\textsf{ss}}} \begin{document}%字體族設計 羅馬字體 無襯線字體 打印機字體\textrm{Roman Family} \textsf{Sans Serif Family} \texttt{TypeWriter Family}%以下的命令表示后續字體的字體族\rmfamily{Roman Family} \sffamily{Sans Serif Family} \ttfamily{TypeWriter Family}%字體系列設置(粗細,寬度)\textmd{Medium Series} \textbf{BoldFace Series}%字體形狀(直立,斜體,偽斜體,小型大寫)\textup{Upright Shape} \textit{Italic Shape}\textsl{Slanted Shape} \textsc{Small Caps Shape}%中文字體{\songti 宋體} {\heiti 黑體} {\fangsong 仿宋} {\kaishu 楷書}%字體大小設置{\tiny Hello}\\{\scriptsize Hello}\\ {\footnotesize Hello}\\{\small Hello}\\{\normalsize Hello}\\{\large Hello}\\{\Large Hello}\\{\LARGE Hello}\\{\huge Hello}\\{\Huge Hello}\\%中文字號設置\zihao{5} 你好\myfont\end{document}

文章基本結構

  • 對于article類的文檔來說里面有section,subsection,subsubsection等等命令。對于book類的文檔來說,有chapter,section等,此時subsection和subsubsection等等命令就不能發揮作用
  • 可以在文檔區也就是正文區的前面使用tableofcontents這個命令
  • 利用好引言區,盡量在引言區里面設置好格式。
\documentclass{book} \usepackage{ctex} \begin{document}\tableofcontents\section{引言}\section{摘要}\section{實驗}\subsection{實驗}\subsubsection{圖表}\chapter{章節}\section{引言}\section{摘要}\section{實驗}\subsection{實驗}\subsubsection{圖表} \end{document}

特殊字符處理

\documentclass{book} \usepackage{ctex} \usepackage{xltxtra} \usepackage{texnames} \usepackage{mflogo} \begin{document}\section{空白字符}%空行分段,多個空行等于一個空行%自動縮進,絕對不能使用空格代替%英文中多個空格為一個空格,中文中空格無效%漢字與其它字符的間距會自動由XeLeTex自動處理%禁止使用中文全角空格Are you OK!我愛 你!Do you love me !滾%1em(相當于字體中M的寬度)a\quad b%2ema\qquad b%約為1/6個ema\,b a\thinspace b%0.5ema\enspace b%空格a\ b%硬空格 不能分割的空格a~b%1pc=12pt=4.218mma\kern 1pc ba\kern -1em ba\hskip 1em b%根據參數留出空白a\hspace{35pt}b%根據xyz的寬度得到占位寬度的空白a\hphantom{xyz}b%彈性寬度a\hfill b\section{\LaTeX 控制符}%雙反斜杠表示換行,所以要顯示反斜杠需要用\textbackslash\# \$ \% \{ \} \~{} \_{} \^{} \textbackslash \&\section{排版符}\S \P \dag \ddag \copyright \pounds\section{\TeX 標志符號}%基本符號\TeX \LaTeX \LaTeXe%XeLaTex符號,使用xltxtra宏包\XeLaTeX%texnames宏包提供\AmSTeX{} \AmS-\LaTeX{}\BibTeX{} \LuaTeX{}%由mflogo提供\METAFONT{} \MF{} \MP{}\section{引號}` ' `` '' ``你好''\section{連字符}- -- ---\section{非英文字符}\oe \OE \ae \AE \aa \AA \o \O \l \L \ss \SS !` ?`\section{重音符號}\`o \'o \^o \' 'o \~o \=o \.o \u{o} \v{o} \H{o} \r{o} \t{o} \b{o}\c{o} \d{o}\section{實驗}\subsubsection{圖表} \end{document}

效果輸出:

圖片的使用

  • 需要在導言區里面導入graphicx這個包
  • 插入圖片的時候,使用以下命令,\includegraphics[<選項>]{文件名}
  • 支持以下格式的圖片 EPS,PDF,PNG,JPEG,BMP,在導入圖片的時候可以不用加后綴名。
  • 選項有scale,width,height,angle等選項,而且支持相對值
\documentclass{article} \usepackage{ctex} %導言區 \usepackage{graphicx} %語法 \includegraphics[<選項>]{文件名} %格式 EPS,PDF,PNG,JPEG,BMP \usepackage{graphicx} \graphicspath{{figures/},{pics/}} %圖片在當前目錄下的figures目錄%正文區(文稿區) \begin{document}\LaTeX{} 中的插圖\includegraphics{1.png}\includegraphics{2.png}\includegraphics{3.png}\includegraphics[scale=0.3]{1.png}\includegraphics[scale=0.5]{2.png}\includegraphics[scale=0.8]{3.png}\includegraphics[width=1cm]{1.png}\includegraphics[width=2cm]{2.png}\includegraphics[width=3cm]{3.png}\includegraphics[height=1cm]{1.png}\includegraphics[height=2cm]{2.png}\includegraphics[height=3cm]{3.png}\includegraphics[width=0.1\textwidth]{1.png}\includegraphics[width=0.2\textwidth]{2.png}\includegraphics[width=0.3\textwidth]{3.png}\includegraphics[height=0.1\textheight]{1.png}\includegraphics[height=0.2\textheight]{2.png}\includegraphics[height=0.3\textheight]{3.png}\includegraphics[angle=-45,width=0.2\textwidth]{1.png}\includegraphics[width=0.2\textwidth]{2.png}\includegraphics[angle=45,width=0.2\textwidth]{3.png} \end{document}

表格的使用(Texstduio的導入表格功能會更快)

  • 在begin和end里面使用tabular可以創建表格
  • l,c,r 左,中,右;p指示寬度,不夠就換行
  • \\表示換行
  • \hline表示行線,可以有多個疊加
  • |是豎線,可以有多個疊加
\documentclass{article} \usepackage{ctex}%正文區(文稿區) \begin{document}\LaTeX{} 中的表格\begin{tabular}{l|c|c|p{1.5cm}|r} %l,c,r 左,中,右;p指示寬度,不夠就換行\hline %使用兩個\hline表示雙橫線姓名 & 語文 & 數學 & 英語 & 備注 \\ % \\表示換行\hline 張三 & 90 & 86 & 93 & 優秀 \\\hline李四 & 60 & 70 & 80 &\\\hline王五 & 50 & 80 & 66 &\\\hline\end{tabular}\end{document}

浮動體的使用

  • 浮動體可以實現靈活分頁,比如figure,table(避免無法分割的內容產生的頁面的空白)
  • 給圖表添加標題
  • 交叉引用
  • 允許位置的參數,h(here),表示此處,代碼所在的上下文位置;t(top)代碼所在頁面或之后頁面的頂部;b(bottom)代碼所在頁面或之后頁面的底部;p(page)獨立頁面——浮動頁面
  • 標題控制,caption,bicaption等宏包
  • 并排與子圖表 subcaption,subfig,floatrow等宏包
  • 繞排 picinpar,wrapfig等宏包
\documentclass{article} \usepackage{ctex} \usepackage{graphicx} \graphicspath{{figures/}} %正文區(文稿區) \begin{document}\LaTeX{} 中的圖片,如圖\ref{天線} 所示%交叉引用\begin{figure}[htbp] %允許位置\centering\includegraphics[scale=0.3]{1}\caption{天線衰減圖}\label{天線}\end{figure}以下是2014年我們班的成績,如表格\ref{grade}所示\begin{table}[h]\centering\caption{成績單}\label{grade}\begin{tabular}{l|c|c|p{1.5cm}|r} %l,c,r 左,中,右;p指示寬度,不夠就換行\hline %使用兩個\hline表示雙橫線姓名 & 語文 & 數學 & 英語 & 備注 \\ % \\表示換行\hline 張三 & 90 & 86 & 93 & 優秀 \\\hline李四 & 60 & 70 & 80 &\\\hline王五 & 50 & 80 & 66 &\\\hline\end{tabular}\end{table} \end{document}

數學公式初步

  • 行內數學用,$
  • 希臘字母用相應的發音
  • 注意交叉引用
  • \frac{}{}用來表示分式
\documentclass{article} \usepackage{ctex} \usepackage{graphicx} \graphicspath{{figures/}} %正文區(文稿區) \begin{document} \section{行內公式} \subsection{美元符號} 交換公式是$a+b=b+a$所示 \subsection{小括號} 交換公式是\(a+b=b+a\)所示 \subsection{math環境} 交換公式是\begin{math}a+b=b+a\end{math}所示 \section{上標} $a^2$ \section{下標} $a_2$ \section{希臘字母} $\alpha$ $\beta$ $\gamma$ $\epsilon$ $\pi$ $\omega$ $\Gamma$ $\Delta$ $\Theta$ $\Pi$ $\Omega$ \section{數學函數} $\log$ $\sin$ $\cos$ $\arcsin$ $\arccos$ $\ln$ $\sin^2 x+\cos^2 x=1$ $y=\sin^{-1} x$ $y=\sqrt{2}$ $y=\sqrt[4]{5x}$ \section{分式} 體積大約是原來的$3/4$ 體積大約是原來的$\frac{5}{100}$ \section{行間公式} \subsection{美元符號} 交換律是 $$a+b=b+a$$$$1+2=2+1=3$$ \subsection{中括號} \[a+b=b+a\] 如 \[1+2=2+1=3\] \subsection{displaymath環境} \begin{displaymath}1+2=2+1=3 \end{displaymath} \subsection{自動編號公式equation環境} 交換律見式\ref{eq:commutative} \begin{equation}a+b=b+a \label{eq:commutative} \end{equation} 公式的編號與交叉引用是自動實現的,大家在排版中,要習慣采用自動化的方式處理諸如圖,表,公式的編號與交叉引用。 \end{document}

矩陣的使用(TexStudio里面的矩陣模板功能)

參考文獻(使用BibTex)

一次管理,一次使用,thebibliography環境(不推薦),推薦使用BibTex文件把文獻單獨管理,方便后續使用

\documentclass{article} \usepackage{ctex}%正文區(文稿區) \begin{document} %一次管理,一次使用, %參考文獻格式 %\begin{thebibliography}{widestlabel} % \bibitem[記號]{引用標志}文獻條目1 % \bibitem[記號]{引用標志}文獻條目2 % ... %\end{thebibliography} %其中文獻條目包括:作者,題目,出版社,年代,版本,頁碼等 %引用文章的使用采用: \cite{引用標志1,引用標志2} \end{document}
  • 自己編輯一個bib文件,然后進行引用,或者用google學術搜索,然后點擊引用的按鈕,選擇BibLatex的格式

下面是一個Bib文件

@BOOK{mittebach2004, title={The {{\LaTeX}} Companion}, publisher = {Addison-Wesley}, year={2004}, author={Frank Mittelbach and Michel Goossens}, series={Tools and Techniques for Computer Typesetting}, address={Boston}, edition={Second} } @article{comaniciu2003kernel,title={Kernel-based object tracking},author={Comaniciu, Dorin and Ramesh, Visvanathan and Meer, Peter},journal={IEEE Transactions on pattern analysis and machine intelligence},volume={25},number={5},pages={564--577},year={2003},publisher={IEEE} }

然后引入該文件,并在相應的地方進行引用

\documentclass{article} \usepackage{ctex} \bibliographystyle{plain} %plain unsrt alpha abbrv %正文區(文稿區) \begin{document} %一次管理,一次使用, %參考文獻格式 %\begin{thebibliography}{widestlabel} % \bibitem[記號]{引用標志}文獻條目1 % \bibitem[記號]{引用標志}文獻條目2 % ... %\end{thebibliography} %其中文獻條目包括:作者,題目,出版社,年代,版本,頁碼等 %引用文章的使用采用: \cite{引用標志1,引用標志2} \bibliography{literacy} \cite{mittebach2004} \cite{comaniciu2003kernel} \end{document}

定義自己的命令

  • 使用newcommand命令來定義自己的命令
  • 可以在方括號里面設置默認參數,然后默認參數在花括號里面放在第一個
\documentclass{article} \usepackage{ctex} \newcommand\PRC{Public of \emph{China}} %最多有9個#的參數 \newcommand\loves[2]{#1 喜歡 #2} \newcommand\hatedby[2]{#1 不受 #2 喜歡} %默認參數,放第一個位置 \newcommand\love[3][喜歡]{#2#1#3} %正文區(文稿區) \begin{document} \PRC\loves{貓}{魚}\hatedby{狗}{貓}\love{豬}{喜歡}{狗} \end{document} 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的latex的基本使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。