LaTeXがlistingsパッケージを使用してコードを挿入する場合、コードフォントをMonacoに設定します



When Latex Inserts Code Using Listings Package



documentclass{article} usepackage{listings} usepackage{fontspec} ewfontfamilymonaco{Monaco} egin{document} egin{lstlisting}[language={[ANSI]C}, numbers=left, numberstyle= inymonaco, basicstyle=smallmonaco] #include #include #include #define SIZE 26 int main (int argc, char *argv[]) { int array[SIZE] int i char c for (i = 0 i while ((c = getchar ()) != EOF) { if (isupper (c)) { array[c - 'A']++ } } for (i = 0 i <26 i++) printf ('%c:%5d ', (char) ('A' + i), array[i]) return 0 } end{lstlisting} end{document} Copy code documentclass[UTF-8]{article} usepackage{listings} usepackage{color,xcolor} usepackage{fontspec} usepackage{xeCJK} setmonofont[Mapping={}]{Monaco} % normal display of English quotation marks, equivalent to setting English fonts setsansfont{Monaco} %Set English Fonts Monaco, Consolas, Fantasque Sans Mono setmainfont{Monaco} %Set English font setCJKmainfont{Microsoft Yahei} % Chinese font settings %setCJKsansfont{ } %Set Chinese font %setCJKmonofont{} % set Chinese font definecolor{mygreen}{rgb}{0,0.6,0} definecolor{mygray}{rgb}{0.5,0.5,0.5} definecolor{mymauve}{rgb}{0.58,0,0.82} lstset{ backgroundcolor=color{white}, % choose the background color basicstyle=footnotesizemonaco, % size of fonts used for The code or change to smallmonaco slightly larger Numbers=left, % set the line number Numberstyle= inymonaco, % set the line number font size columns=fullflexible, breaklines=true, % automatic line breaking only at whitespace captionpos=b, % sets the caption-position to bottom tabsize=4, Commentstyle=color{mygreen}, % set the annotation color escapeinside={\%*}{*)}, % if you want to add LaTeX within your code Keywordstyle=color{blue}, % set the keyword color stringstyle=color{mymauve}monaco, % string literal style Frame=single, % set with border rulesepcolor=color{red!20!green!20!blue!20}, % identifierstyle=color{red}, language=c++, } egin{document} egin{lstlisting} inline int gcd(int a, int b) { // If a log max(a, b)) return b==0?a:gcd(b,a%b) } inline int lcm(int a, int b) { return a/gcd(a,b)*b } end{lstlisting} end{document} Copy code