Notes on LaTeX

在写论文了, 记录一下学习LaTeX的过程.

LaTeX Cheat Sheet - CTAN

{ CHEAT SHEET } - Dr. Cosima Meyer

LATEX 2ε Cheat Sheet

Templates

Arxiv & PRIME AI Style Template - Moulay A. Akhloufi

IEEE

IEEE Template Selector

How to Use the IEEEtran LATEX Class

This article describes how to use the IEEEtran class with LATEX to produce high quality typeset papers that are suitable for submission to the Institute of Electrical and Electronics Engineers (IEEE). IEEEtran can produce conference, journal and technical note (correspondence) papers with a suitable choice of class options. This document was produced using IEEEtran in journal mode.

IEEE affiliation blocks: 会议时的作者格式, 加脚注的方法\IEEEauthorrefmark{1}

tikz package causing error in IEEE access template: IEEEtran和tikz有冲突? 实际上我遇到的问题在于subfigure的包产生了冲突, 把IEEEtran默认的subfig导入命令注释掉, 改为导入subcaption就可以了

Reference

Automatically extract a bibitem in LaTex: 之前引用是使用的Zotero导出的.bib文件, 现在如何获得bibitem的引用格式? 见References in IEEEtran?, 新建references.bib后用以下两行搞定: (这个名字最好不要带空格)

1
2
\bibliographystyle{ieeetran}
\bibliography{references}

发现有的引用里带有url, 参考Disabling URLs in bibliography的方法, 具体为在.bib

1
2
3
@IEEEtranBSTCTL{MyBSTcontrol,
CTLuse_url = "no",
}
1
2
\begin{document}
\bstctlcite{MyBSTcontrol}

@IEEEtranBSTCTL的详细的语法见How to Use the IEEEtran BIBTEX Style.

然而发现Zotero更新的时候会覆盖源文件, 导致设置的@IEEEtranBSTCTL会消失, 正确做法是在Zotero中调整格式的输出设置.

Shortcut

Go to Source

使用ctrl + left clickctrl + alt +jpdftex文件来回切换, 见"Go to Source" for Latex on VS Code does not seem to work.

今天还遇到一个bug, 头疼了一晚上, 就是某个tex文件的两个切换不管用, 而目录中有个**.synctex(busy)文件相当可疑, 直接删除还删不掉, 于是用任务管理器把占用该文件的进程强制关闭后重新编译, 问题解决.

Reference

Arxiv & PRIME AI Style Template里有个搞笑的错误, 搁这手打引用呢?

1
2
3
4
5
6
7
8
9
Of note is the command \verb+\citet+, which produces citations
appropriate for use in inline text. For example,
\begin{verbatim}
\citet{hasselmo} investigated\dots
\end{verbatim}
produces
\begin{quote}
Hasselmo, et al.\ (1995) investigated\dots
\end{quote}

作者原意是要教大家怎么使用numerical引用(如[1])和textual引用(如Jones et al. (1990)), 修改该模板的方式如下, 见Numbered citations in LaTeX, 其中plainnat也可换为unsrtnat, 就是排不排序的区别.

1
2
\usepackage[numbers]{natbib}
\bibliographystyle{plainnat}

另见Bibliography management with natbib, Reference sheet for natbib usage.

引用后报错

1
2
3
\cite{gendreauTabuSearchHeuristic1999}
\bibliography{BibTeX}
\bibliographystyle{ieeetran}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@article{gendreauTabuSearchHeuristic1999,
title = {A Tabu Search Heuristic for the {{Steiner Tree Problem}}},
author = {Gendreau, Michel and Larochelle, Jean-Francois and Sans{\dbend}, Brunilde},
year = {1999},
month = sep,
journal = {Networks},
volume = {34},
number = {2},
pages = {162--172},
issn = {0028-3045, 1097-0037},
doi = {10.1002/(SICI)1097-0037(199909)34:2<162::AID-NET9>3.0.CO;2-9},
langid = {english},
file = {D\:\\OneDrive\\literature\\STP\\Gendreau et al_1999_A tabu search heuristic for the Steiner Tree Problem.pdf}
}

Table

Tables Generator上打个样稿, 然后做一些细节上的微调.

  1. 让表格变长一点. 撑满屏幕的方法见How to force a table into page width?.

    1
    2
    3
    \begin{tabular*}{\textwidth}{c @{\extracolsep{\fill}} ccccc}
    ...
    \end{tabular*}

    不过这对窄表来说太难看了, 我真正需要的是头尾列多一点点空间, 方法为\begin{tabular*}{@{\hskip 0.5em}l||rrr|rrr|rrr@{\hskip 0.5em}}, 见Adding space between columns in a table

  2. 对列宽做微调. 把c改为p{0.5cm}, 见How to make width of columns in table smaller

  3. Booktabs样式下画双线, 如POMO中的表2, 方法参见4 Abuse of the new commands -- Publication quality tables in LATEX ∗, 有几点地方要注意:

    • \cmidrule{1-2}\morecmidrules\cmidrule{1-2}会导致无限build, 原因未知.
    • 使用\midrule{1-2}\morecmidrules\midrule{1-2}距离太宽.
    • 使用\midrule\addlinespace[0em] \midrule距离正好.
    • 以上都是横线, 竖线加法很简单, 如:\begin{*tabular*}{@{}l||rrr|rrr|rrr@{}}, 想加的地方画两杠就行了.

