LaTex中文article模板(支持代码、数学、TikZ)

代码

请使用XeLatex编译

main.tex

documentclass{article}
usepackage{ctex}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 页面设置
usepackage{geometry}
geometry{a4paper,scale=0.8}
%usepackage{fontspec}
%setmonofont{Consolas}
usepackage{chngpage}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 表格
usepackage{diagbox}
% 超链接
usepackage{hyperref}
hypersetup{hidelinks}
% 图片
usepackage{graphicx}
usepackage{subfigure} % subfigure[]{}
usepackage{caption} % caption*{}
% 浮动
usepackage{float} % [H]
% 列表
usepackage{enumerate}
% pandoc markdown转latex

ewcommand{	ightlist}{setlength{itemsep}{0pt}setlength{parskip}{0pt}}
usepackage{longtable}
usepackage{booktabs}% 	oprule, midrule, ottomrule

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 数学
usepackage{mathrsfs} % mathscr
usepackage{amssymb,amsfonts,amsmath,amsthm,mathtools}
usepackage{xcolor}
usepackage{mdframed}

mdfdefinestyle{shadeStyle}{backgroundcolor=gray!10,linewidth=0pt,innerleftmargin=1ex,innertopmargin=-0.5ex}

	heoremstyle{plain}

ewmdtheoremenv[style=shadeStyle]{theorem}{定理}[section]

ewmdtheoremenv[style=shadeStyle]{lemma}[theorem]{引理}

ewmdtheoremenv[style=shadeStyle]{proposition}[theorem]{命题}

ewmdtheoremenv[style=shadeStyle]{corollary}[theorem]{推论}

	heoremstyle{definition}

ewtheorem{definition}[theorem]{定义}

ewtheorem{exercise}[theorem]{习题}

ewtheorem{question}[theorem]{问题}

ewtheorem{example}[theorem]{例}

	heoremstyle{remark}

ewtheorem{remark}[theorem]{注}

ewtheorem{notation}[theorem]{记号}

ewtheorem{summary}[theorem]{总结}

swapnumbers

ewcommand{
ameOfIt}{}
% customized theorem
	heoremstyle{plain}

ewmdtheoremenv[style=shadeStyle]{custhm}[theorem]{
ameOfIt}

