引言
本科毕设论文排版使用的微软Office的Word,当时最为繁琐的就是插入参考文献了,后来用了Endnote软件,体验了一把快感。可是Word排版出来的论文并不是那么美观,比如英文单词间空白距离不一致,公式行间距等等。
也不知怎么就认识到了LaTex,说是世界上优秀科学家与艺术家的结晶,就想着一定要学会,绝不能半途而废。可是当我们开始用的时候才会发现一大堆问题,有事甚至无从下手。
本文重在讲述 思想方法与实践,
LaTex环境配置
软件包选择与安装
LaTex或TeX排版软件
LaTeX在Windows、Linux、Mac OS上都有发行版:
操作系统 | 软件发行版 | 编辑器 |
---|---|---|
Windows | MikTeX、TexLive | TeXnicCenter、WinEdt、Sublime Text |
Unix/Linux | MikTeX、TexLive | Emacs、vim、Kile、Sublime Text |
Mac OS | MikTeX、TexLive、MacTeX | TeXShop、Sublime Text |
建议选择TEXLive,安装较为方便,就是安装包大了点,镜像包约2.9G。
MikTex源码及其Windows安装版可以在这里下载,如果想自己编译安装(比较麻烦),Windows系统请参考官方文档Building MiKTeX (Windows) ,Unix系统参考官方文档Building MiKTeX (GNU/Linux) 。
安装
MikTex在Windows上的安装很简单,这里就不再介绍,仅简要介绍Linux下TeXLive的安装,也很简单。
根据安装包给出的安装指南中所述,有文本模式,专家GUI模式等等,本人选择GUI模式,需要安装perl-tk
:
sudo apt-get install perl-tk
perl的TK安装很快,之后解压你下载的TeXLive.iso
镜像,进入TeXLive
根目录,然后输入如下命令执行安装
cd texlive
perl install-tl -gui
在弹出的对话框中,根据自己需要设置,主要设置安装目录即可:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-F3bPermo-1592882113075)(https://img-blog.csdn.net/20160326220934611 “TeXLive安装界面”)]
点击安装TeXLive
,等待安装结束即可,Sublime Text3下LaTex环境配置见本人[博客]。
编辑器
编辑器的选择,任何一款文本编辑器即可,但本人偏向Sublime Text,因为其跨平台、几乎你需要的功能都有,一切可修改(快捷键、插件包etc.);界面优美;免费;可惜的是不开源。在上面配置LaTex环境也是很舒服和容易的,具体见超级文本编辑器Sublime Text3。
注: 有关Sublime Text3下LaTex环境配置见本人博客;
LaTex排版基础
参考文献
Inventors have long dreamed of creating machines that think. Ancient Greek myths tell of intelligent objects, such as animated statues of human beings and tables that arrive full of food and drink when called. When programmable computers were first conceived, people wondered whether they might become intelligent, over a hundred years before one was built \cite{lovelace3sketch}. % 这里使用\cite{}引用
\begin{thebibliography}{}
\bibliographystyle{ieeetr}
\bibitem{lovelace3sketch}
A.~Lovelace, ``Sketch of the analytical engine invented by charles babbage, by
lf menabrea, officer of the military engineers, with notes upon the memoir by
the translator,'' {\em Taylor’s Scientific Memoirs}, vol.~3, pp.~666--731.
\end{thebibliography}
\end{document}
使用技巧
插入eps图片
Latex仅支持eps格式的图片,pdflatex支持jpg、png等格式的图片,可以像下面这样,使得这几种图片格式都支持,文件名中不加后缀,可以自动判断,很方便使用:
\documentclass[UTF8,10pt,oneside]{ctexbook}
% 导言区
\usepackage{graphicx}
\usepackage{epstopdf}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=0.9\textwidth]{./figs/fig1-1}
\caption{不同表示方法的例子}
\label{fig1.1}
\end{figure}
\end{document}
脚注
footmisc
宏包可以设置每页脚注重头开始编号,显示位置等等,结合hyperref
宏包使用,还能生成超链接,可是却发现,现引用hyperref
再引用footmisc
,超链接会失效,只能下面这样放:
% ----------------------------------------------------
% for misc footnote 放在 hyperref 后,超链接竟然会失效!!!
\usepackage[perpage,stable,bottom]{footmisc}
% ----------------------------------------------------
% generates Contents with Hyperlink
\usepackage[colorlinks,linkcolor=red,anchorcolor=blue,citecolor=green]{hyperref}
% “colorlinks”的意思是将超链接以颜色来标识,而并非使用默认的方框来标识。
% linkcolor, anchorcolor, citecolor分别表示用来标识link, anchor, cite等各种链接的颜色。
% 若正式的文档中不想使用彩色的标识,但又希望具有超链接的功能,则将上例中的各种颜色换成“black”即可。
特殊符号
数学字体
\documentclass{article}
\usepackage[UTF8]{ctex}
\usepackage{threeparttable}
\usepackage[scale={0.9,0.9}]{geometry}
\DeclareMathAlphabet{\mathpzc}{OT1}{pzc}{m}{it}%数学符号字体的设置
%\usepackage{bm} % 粗斜体 \bm
\usepackage{bbm} % \mathbbm, \mathbbss, \mathbbmtt
\usepackage{dsfont} % \mathds
\usepackage{yfonts} % \textfrak, \textswab
\usepackage{amssymb} % \mathfrak, \mathcal
\usepackage{mathrsfs}% \mathscr, 不同于\mathcal or \mathfrak 之类的英文花体字体%产生拉普拉斯变换式的字母
\begin{document}
\newcommand{\testmath}[1]{ \begin{tabular}{l}
$#1{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$ \\[-5pt]
$#1{abcdefghijklmnopqrstuvwxyz\ 0123456789 Add to Citavi project by ISBN}$
\end{tabular}}
\newcommand{\testtext}[1]{ \begin{tabular}{l}
#1{ABCDEFGHIJKLMNOPQRSTUVWXYZ} \\[-5pt]
#1{abcdefghijklmnopqrstuvwxyz\ 0123456789 Add to Citavi project by ISBN}
\end{tabular}}
\begin{table}
\centering
\begin{threeparttable}
\begin{tabular}{c|l|c}
\hline
command & result & package \\\hline
default & \testmath{} & non \\\hline
\verb|\mathrm| & \testmath{\mathrm} & non \\\hline
\verb|\mathit| & \testmath{\mathit} & non \\\hline
\verb|\mathbf| & \testmath{\mathbf} & non \\\hline
\verb|\mathtt| & \testmath{\mathtt} & non \\\hline
\verb|\mathsf| & \testtext{\textsf} & non\tnote{a} \\\hline
\verb|\mathcal| & \testmath{\mathcal} & non\tnote{b} \\\hline
\verb|\mathbb| & \testmath{\mathbb} & \verb|\usepackage{amssymb}|\tnote{c} \\\hline
\verb|\mathfrak| & \testmath{\mathfrak} & \verb|\usepackage{amssymb}| \\\hline
% \verb|\bm| & \testmath{\bm} & \verb|\usepackage{bm}| \\\hline
\verb|\mathbbm| & \testmath{\mathbbm} & \verb|\usepackage{bbm}| \\\hline
\verb|\mathbbmss| & \testmath{\mathbbmss} & \verb|\usepackage{bbm}| \\\hline
\verb|\mathbbmtt| & \testmath{\mathbbmtt} & \verb|\usepackage{bbm}| \\\hline
\verb|\mathscr| & \testmath{\mathscr} & \verb|\usepackage{mathrsfs}| \\\hline
\verb|\mathds| & \testmath{\mathds} & \verb|\usepackage{dsfont}|\tnote{d} \\\hline
\verb|\mathpzc| & \testmath{\mathpzc} & non\tnote{e} \\\hline
\verb|\textfrak| & \testtext{\textfrak} & \verb|\usepackage{yfonts}| \\\hline
\verb|\textswab| & \testtext{\textswab} & \verb|\usepackage{yfonts}| \\\hline
\end{tabular}
\begin{tablenotes}
\item [a] \verb|\mathpzc| conflicts with \verb|\mathsf|, so here the result is in fact from \verb|\textsf|
which gives the same result with \verb|\mathsf|.
\item [b] The useage of package \verb|eucal| can change the font appearence.
\item [c] The \verb|amssymb| package is a superset of the \verb|amsfonts| package.
\item [d] Using \verb|sans| option, \verb|\usepackage[sans]{dsfont}|, gives sans version font.
\item [e] Need the command: \verb|\DeclareMathAlphabet{\mathpzc}{OT1}{pzc}{m}{it}|
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
PDF页面组合
可以使用 pdfpages
,但是如其文档所说会丢失链接。
\documentclass[a4paper]{article}
\usepackage{pdfpages}
\begin{document}
% ---way1
\includepdf[pages=1-1]{main1.pdf}
\includepdf[pages=1-1]{main2.pdf}
% ---way2
% \includepdfmerge{main1.pdf,1-1}
% \includepdfmerge{main2.pdf,1-1}
\end{document}
如pdfpages
文档建议,可以使用用 pax
保留链接,步骤如下:
- 在主文件中添加引用:
\usepackage{pax}
- 处理pdf文件得到pax文件:
java -jar pax.jar main2.pdf
,其中par.jar
文件的路径可以在texlive安装包中找到,比如:/usr/local/texlive/2023/texmf-dist/scripts/pax/
- 重新编译生成合并后的pdf文件:
pdflatex main.tex
,至少编译2次。
插入多媒体文件
LaTeX幻灯片提纲 这个总结较详细。
问题解决
使用
Something’s wrong–perhaps a missing \item.
这很可能是你将参考文献放在了一个bib文件中,而在正文中你是这样写的:
\begin{thebibliography}{}
\bibliographystyle{ieeetr}
\bibliography{DeepLearning_zh_me}
\end{thebibliography}
因为tex文件中的\begin{thebibliography}{} ... \end{thebibliography}
与bbl中的重复,所以只需将tex中代码改成这样即可:
\bibliographystyle{ieeetr}
\bibliography{DeepLearning_zh_me}
I found no style file
检查源文件根目录或者texlive安装目录是否有相应参考文献格式话文件,如IEE模板的 IEEEtrans.bst
,一般下载的模板文件夹中会有bst文件夹,从中拷贝放至根目录重新编译即可。
pdfstartlink pdfendlink
提示如下错误:
Errors:
pdfTeX error (ext4): \pdfendlink ended up in different nesting level than \pdfstartlink.
Check the TeX log file for more information
和 hyperref
这个包有关, 把你刚改的那块文字增加或者减少一些估计就好了, 很奇怪.