\documentclass[UTF8,fontset=fandol,12pt,openany]{ctexbook}

% ---------- 页面与字体 ----------
\usepackage[a4paper,top=2.8cm,bottom=2.6cm,left=3cm,right=2.6cm]{geometry}
% ---------- 常用功能 ----------
\usepackage{setspace}
\usepackage{indentfirst}
\usepackage{amsmath,amssymb,mathtools}
\usepackage{graphicx}
\usepackage{booktabs,tabularx,array,multirow}
\usepackage{xcolor}
\usepackage{float}
\usepackage{listings}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage{bookmark}
\usepackage[backend=biber,style=numeric,sorting=none]{biblatex}

\addbibresource{references.bib}

% ---------- 正文样式 ----------
\onehalfspacing
\setlength{\parindent}{2em}
\setlength{\parskip}{0pt}
\setlength{\headheight}{15pt}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{通用中文论文模板}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}

\hypersetup{
  colorlinks=true,
  linkcolor=blue,
  citecolor=blue,
  urlcolor=blue,
  pdftitle={通用中文论文模板},
  pdfauthor={你的名字}
}

\lstset{
  basicstyle=\ttfamily\small,
  keywordstyle=\color{blue},
  commentstyle=\color{green!50!black},
  stringstyle=\color{orange!70!black},
  numbers=left,
  numberstyle=\tiny\color{gray},
  frame=single,
  breaklines=true,
  showstringspaces=false,
  columns=fullflexible
}

\floatname{algorithm}{算法}
\algrenewcommand\algorithmicrequire{\textbf{输入：}}
\algrenewcommand\algorithmicensure{\textbf{输出：}}

\begin{document}

% ============================================================
% 封面
% ============================================================
\begin{titlepage}
  \centering
  \vspace*{2cm}

  {\zihao{2}\bfseries 某某大学\par}
  \vspace{1.5cm}
  {\zihao{-2}\bfseries 课程报告 / 学术论文 / 毕业设计\par}
  \vspace{2cm}

  {\zihao{1}\bfseries 在这里填写论文题目\par}
  \vspace{2.5cm}

  \begin{tabular}{rl}
    \zihao{4}作者： & \zihao{4}你的名字 \\
    \zihao{4}学号： & \zihao{4}2026000000 \\
    \zihao{4}专业： & \zihao{4}计算机科学与技术 \\
    \zihao{4}指导教师： & \zihao{4}某某老师 \\
  \end{tabular}

  \vfill
  {\zihao{4}\today\par}
\end{titlepage}

\frontmatter

% ============================================================
% 中文摘要
% ============================================================
\chapter*{摘\quad 要}
\addcontentsline{toc}{chapter}{摘要}

这里填写中文摘要。摘要通常说明研究背景、要解决的问题、使用的方法、主要实验结果和结论。摘要一般不放图片、表格和很长的公式。

\vspace{1em}
\noindent\textbf{关键词：}LaTeX；学术写作；论文模板；XeLaTeX

% ============================================================
% 英文摘要
% ============================================================
\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}

Write the English abstract here. Briefly introduce the background, problem, method, main results, and conclusion.

\vspace{1em}
\noindent\textbf{Keywords:} LaTeX; academic writing; thesis template; XeLaTeX

\tableofcontents
\clearpage

\mainmatter

% ============================================================
% 第一章 引言
% ============================================================
\chapter{引言}
\label{chap:introduction}

这里介绍研究背景、研究问题和本文贡献。LaTeX 的文档准备思想由 Lamport 系统推广\cite{lamport1994}。

本文的主要贡献可以写成列表：

\begin{itemize}
  \item 提出了一种简单、清晰的方法；
  \item 完成了可重复的实验；
  \item 对实验结果进行了分析。
\end{itemize}

\section{研究背景}

这里填写研究领域的背景和实际意义。

\section{本文结构}

第\ref{chap:related}章介绍相关工作，第\ref{chap:method}章介绍方法，第\ref{chap:experiment}章给出实验，第\ref{chap:conclusion}章总结全文。

% ============================================================
% 第二章 相关工作
% ============================================================
\chapter{相关工作}
\label{chap:related}

这里按照主题介绍已有研究，并指出它们与本文工作的关系。不要只罗列论文，要说明它们做了什么、有什么不足、与你的方法有什么联系。

% ============================================================
% 第三章 方法
% ============================================================
\chapter{方法}
\label{chap:method}

设输入为 $x$，模型参数为 $\theta$，预测结果为

\begin{equation}
  \hat{y}=f(x;\theta).
  \label{eq:model}
\end{equation}

式\eqref{eq:model}给出了模型的基本形式。

\section{训练流程}

\begin{algorithm}[htbp]
  \caption{机器学习模型训练流程}
  \label{alg:training}
  \begin{algorithmic}[1]
    \Require 训练集 $D$，学习率 $\eta$，最大轮数 $T$
    \Ensure 训练后的参数 $\theta$
    \State 随机初始化参数 $\theta$
    \For{$t=1$ to $T$}
      \State 从 $D$ 中读取一个小批量样本
      \State 计算损失函数 $L(\theta)$
      \State $\theta \gets \theta-\eta\nabla_{\theta}L(\theta)$
      \If{验证集性能不再提升}
        \State \textbf{break}
      \EndIf
    \EndFor
    \State \Return $\theta$
  \end{algorithmic}
\end{algorithm}

算法\ref{alg:training}展示了一个简化的训练过程。

% ============================================================
% 第四章 实验
% ============================================================
\chapter{实验}
\label{chap:experiment}

\section{实验设置}

表\ref{tab:settings}给出示例实验设置。

\begin{table}[htbp]
  \centering
  \caption{实验设置}
  \label{tab:settings}
  \begin{tabular}{lcc}
    \toprule
    参数 & 取值 & 说明 \\
    \midrule
    学习率 & 0.001 & Adam 优化器 \\
    批大小 & 32 & 每批样本数 \\
    训练轮数 & 100 & 最大训练轮数 \\
    \bottomrule
  \end{tabular}
\end{table}

\section{示例图片位置}

图\ref{fig:placeholder}是一个不依赖外部文件的占位图。替换成真实图片时，把方框部分换成 \verb|\includegraphics| 命令。

\begin{figure}[htbp]
  \centering
  \fbox{\rule{0pt}{5cm}\rule{0.75\textwidth}{0pt}}
  \caption{请在这里替换成实验结果图片}
  \label{fig:placeholder}
\end{figure}

% ============================================================
% 第五章 结果分析
% ============================================================
\chapter{结果分析}

这里解释实验结果为什么会这样，而不是只重复表格里的数字。可以讨论最佳结果、异常现象、误差来源、方法局限和改进方向。

\begin{lstlisting}[language=Python,caption={简单的 Python 示例},label={code:python}]
def accuracy(correct, total):
    return correct / total

print(accuracy(92, 100))
\end{lstlisting}

代码\ref{code:python}展示了一个简单的准确率计算函数。

% ============================================================
% 第六章 结论
% ============================================================
\chapter{结论}
\label{chap:conclusion}

这里总结本文解决了什么问题、采用了什么方法、得到了什么结果，并简要说明未来工作。不要在结论中突然加入正文从未出现的新实验。

\printbibliography[heading=bibintoc,title={参考文献}]

% ============================================================
% 附录
% ============================================================
\appendix

\chapter{补充实验}

这里放不适合塞进正文、但又值得保留的推导、额外实验、完整问卷或大段代码。

\chapter{补充代码}

\begin{lstlisting}[language=Python,caption={附录中的示例代码}]
for epoch in range(10):
    print(f"epoch = {epoch}")
\end{lstlisting}

\end{document}
