一些 LaTeX 技巧

  • 修改数学公式字体
  • 打生僻字
  • 一些数学符号
  • 代码环境

修改数学公式字体

LaTeX - Beamer 中默认字体很难看,以下两种方法均可修改

1
\usefonttheme[onlymath]{serif}
1
\usefonttheme{professionalfonts}

左右结构的生僻字

名字有“喆”的痛苦… 有些字体可能没有这个字.. 既然打不出来“喆”,那“吉”总可以搞定吧,那我打两个一半宽度的“吉”不就好了吗?

实现代码如下:

1
\hbox{\resizebox{1.1ex}{1.8ex}{吉}}\hbox{\resizebox{1.1ex}{1.8ex}{吉}}

其中的高度和宽度可以自行调整。

类似“喆”的左右结构的生僻字都可以用这种方法解决。

一些数学符号

  • 正规子群:\(\trianglelefteq\) \trianglelefteq \(\triangleleft\) \triangleleft
  • 半直积:\(\rtimes\) \rtimes \(\ltimes\) \ltimes
  • 逻辑运算:\(\lnot\) \lnot \(\land\) \land \(\lor\) \lor
  • 映射:\(f: G\to H,~~a \mapsto f(a)\) \mapsto

代码环境

一般用 listings,C++ 的具体配置如下:

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
\usepackage{listings}
\usepackage{xcolor}

\definecolor{CPPLight} {HTML} {686868}
\definecolor{CPPSteel} {HTML} {888888}
\definecolor{CPPDark} {HTML} {262626}
\definecolor{CPPBlue} {HTML} {4172A3}
\definecolor{CPPGreen} {HTML} {487818}
\definecolor{CPPBrown} {HTML} {A07040}
\definecolor{CPPRed} {HTML} {AD4D3A}
\definecolor{CPPViolet} {HTML} {7040A0}
\definecolor{CPPGray} {HTML} {B8B8B8}

\lstset{
columns=fixed,
numbers=left, % 在左侧显示行号
frame=none, % 不显示背景边框
backgroundcolor=\color[RGB]{245,245,244}, % 设定背景颜色
keywordstyle=\color[RGB]{40,40,255}, % 设定关键字颜色
numberstyle=\footnotesize\color{darkgray}, % 设定行号格式
commentstyle=\it\color[RGB]{0,96,96}, % 设置代码注释的格式
stringstyle=\rmfamily\slshape\color[RGB]{128,0,0}, % 设置字符串格式
showstringspaces=false, % 不显示字符串中的空格
language=c++, % 设置语言
morekeywords={alignas,continute,friend,register,true,alignof,decltype,goto,
reinterpret_cast,try,asm,defult,if,return,typedef,auto,delete,inline,short,
typeid,bool,do,int,signed,typename,break,double,long,sizeof,union,case,
dynamic_cast,mutable,static,unsigned,catch,else,namespace,static_assert,using,
char,enum,new,static_cast,virtual,char16_t,char32_t,explict,noexcept,struct,
void,export,nullptr,switch,volatile,class,extern,operator,template,wchar_t,
const,false,private,this,while,constexpr,float,protected,thread_local,
const_cast,for,public,throw,std},
}

2019.09.01 Young 表绘制

核心是去掉一些竖线.

1
2
3
4
5
6
\begin{array}{|cc|}
\cline{1-1} 1 & \multicolumn{1}{|c}{} \\
\hline
2 & 3 \\
\hline
\end{array}

2020.09.25 图片与文字在同一行的对齐问题

似乎默认是最下面对齐的,也就是说文字的最下面和图片的最下面对齐……这可能会导致一些问题。

解决方法有两种:

  1. raisebox(应该是不需要额外宏包了):

    1
    \raisebox{-1em}{\includegraphics{FIGURE.png}} % 调节第一个参数即可

  2. adjustbox 宏包

    1
    2
    3
    \usepackage{adjustbox}
    ...
    \adjustbox{valign=t}{\includegraphics{FIGURE.png}}

参见 https://www.latexstudio.net/archives/6983.html

2020.12.11 控制表格尺寸(宽/高)

1
2
3
4
5
6
7
\begin{tabular}{p{.3\linewidth}<{\flushleft}p{0.05\linewidth}p{.3\linewidth}<{\center}}
\specialrule{0em}{1pt}{1pt}
aaa \hfill 97 & & bbb \hfill 91 \\
\specialrule{0em}{-8pt}{-8pt}
ccc \hfill 95 & & ddd \hfill 95 \\
\specialrule{0em}{-6pt}{-6pt}
\end{tabular}

2021.04.13 行间公式使用 display style

在公式前加 \displaystyle 即可:

1
2
What is $\frac{a}{b}$               -> Inline mode
What is $\displaystyle \frac{a}{b}$ -> Display mode