Color

Background Color

设置一些护眼色, 见Change background colour for entire document, pagecolor – Interrogate page colour. 然而这个调色没搞懂, 目前用的red!60!green!90!blue!70!.

1
2
3
4
5
6
\documentclass{article}
\usepackage{pagecolor,lipsum}% http://ctan.org/pkg/{pagecolor,lipsum}
\begin{document}
\pagecolor{red!60!green!90!blue!70!}
\lipsum
\end{document}

Scientific Color

Choosing color palettes for scientific figures

Color name Color RGB Triplet RGB Hexadecimal
RPTH Blue (0, 45, 106) #003366
RPTH Red (227, 27, 35) #E31B23
RPTH Medium Blue (0, 92, 171) #005CAB
RPTH Light Blue (220, 238, 243) #DCEEF3
RPTH Accent Yellow (255, 195, 37) #FFC325
RPTH Cool Gray (230, 241, 238) #E6F1EE

TikZ

crash course to tikz [1 · basics]

crash course to tikz [2 · positioning]

Subfigure

LaTeX Tutorial-Figures: 简洁的1×3例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
\documentclass{article}
\usepackage{float}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}[H]
\centering
\begin{subfigure}{.1\textwidth}
\includegraphics[width=\textwidth]{atom.png}
\caption{Atom 1}
\end{subfigure}
%%%%%%%%%%%%%%
\begin{subfigure}{.3\textwidth}
\includegraphics[width=\textwidth]{atom.png}
\caption{Atom 2}
\end{subfigure}
%%%%%%%%%%%%%%
\begin{subfigure}{.4\textwidth}
\includegraphics[width=\textwidth]{atom.png}
\caption{Atom 3}
\end{subfigure}
\caption{Atoms are fun!}
\end{figure}
\end{document}

image-20220331144848773

TikZ in subfigure environment not scaling properly with : 解释\linewidth\textwidth.

To start with \linewidth is the width of a text line. In normal one column text it is the same as the text width (\textwidth) but in two columns it is the width of a column.

1×3模板: 3 or 4 tikz figures side-by-side; 2x2模板: Problem on subfigure 2X2

Multiple Tikz-Trees in a subfigure-grouped figure row: 子图换行的原因, 是因为多打了空行. (气死了, debug了一个小时!)

standalone和subfigure结合时报错

standalone和subfigure结合时报错! LaTeX Error: Something's wrong--perhaps a missing \item, 解决方法为\documentclass[preview, border=5pt]{standalone}, 见Troubles using standalone class with subfig

使用includestandalone导入图片

Using for TikZ figure which uses \includegraphics

1
2
\usepackage[mode=buildnew,subpreambles=true]{standalone}
\includestandalone[width=\linewidth]{images/standalone-image}

但好像子图不能引用.

tikz在standlone报错

Troubles using standalone class with subfig: 改为\documentclass[preview]{standalone}

Image

svg

论文中有导入矢量图的需求, 具体方法见How to include SVG diagrams in LaTeX?, passing the extension to - damned if you do, damned if you don't, 做几点必要的说明:

  • 安装Inkscape, 并加入代码\setsvg{inkscape={"C:/Program Files/Inkscape/inkscape.com"}}指定路径, 参见Trouble converting svg file to pdf_svg using svg package.
  • 编译时需要使用pdflatex -shell-escape test的选项, 在VS Code中的设置方式为Manage → Settings → workshop.latex.tools → Edit in settings.json, 在args 中加入-shell-escape即可. 另见Compiling - LaTeX recipes - LaTeX tools.

最后给出我的代码, 其中所有的svg图片都在images文件夹中.

1
2
3
4
5
\begin{figure}[]
\centering
\includesvg[width=0.5\columnwidth, svgpath=images]{mrcst2_generalization}
\caption{svg image}
\end{figure}

子目录下使用includegraphics

Inserting Images: 使用\graphicspath{ {./images/} }

绘制有向图

  • Directed graph weights: \path[->] (y1) edge node[pos=0.25,below right] {-8} (x2);
  • Directed graph weights: (m-2-1) edge node[near start, swap] {-8} (m-1-2)
  • Adding edge weights to TikZ using syntax: \draw[edge] (t) to node[above, xshift=8mm] {$w_{tu}$} (u);