This page looks best with JavaScript enabled

Latex编写指南

 ·  ☕ 3 min read

VSCode + Latex

  • 在VScode中安装Latex Workshop插件

  • VScode 中 Ctrl + Shift + P 打开用户设置 (>Preference: Open user setting json)

  • 添加编译工具 (latex-workshop.latex.tools) 和编译方案 (latex-workshop.latex.recipes)

 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
{
    "latex-workshop.latex.tools": [
        {
            "name": "xelatex", 
            "command": "xelatex",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "%DOCFILE%"
            ]
        },
        {
            "name": "pdflatex",
            "command": "pdflatex",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "%DOCFILE%"
            ]
        },
        {
            "name": "bibtex",
            "command": "bibtex",
            "args": [
                "%DOCFILE%"
            ]
        }
    ],
 "latex-workshop.latex.recipes": [
        {
            "name": "xelatex",
            "tools": [
                "xelatex"
            ],
        },
        {
            "name": "pdflatex",
            "tools": [
                "pdflatex"
            ]
        },
        {
            "name": "xe->bib->xe->xe",
            "tools": [
                "xelatex",
                "bibtex",
                "xelatex",
                "xelatex"
            ]
        },
        {
            "name": "pdf->bib->pdf->pdf",
            "tools": [
                "pdflatex",
                "bibtex",
                "pdflatex",
                "pdflatex"
            ]
        }
    ],
}
  • 其他设置
1
2
"latex-workshop.latex.autoBuild.run": "onFileChange", ## 保存tex文件时自动编译
"latex-workshop.latex.autoBuild.run": "never",        ## 我选择保存不编译

Trick

引用子图片

[https://wenda.latexstudio.net/q-1405.html]

使用subfig宏包的办法:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
\documentclass[journal]{IEEEtran}
\usepackage{graphicx}

\usepackage{subfig}
\captionsetup[subfigure]{labelformat=simple}
\renewcommand\thesubfigure{(\alph{subfigure})}

\usepackage{hyperref}
\newcommand{\subfigureautorefname}{Fig.} % the name is sub-figure-auto-ref-name

\usepackage{mwe}  % for use of sample images
\begin{document}
\begin{figure}[!t]
    \centering
    \subfloat[]{\includegraphics[width=2.5in]{example-image-a}\label{A}}
    \\
    \subfloat[]{\includegraphics[width=2.5in]{example-image-b}\label{B}}
    \caption{LETTER }
    \label{LETTER}
\end{figure}  

The letter A is shown in \autoref{A}
\end{document}

使用subcaption宏包:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
\documentclass[journal]{IEEEtran}
\usepackage{graphicx}

% ref: https://tex.stackexchange.com/a/512010
\usepackage{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}
\captionsetup[sub]{labelformat=simple}

\usepackage{hyperref}
\renewcommand{\figureautorefname}{Fig.}

\usepackage{mwe}  % for use of sample images
\begin{document}
\begin{figure}[!t]
 \centering
 \subfloat[]{\includegraphics[width=2.5in]{example-image-a}\label{A}}
 \\
 \subfloat[]{\includegraphics[width=2.5in]{example-image-b}\label{B}}
 \caption{LETTER }
 \label{LETTER}
\end{figure}  

The letter A is shown in \autoref{A}
\end{document}

旋转图片

1
2
3
4
5
6
7
8
\usepackage{rotating}

\begin{sidewaysfigure}
  \centering
  \includegraphics[width=0.99\textwidth]{./figures.pdf}
  \caption{Caption Here.}
  \label{fig:workflow}
\end{sidewaysfigure}

表格的大小

  1. 调整宽度:设置列间距
1
2
3
\setlength{\tabcolsep}{7mm}{
    Tabular...
}
  1. 调整高度:设置行间距
1
2
3
4
5
\begin{table}
    \renewcommand\arraystretch{1.2}
    \begin{tabular}
    \end{tabular}
\end{table}

不建议使用,效果不太好,会好多东西挤在一块,字体也会一块缩放

1
2
3
4
5
6
\begin{adjustbox}{width=.48\textwidth}{
    \begin{tabular}  
    ...
    \end{tabular}  
}
\end{adjustbox}

ERROR

IEEE Template Xlatex 字体警告

最开始没发现这个问题,论文初稿也是这么提交的。结果文章中了之后在提交Camera Ready的时候感觉模板中的标题和自己文章的标题总感觉不是一个字体,这才发现了这个警告:

Font shape `TU/ptm/b/it' undefined (Font)	using `TU/ptm/bx/it' instead.

原因是xelatex缺少了某些字体,导致编译后的文章出现了字体错误

网上的解决办法大多是使用pdflatex,但是这里因为字符编码原因没办法使用pdflatex

然后找到了原因和解决办法,上述报错的这个字体是pdflatex中独有的,所以换成xelatex的就可以了,使用库:

1
\usepackage[OT1]{fontenc}

https://tex.stackexchange.com/questions/358261/latex-font-warning-after-updating-to-texlive-2016

IEEE hyperref 无法链接参考文献

编写Trans.文章的过程中法线,即使添加了hyperref的库,引用仍然是黑色的,并且没有链接

找到原因 https://blog.csdn.net/nkhgl/article/details/100108833, 发生在ieeeconf.cls下

解决办法:https://tex.stackexchange.com/questions/247104/hyperref-doesnt-link-cite-command

1
2
3
\makeatletter
\let\NAT@parse\undefined
\makeatother

加在\usepackage[colorlinks,citecolor=green]{hyperref}之前

IEEE 摘要对齐错误

https://blog.csdn.net/weixin_42998214/article/details/120048716

需要对文本进行两端对齐时:

1
\usepackage{ragged2e}

在需要对齐的文字前面添加 \justifying,如:

1
2
3
4
\justifying
\begin{abstract}
...
\end{abstract}

IEEE 引用子图 Fig.1a -> Fig.1(a)

https://blog.csdn.net/xdzhujy/article/details/120752598

在\begin{document}之前插入以下几句代码:

1
2
3
4
\usepackage[labelformat=simple]{subcaption}
\captionsetup[sub]{font=footnotesize}
\captionsetup[figure]{name={Fig.},labelsep=period,font=footnotesize} 
\renewcommand\thesubfigure{(\alph{subfigure})}

Subfigure 错误

IEEE 模板中想要添加子图,使用了\subfigure,想当然的添加了\usepackage{subfigure},结果导致了下述错误:

1
Missing number, treated as zero. <to be read again> 
1
Illegal unit of measure (pt inserted).

https://xovee.blog.csdn.net/article/details/106600220

导致的原因貌似是因为subfigure包太过久远,解决办法就是把*\usepackage{subfigure}替换成最新的\usepackage{subcaption}*就可以了

ACM Reference Format

ACM 的 Latex 模板会有ACM Reference的信息,所以需要去掉

在 \documentclass[sigconf]{acmart} 下面添加以下字段:

1
2
3
\settopmatter{printacmref=false} % Removes citation information below abstract
\renewcommand\footnotetextcopyrightpermission[1]{} % removes footnote with conference information in first column
\pagestyle{plain} % removes running headers
Share on

MiaoMiaoYang
WRITTEN BY
MiaoMiaoYang