ewenvironment{mytheorem}[1]{
enewcommand{
ameOfIt}{#1}egin{custhm}}{end{custhm}}
% customized definition
	heoremstyle{definition}

ewtheorem{cusdef}[theorem]{
ameOfIt}

ewenvironment{mydefinition}[1]{
enewcommand{
ameOfIt}{#1}egin{cusdef}}{end{cusdef}}
% customized remark
	heoremstyle{remark}

ewtheorem{cusrmk}[theorem]{
ameOfIt}

ewenvironment{myremark}[1]{
enewcommand{
ameOfIt}{#1}egin{cusrmk}}{end{cusrmk}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 代码
usepackage{listings}
%usepackage{xcolor}

lstset{
	%language=Octave,
	numbers=left,
	numberstyle=small,
	stepnumber=1,	% the step between two line-numbers. If it's 1, each line will be numbered
  	numbersep=5pt,	% how far the line-numbers are from the code
  	backgroundcolor=color{white},	% You must add usepackage{color}
  	showspaces=false,	% show spaces adding particular underscores
  	showstringspaces=false,	% underline spaces within strings
  	showtabs=false,	% show tabs within strings adding particular underscores
  	frame=shadowbox,	% single / shadowbox
  	%rulecolor=color{black},	% if not set, the frame-color may be changed on line-breaks within not-black text (e.g. commens (green here))
  	rulesepcolor=color{red!20!green!20!blue!20},
  	tabsize=2,	% sets default tabsize to 2 spaces
  	captionpos=b,	% sets the caption-position to bottom
  	breaklines=true,	% sets automatic line breaking
  	breakatwhitespace=false,	% sets if automatic breaks should only happen at whitespace
  	title=lstname,	% show the filename of files included with lstinputlisting; also try caption instead of title
	basicstyle=	tfamily,
  	%keywordstyle=color{red},
  	commentstyle=color{grey},
  	%stringstyle=color{mauve},
  	escapeinside={\%*}{*)},	% if you want to add LaTeX within your code
  	morekeywords={*,...}	% if you want to add more keywords to the set
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 算法/伪代码
usepackage{algorithm}
usepackage{algorithmicx}
usepackage{algpseudocode}

floatname{algorithm}{算法}

enewcommand{algorithmicrequire}{	extbf{输入:}}

enewcommand{algorithmicensure}{	extbf{输出:}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%TikZ
usepackage{tikz}
usepackage{mathdots}
usepackage{yhmath}
usepackage{cancel}
usepackage{color}
usepackage{siunitx}
usepackage{array}
usepackage{multirow}
%usepackage{gensymb}
usepackage{tabularx}
usetikzlibrary{fadings}
usetikzlibrary{patterns}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	itle{中文article模板}
author{maoruimas}
%date{}
setlength{parindent}{0pt} % 首行不缩进

egin{document}

maketitle
% 正文
input{body}

end{document}

body.tex

请使用XeLaTeX编译. 推荐url{https://www.overleaf.com/}.

section{表格}
egin{table}[H]
centering
egin{tabular}{c|ccccccc}
diagbox[height=2em]{$p$}{$k$} & 0 & 1 & 2 & 3 & 4 \
hline
0 & 1	& 0	& 0	& 0	& 0	\
1 & 0	& 1	& 0	& 0	& 0	\
2 & 0	& 1	& 1	& 0	& 0	\
3 & 0	& 2	& 3	& 1	& 0	\
4 & 0	& 6	& 11	& 6	& 1	\
end{tabular}
caption*{斯特林数$s(p,k)$}
end{table}

section{多图并列}
egin{figure}[H]
    centering
    subfigure{
        egin{minipage}[t]{0.3linewidth}
        centering
        includegraphics[width=linewidth]{y-x.png}
        caption*{$y=dfrac {kappa left( 0
ight) }{2}x^{2}$}
        end{minipage}
    }
    subfigure{
        egin{minipage}[t]{0.3linewidth}
        centering
        includegraphics[width=linewidth]{z-x.png}
        caption*{$z=dfrac {kappa left( 0
ight) 	au left( 0
ight) }{6}x^{3}$}
        end{minipage}
    }
    subfigure{
        egin{minipage}[t]{0.3linewidth}
        centering
        includegraphics[width=linewidth]{z-y.png}
        caption*{$z^{2}=dfrac {2}{9}dfrac {	au ^{2}left( 0
ight) }{kappa left( 0
ight) }y^{3}$}
        end{minipage}
    }
end{figure}

section{数学}
egin{definition}
设$mathbb{I}_{K}$是整体域$K$的Idele群, 定义$K$的	extbf{1-Idele群}为$mathbb{I}^{1}_{K} = {xin mathbb{I}_{K}||x|=1}$.
end{definition}
egin{theorem}label{ik}
$K^{	imes }$在$mathbb{I}^{1}_{K}$中离散, 且$mathbb{I}^{1}_{K} /K^{	imes }$紧.
end{theorem}
egin{remark}
$mathbb{I}_{K} /K^{	imes }$不一定紧.
end{remark}
egin{mytheorem}{良序基本定理}[自定义定理格式]
任意良序集与某个序数同构.
end{mytheorem}
egin{proof}[定理
ef{ik}的证明]
blabla.
end{proof}

section{代码}
egin{lstlisting}[language={C++}]
int powmod(int a, int b, int m) {
    int res = 1;
    while (b > 0) {
        if (b & 1) {
            res = (res * a) % m;
        }
        a = (a * a) % m;
        b >>= 1;
    }
    return res;
}
end{lstlisting}

section{算法}
egin{algorithm}
caption{示例}
egin{algorithmic}[1] %行号
Function {MergerSort}{$Array, left, right$}
State $result gets 0$
If {$left < right$}
State $middle gets (left + right) / 2$
State $result gets result +$ Call{MergerSort}{$Array, left, middle$}
State $result gets result +$ Call{MergerSort}{$Array, middle, right$}
State $result gets result +$ Call{Merger}{$Array,left,middle,right$}
EndIf
State Return{$result$}
EndFunction
end{algorithmic}
end{algorithm}

section{TikZ}
推荐使用url{https://www.mathcha.io}绘图.
	ikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        
egin{center}
egin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
draw  [draw opacity=0][dash pattern={on 4.5pt off 4.5pt}] (250,159.56) .. controls (250,159.52) and (250,159.49) .. (250,159.46) .. controls (250,148.71) and (292.53,140) .. (345,140) .. controls (397.47,140) and (440,148.71) .. (440,159.46) .. controls (440,159.5) and (440,159.53) .. (440,159.57) -- (345,159.46) -- cycle ; draw  [color={rgb, 255:red, 0; green, 0; blue, 0 }  ,draw opacity=1 ][dash pattern={on 4.5pt off 4.5pt}] (250,159.56) .. controls (250,159.52) and (250,159.49) .. (250,159.46) .. controls (250,148.71) and (292.53,140) .. (345,140) .. controls (397.47,140) and (440,148.71) .. (440,159.46) .. controls (440,159.5) and (440,159.53) .. (440,159.57) ;
draw  [draw opacity=0] (440,159.36) .. controls (440,159.39) and (440,159.42) .. (440,159.46) .. controls (440,170.2) and (397.47,178.91) .. (345,178.91) .. controls (292.53,178.91) and (250,170.2) .. (250,159.46) .. controls (250,159.42) and (250,159.38) .. (250,159.34) -- (345,159.46) -- cycle ; draw  [color={rgb, 255:red, 0; green, 0; blue, 0 }  ,draw opacity=1 ] (440,159.36) .. controls (440,159.39) and (440,159.42) .. (440,159.46) .. controls (440,170.2) and (397.47,178.91) .. (345,178.91) .. controls (292.53,178.91) and (250,170.2) .. (250,159.46) .. controls (250,159.42) and (250,159.38) .. (250,159.34) ;
draw  [draw opacity=0][dash pattern={on 4.5pt off 4.5pt}] (256.4,189.71) .. controls (252.35,179.27) and (250.09,167.94) .. (250,156.09) -- (345,155.36) -- cycle ; draw  [dash pattern={on 4.5pt off 4.5pt}] (256.4,189.71) .. controls (252.35,179.27) and (250.09,167.94) .. (250,156.09) ;
draw  [draw opacity=0] (250.11,160.04) .. controls (250.04,158.49) and (250,156.93) .. (250,155.36) .. controls (250,102.9) and (292.53,60.36) .. (345,60.36) .. controls (397.47,60.36) and (440,102.9) .. (440,155.36) .. controls (440,157.58) and (439.92,159.78) .. (439.77,161.96) -- (345,155.36) -- cycle ; draw   (250.11,160.04) .. controls (250.04,158.49) and (250,156.93) .. (250,155.36) .. controls (250,102.9) and (292.53,60.36) .. (345,60.36) .. controls (397.47,60.36) and (440,102.9) .. (440,155.36) .. controls (440,157.58) and (439.92,159.78) .. (439.77,161.96) ;
draw  [draw opacity=0] (433.56,189.39) .. controls (419.82,224.94) and (385.31,250.15) .. (344.92,250.15) .. controls (304.64,250.15) and (270.22,225.09) .. (256.4,189.71) -- (344.92,155.15) -- cycle ; draw   (433.56,189.39) .. controls (419.82,224.94) and (385.31,250.15) .. (344.92,250.15) .. controls (304.64,250.15) and (270.22,225.09) .. (256.4,189.71) ;
draw  [draw opacity=0][dash pattern={on 4.5pt off 4.5pt}] (440,156.03) .. controls (439.92,167.62) and (437.76,178.72) .. (433.88,188.97) -- (345,155.36) -- cycle ; draw  [dash pattern={on 4.5pt off 4.5pt}] (440,156.03) .. controls (439.92,167.62) and (437.76,178.72) .. (433.88,188.97) ;
draw    (247,130) -- (100,190) -- (443,190) -- (590,130) -- (437,130.67) ;
draw    (247,130) -- (253.67,130.67) ;
draw  [dash pattern={on 4.5pt off 4.5pt}]  (253.67,130.67) -- (437,130.67) ;
draw  [dash pattern={on 4.5pt off 4.5pt}]  (345,60) -- (400.33,104.67) ;
draw    (400.33,104.67) -- (470,160) ;
draw  [draw opacity=0][fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=1 ] (467.5,160) .. controls (467.5,158.62) and (468.62,157.5) .. (470,157.5) .. controls (471.38,157.5) and (472.5,158.62) .. (472.5,160) .. controls (472.5,161.38) and (471.38,162.5) .. (470,162.5) .. controls (468.62,162.5) and (467.5,161.38) .. (467.5,160) -- cycle ;
draw  [draw opacity=0][fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=1 ] (342.5,159.46) .. controls (342.5,158.08) and (343.62,156.96) .. (345,156.96) .. controls (346.38,156.96) and (347.5,158.08) .. (347.5,159.46) .. controls (347.5,160.84) and (346.38,161.96) .. (345,161.96) .. controls (343.62,161.96) and (342.5,160.84) .. (342.5,159.46) -- cycle ;
draw (419,72.4) node [anchor=north west][inner sep=0.75pt]    {$S^{n}$};
draw (162.14,166.97) node [anchor=north west][inner sep=0.75pt]    {$mathbb{R}^{n}$};
draw (351.71,151.97) node [anchor=north west][inner sep=0.75pt]    {$0$};
draw (348,41.69) node [anchor=north west][inner sep=0.75pt]    {$1$};
draw (383.14,98.83) node [anchor=north west][inner sep=0.75pt]    {$x$};
draw (476.86,149.11) node [anchor=north west][inner sep=0.75pt]    {$y$};
draw [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=1 ]  (345.45, 60.37) circle [x radius= 2, y radius= 2]   ;
draw [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=1 ]  (400.33, 104.67) circle [x radius= 2, y radius= 2]   ;
end{tikzpicture}
end{center}

效果



原文地址:https://www.cnblogs.com/maoruimas/p/12774996.html