Note on LaTeX

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

LaTeX Cheat Sheet - CTAN

{ CHEAT SHEET } - Dr. Cosima Meyer

LATEX 2ε Cheat Sheet

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.

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. 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.

3 or 4 tikz figures side-by-side: 一个很好的1×3模板.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
\begin{figure}
\begin{subfigure}[b]{0.30\textwidth}
\centering
\resizebox{\linewidth}{!}{\input{figures/a.tikz}}
\caption{Caption A}
\label{fig:A}
\end{subfigure}
\begin{subfigure}[b]{0.30\textwidth}
\centering
\resizebox{\linewidth}{!}{\input{figures/b.tikz}}
\caption{Caption B}
\label{fig:B}
\end{subfigure}
\begin{subfigure}[b]{0.30\textwidth}
\centering
\resizebox{\linewidth}{!}{\input{figures/c.tikz}}
\caption{Caption C}
\label{fig:C}
\end{subfigure}
\end{figure}

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}

但好像子图不能引用.