memo: Latex

Basics

长伪代码跨栏

Placing a single algorithm in two columns

1
2
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\usepackage{multicol}

把算法内容\begin{multicols}[2] ... \end{multicols} 包起来,而不是在 \begin{algorithm} ... \end{algorithm}外面。

文档页面旋转90度

Rotate a page 180 degrees in LaTeX

For the whole document:

1
\documentclass[landscape]{article}

Table每行自动标号

Reference table row in LaTeX

使用 counter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
\usepackage{array}
\newcounter{rowcntr}[table]
\renewcommand{\therowcntr}{\arabic{rowcntr}}

% A new columntype to apply automatic stepping
\newcolumntype{N}{>{\refstepcounter{rowcntr}\therowcntr}w{c}{0.1em}}

% Reset the rowcntr counter at each new tabular
% \AtBeginEnvironment{tabular}{\setcounter{rowcntr}{0}}
.......

\begin{tabular}{|N|c|c|c|}
\end{tabular}

How does the \newcolumntype command work?

w{c}{0.1em} 是控制对齐和列宽

长表格自动换页

latex long table automatic move to next page

\usepackage{longtable}

Multi-page tables using \longtable

里面不能用 tabular 环境,不过据说它支持大部分tabular 特性

1
2
3
4
\begin{longtable}{|c|c|c|c|}
Title & Nerf’s Problems & Solutions & Flaw
\endhead % 让表头出现在每页上
\end{longtable}

表格内换行

  1. cell 内部再用个 tabular 环境:

    \begin{tabular}[t]{@{}p{\linewidth}@{}}PlenOctrees for Real-time Rendering of Neural Radiance Fields \\ ICCV 2021 Oral \end{tabular}

  2. \newline ICCV 2021

交叉引用替换为文字

LaTeX/Hyperlinks

用法:

1
2
3
\usepackage{hyperref}
...
\hyperref[label_name]{''link text''}

\ref{label_name} 只是数字

Advanced LaTeX Cross-references

post

\pageref{key} command, which prints the number of the page where the \label{key} was inserted.

画程序流程图

Code using algorithm2e package

插入代码块

matlab Highlighting MATLAB Code in LaTeX with mcode

画坐标系

Coordinate system in LaTeX with TikZ

Pgfplots package overleaf

Overfull \hbox with pgfplots graph


画夹角

How to draw a simple angle, two intersecting lines Tikz


画圆柱体

generate simple cylindrical shape with text in latex (tikz)

Learn How to Draw a Cylinder Shape in TikZ

同步缩放 TikZ 与其中的 node

在 LaTeX 中同步缩放 TikZ 与其中的 node

缩放表格

Is there a way to slightly shrink a table, including font size, to fit within the column boundaries?

多张图片并排

subfigure:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
\usepackage{subfigure}%并排子图 共享标题 有子标题

\begin{document}
\begin{figure}[H]
  \centering
  \subfigure[一次函数]{
    \label{fig:subfig:onefunction} 
    \includegraphics[scale=0.3]{figureDemo2}}
  \hspace{0.5in} % 两图片之间的距离
  \subfigure[二次函数]{
    \label{fig:subfig:twofunction} 
    \includegraphics[scale=0.3]{figureDemo3}}
  \caption{2个图片并排演示}
  \label{fig:twopicture} 
\end{figure}
\end{document} 

minipage

1
2
3
4
\begin{figure}[htbp]
\centering

\end{figure}

矩阵每行加 label

1
\usepackage{blkarray}

overleaf DIP assign 3

Suitable for R markdown Label rows and columns of a matrix in R Markdown with Latex and HTML rendering

Basic usage

(2021-01-15)

 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
\documentclass{article}	%文档类型:文章
\documentclass{book}	%书
\documentclass{beamer}	%幻灯片格式
\documentclass[UTF8]{ctexart}	%ctexart支持中英文混拍,指定文档编码类型
\documentclas[UTF8]{ctexbook}	%对书籍排版

\title{文章标题}
\author{文章作者}
\date{文档的修改日期}
\date{\today}	%自动生成当天日期

\begin{document}	%下面是正文,上面是前言,\begin和\end之间是环境/作用域,位于同一个环境中的内容将会共享相同的文字格式
\maketitle	%在当前位置生成文档的标题(前言区设置的信息)

\textbf{加粗文字}	%bold font
\textit{斜体}		%italic
\underline{加下划线}
%两个回车是换段,一个回车是一个空格

\part{书籍的第一部分}
\chapter{书籍的第一章}
\section{这是地一个章节}
你好!
\subsection{子章节}
二级章节下的内容
\subsubsection{这是一个三级章节}
三级章节下的内容
\section{这是第二个章节}
第二章节下的内容

%插入图片
\usepackage{graphicx}	%引用包,包含了若干绘制图片的指令
\begin{figure}	%把图片嵌套到figure环境中,可以指定标题
\centering		%将图片居中显示
\includegraphics[width=0.5\textwidth]{图片名字可省略后缀}	%在当前位置添加一张图片,图片宽度等于0.5倍的当前文本区域的宽度
\caption{这是图片的标题}
\end{figure}

%列表
\begin{itemize}	%无序列表的创建:列表中的每一个元素都需要以\item开头
\item 列表项1
\item 列表项2
\item 列表项3
\end{itemize}

\begin{enumrate}	%有序列表:前面带编号
\item 列表项1
\item 列表项2
\item 列表项3
\end{enumerate}

%数学公式
质能方程:$E=mc^2$

\begin{equation}
E=mc^2
\end{equation}

\[
E=mc^2
\]

\over 是几分之几
\[
d={k \varphi(n)+1} \over e
\]
codecogs 可以测试公式

%表格
\begin{table}	%table环境设置标题
\caption{表格的标题}
\center	%表格居中显示
\begin{tabular}{|c| c| c|}	%有三列,每列都居中(centering),| 代表竖直边框。
% {l c c} 则表示第一列左对齐(left)
% {p{2cm} c c}	设置列宽2cm
\hline	#水平边框
单元格1 & 单元格2 & 单元格3 \\
\hline\hline	%双横线
单元格4 & 单元格5 & 单元格6 \\
\hline
单元格7 & 单元格8 & 单元格9 \\
\hline
\end{tabular}
\end{table}

Paper tips

(2024-03-21)

guanyingc/latex_paper_writing_tips


Plots

Tikz Examples

(2024-04-11)

Example of Petar Veličković X

Inkscape

(2024-04-23)


Take Lecture Notes

(2024-04-23)


PseudoCode

(2024-06-01)

  • Curious how to add comments like this: