latex-writing
Use when: 需要用 LaTeX 写作、排版文档(含中文支持、公式、三线表、插图、章节格式)。涵盖常用宏包用法、表格防溢出、图表编号、XeLaTeX 编译与常见错误修复。关键词:LaTeX 排版、中文 LaTeX、XeLaTeX、三线表、数学公式、插图、编译报错。
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Use when: 需要用 LaTeX 写作、排版文档(含中文支持、公式、三线表、插图、章节格式)。涵盖常用宏包用法、表格防溢出、图表编号、XeLaTeX 编译与常见错误修复。关键词:LaTeX 排版、中文 LaTeX、XeLaTeX、三线表、数学公式、插图、编译报错。
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
使用 MinerU API 将 PDF/Word/PPT/图片解析为结构化 Markdown,公式保留为 LaTeX,表格保留结构,支持 OCR。适合论文解析、教材提取、扫描件文字识别等场景。
Use when writing a Chinese physics, optics, or electronics lab report from local experiment materials, generating a XeLaTeX source file, extracting data from images, inserting figures, answering thinking questions, and compiling a GB/T 7713.1 style PDF.
Use when:drafting, polishing, restructuring, translating, or formatting STEM academic writing such as physics, optics, electronics, computer science notes, abstracts, paper sections, literature summaries, or formal Chinese/English academic prose.
Use when: 需要将 Obsidian Excalidraw 文件(.excalidraw.md)导出为 PNG 或 SVG 图片。支持批量导出、嵌入图片自动注入、嵌入 MD 笔记渲染(含 KaTeX 数学公式)、配对语法为每个文件单独指定输出路径。关键词:excalidraw 导出、Obsidian 画图导出、excalidraw to png、excalidraw to svg。
Use when:packaging Obsidian homework notes by finding linked Excalidraw handwritten notes, exporting them to PNG, generating a watermarked XeLaTeX document, and compiling a PDF for examples, exercises, or chapter homework.
Use when:preparing for a physics, optics, or electronics experiment by reading local materials and generating an experiment interpretation document, an operation guide, and a blank XeLaTeX data-record PDF.
| name | latex-writing |
| description | Use when: 需要用 LaTeX 写作、排版文档(含中文支持、公式、三线表、插图、章节格式)。涵盖常用宏包用法、表格防溢出、图表编号、XeLaTeX 编译与常见错误修复。关键词:LaTeX 排版、中文 LaTeX、XeLaTeX、三线表、数学公式、插图、编译报错。 |
| argument-hint | 描述需要完成的 LaTeX 排版任务 |
中文文档必须使用 XeLaTeX(而非 pdflatex),运行两遍确保交叉引用正确:
xelatex -interaction=nonstopmode main.tex
xelatex -interaction=nonstopmode main.tex
| 功能 | 宏包 | 关键命令 |
|---|---|---|
| 中文支持 | ctex([UTF8, zihao=-4]) | 自动处理字体、缩进、字号 |
| 英文字体 | fontspec | \setmainfont{Times New Roman} |
| 页边距 | geometry | [top=2.5cm, bottom=2.5cm, left=2.8cm, right=2.8cm] |
| 行距 | setspace | \setstretch{1.5} |
| 图片 | graphicx + float | \includegraphics[width=...]{} + [H] 强制定位 |
| 三线表 | booktabs | \toprule \midrule \bottomrule |
| 数学 | amsmath + amssymb | equation、align、multline |
| 表头换行 | makecell | \makecell{第一行\\第二行} |
| 表格自适应宽度 | adjustbox | \begin{adjustbox}{max width=\textwidth} |
| 横向页面 | pdflscape | \begin{landscape}...\end{landscape} |
| 图表标题 | caption | \captionsetup{font=small, labelsep=space} |
| 页眉页脚 | fancyhdr | \fancyhead[C]{...} \fancyfoot[C]{\thepage} |
| 超链接/书签 | hyperref | [colorlinks=true, linkcolor=black] |
| 章节格式 | titlesec | \titleformat{\section}[block]{...} |
\documentclass[12pt, a4paper]{article}
\usepackage[UTF8, zihao=-4]{ctex} % 中文支持,正文小四
\usepackage{fontspec}
\setmainfont{Times New Roman} % 英文/数字 Times New Roman
ctex 会自动设置中文字体(宋体正文、黑体标题)和首行缩进 2 字符\zihao{3}(三号 16pt)、\zihao{4}(四号 14pt)、\zihao{-4}(小四 12pt)、\zihao{5}(五号 10.5pt)\heiti(黑体)、\songti(宋体)、\kaishu(楷书)质量 $m$,速度 $v$,动能为 $E_k = \frac{1}{2}mv^2$
\begin{equation}
E = mc^2 \label{eq:einstein}
\end{equation}
引用:式\eqref{eq:einstein}
\begin{align}
F &= ma \\
&= m \frac{\mathrm{d}v}{\mathrm{d}t}
\end{align}
\begin{multline}
\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i \\
= \frac{x_1 + x_2 + \cdots + x_n}{n}
\end{multline}
| 符号 | 命令 | 符号 | 命令 |
|---|---|---|---|
| $\alpha\beta\gamma$ | \alpha \beta \gamma | $\partial$ | \partial |
| $\nabla$ | \nabla | $\infty$ | \infty |
| $\times$ | \times | $\cdot$ | \cdot |
| $\vec{A}$ | \vec{A} | $\hat{e}$ | \hat{e} |
| $\overrightarrow{AB}$ | \overrightarrow{AB} | $\mathrm{d}$ | \mathrm{d} |
\usepackage{graphicx}
\usepackage{float}
\graphicspath{{./images/}} % 图片目录(相对路径)
\begin{figure}[H] % [H] 强制就地放置,需 float 包
\centering
\includegraphics[width=0.8\textwidth]{filename.png}
\caption{图片标题}
\label{fig:label}
\end{figure}
图片编号分章(如"图2-3"):
\renewcommand{\thefigure}{\arabic{section}-\arabic{figure}}
\counterwithin{figure}{section}
图题在图下方,正文引用:如图~\ref{fig:label}所示
\usepackage{booktabs}
\begin{table}[H]
\caption{表格标题} % 表题在表上方
\label{tab:label}
\centering
\begin{tabular}{ccc}
\toprule
列一 & 列二 & 列三 \\
\midrule
数据 & 数据 & 数据 \\
\bottomrule
\end{tabular}
\end{table}
表格编号分章(如"表2-3"):
\renewcommand{\thetable}{\arabic{section}-\arabic{table}}
\counterwithin{table}{section}
A4 纸正文宽约 15.4 cm。满足以下任一条件时视为高风险:列数 ≥ 6、表头 ≥ 8 汉字、含长公式+单位、行内字符估算 ≥ 80。
按优先级选用:
| 方案 | 适用场景 | 示例 |
|---|---|---|
| a. 缩短表头 | 表头冗长,可用符号代替 | $\bar{x}$/mm |
| b. 表头换行 | 表头中等长度 | \makecell{测量\\次数} |
| c. 整体缩放 | 列数较多,内容难缩短 | \resizebox{\textwidth}{!}{\begin{tabular}{...}...\end{tabular}} |
| d. adjustbox | 超出页宽才缩,否则原尺寸 | \begin{adjustbox}{max width=\textwidth}...\end{adjustbox} |
| e. 横向页面 | 列数极多(≥ 9)或缩放后字号过小 | \begin{landscape}...\end{landscape} |
| f. 拆分子表 | 行列均多,缩放不可读 | 拆为表 X-1a 和 X-1b |
\resizebox只能包裹tabular环境,不能直接包裹table浮动体。
\usepackage{titlesec}
% 一级标题:黑体四号,居中
\titleformat{\section}[block]
{\centering\heiti\zihao{4}}{\thesection}{1em}{}
\titlespacing*{\section}{0pt}{24pt}{18pt}
% 二级标题:黑体小四
\titleformat{\subsection}[hang]
{\heiti\zihao{-4}}{\thesubsection}{1em}{}
\titlespacing*{\subsection}{0pt}{18pt}{6pt}
不要用
\ctexset{section={...}}语法——部分 TeX Live 版本不支持,改用titlesec。
\usepackage{fancyhdr}
\setlength{\headheight}{15pt} % 必须在 \usepackage{fancyhdr} 之后
\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{\small 文档标题}
\fancyfoot[C]{\small\thepage}
\usepackage[colorlinks=true, linkcolor=black, citecolor=black,
urlcolor=blue, bookmarks=true, bookmarksnumbered=true]{hyperref}
\label{fig:xxx} → 引用 图~\ref{fig:xxx}\label{tab:xxx} → 引用 表~\ref{tab:xxx}\label{eq:xxx} → 引用 式~\eqref{eq:xxx}hyperref 必须放在导言区最后加载(fancyhdr 等之后)| 错误信息 | 原因 | 修复方法 |
|---|---|---|
\headheight is too small | fancyhdr 默认高度不足 | 加 \setlength{\headheight}{15pt} |
The key 'ctex/section' is unknown | ctexset 语法不兼容当前版本 | 改用 titlesec 包 |
unicode-math 或 leading 缺失 | 宏包未安装 | 删除该宏包,用 \setstretch{} 替代行距 |
xdvipdfmx: Unable to open .pdf | PDF 被其他程序占用 | 关闭 PDF 查看器后重新编译 |
Overfull \hbox | 内容溢出版心 | 针对 tabular 用上表方案处理;行间公式用 multline/align |
! Undefined control sequence | 宏包未引入或命令拼写错误 | 检查导言区宏包,对照文档核查命令 |
调试流程:编译失败后读取 .log 文件,找所有 ! 开头的行,修复后再次运行两遍 xelatex。
% 方式一:手动(适合少量引用)
\begin{thebibliography}{99}
\bibitem{ref1} 作者. 题名[J]. 期刊名, 年, 卷(期): 起--止页.
\end{thebibliography}
% 方式二:natbib(适合较多引用)
\usepackage[numbers, sort&compress]{natbib}
\bibliographystyle{unsrtnat}
\bibliography{refs} % refs.bib 文件
正文引用:\cite{ref1}(上标数字需配合 \citep 或 \citenum)