【LaTex】在 LaTex 中优雅地插入行内和行间代码
生活随笔
收集整理的這篇文章主要介紹了
【LaTex】在 LaTex 中优雅地插入行内和行间代码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 1. 準備工作
- 1.1 導入依賴
- 1.2 設置代碼樣式(以 Python 為例)
- 2. 行內代碼
- 3. 行間代碼
1. 準備工作
1.1 導入依賴
\usepackage{listings} % 插入代碼用到1.2 設置代碼樣式(以 Python 為例)
% 用來設置附錄中代碼的樣式 \lstset{basicstyle = \sffamily, % 基本代碼風格keywordstyle = \bfseries, % 關鍵字風格commentstyle = \rmfamily\itshape, % 注釋的風格,斜體stringstyle = \ttfamily, % 字符串風格flexiblecolumns, % 別問為什么,加上這個numbers = left, % 行號的位置在左邊showspaces = false, % 是否顯示空格,顯示了有點亂,所以不現實了numberstyle = \zihao{-5}\ttfamily, % 行號的樣式,小五號,tt等寬字體showstringspaces = false,captionpos = t, % 這段代碼的名字所呈現的位置,t指的是top上面frame = lrtb, % 顯示邊框 }\lstdefinestyle{Python}{language = Python, % 語言選Pythonbasicstyle = \zihao{-5}\ttfamily,numberstyle = \zihao{-5}\ttfamily,keywordstyle = \color{blue},keywordstyle = [2] \color{teal},stringstyle = \color{magenta},commentstyle = \color{red}\ttfamily,breaklines = true, % 自動換行,建議不要寫太長的行columns = fixed, % 如果不加這一句,字間距就不固定,很丑,必須加basewidth = 0.5em, }2. 行內代碼
\verb|while(1)|3. 行間代碼
\begin{lstlisting} 代碼寫在這里! \end{lstlisting} 關注公眾號“大學生內卷生存指北” 獲取更多筆記、源碼、學習資源!總結
以上是生活随笔為你收集整理的【LaTex】在 LaTex 中优雅地插入行内和行间代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 适合新手练习的二十套Java项目源码大分
- 下一篇: 理解 Delphi 的类(七) - 认识