Latex 學習日記
  • Latex 小筆記
  • Latex 安裝
  • WinEdt建立快速巨集
  • E501範例文件
  • JabRef使用
  • 有用的網站
  • Package
    • xeCJK-中文輸入必備
    • AMS-Latex 數學式必備
    • Appendix-簡便附錄教學
    • listings- Highlight程式碼
    • subcaption-圖片編排
    • placeins-圖片以section分段
  • error
    • 解決PDF不能自動關掉問題
Powered by GitBook
On this page
  1. Package

listings- Highlight程式碼

\documentclass{report}
\usepackage{listings}
\usepackage{xcolor}
\definecolor{Blue}{rgb}{0,0,1}
\definecolor{Green}{rgb}{0,0.5,0}
\definecolor{Red}{rgb}{0.64,0.08,0.08}
\lstset{
    language=C++,
    captionpos=b,                       % 讓Caption在Bottom的位置
    numbers=left,                       % 程式碼行號
    frame=lines,
    showstringspaces=false,             % "不"標註空格
    escapeinside={(*@}{@*)},            % 脫逃字元
    commentstyle=\color{Green},         % Comment顏色
    keywordstyle=\color{Blue},          % Keyword顏色
    stringstyle=\color{Red},            % String顏色
    basicstyle=\ttfamily\small,         % 字型
}


\begin{document}

\begin{lstlisting}[language=C++, caption={This is caption}]
#include <iostream>
int main()
{
    // Print Hello (*@Test escapeinside@*)
    std::cout << "Hello, world!" << std::endl;
    return 0;
}
\end{lstlisting}


\end{document}
PreviousAppendix-簡便附錄教學Nextsubcaption-圖片編排

Last updated 7 years ago