在任意长度命令之前加 \the 可以输出该长度的具体值 (pt)。
如:\the\linewidth ==> xxx pt
修改文章字号:
\ninept % use 9pt font size
减少公式块的上下间距:
% reduce the space above and below equations globally
\setlength{\abovedisplayskip}{3pt}
\setlength{\belowdisplayskip}{3pt}
% reduce the space above and below an equation locally
{\setlength\abovedisplayskip{11pt plus 3pt minus 7pt}
\setlength\belowdisplayskip{11pt plus 3pt minus 7pt}
... (Equation) ...
}
减少公式块内部的间距:
在 \\ 之后加入诸如 [-1ex] 或者 [-1em] 的参数,调整行间距
在行内加入 \!,减小相邻符号的间距
允许公式块内多个公式跨页/栏:
% it is better to use this locally
{\allowdisplaybreaks
...
\begin{align}
...
\end{align}
}
减少图片/表格的上下间距:
% reduce the distance between floats on the top or the bottom and the text
\setlength{\textfloatsep}{10pt plus 0.0pt minus 2.0pt}
% reduce the distance between two floats
\setlength{\floatsep}{10pt plus 0.0pt minus 2.0pt}
% reduce the distance between two floats [h]
\setlength{\intextsep}{10pt plus 0.0pt minus 2.0pt}
% reduce the distance between columns in a table
\setlength{\tabcolsep}{1pt}
减小 caption 和表格的间距:
% modify the space between the table and its caption
\usepackage{caption}
\captionsetup[table]{skip=5pt}
\captionsetup[figure]{skip=5pt}
控制表格宽度:
% The two percent signs below are used to remove extra spaces on either side of the table
\begin{table}
...
\resizebox{0.9\columnwidth}{!}{% <------ Don't forget this %
\begin{tabular}
...
\end{tabular}% <------ Don't forget this %
}
\end{table}
控制公式宽度:
\begin{equation}
\resizebox{\columnwidth}{!}{%
$
some formula here
$%
}%
\end{equation}
修改字体大小(慎用):
https://tex.stackexchange.com/a/48277
\fontsize{size}{skip}
Set font size. The first parameter is the font size to switch to; the second is the `\baselineskip` to use. The unit of both parameters defaults to pt. A rule of thumb is that the baselineskip should be 1.2 times the font size.
\fontsize{8.5pt}{10.2pt}\selectfont
手动减小间距:
\vspace{-10pt}
调整参考文献样式:
use et al. for many author paper (say more than five)
将作者列表中想省略的名称替换成 and others,生成的参考文献条目即会自动添加 et al.
自动将超过指定作者数量的参考文献的作者列表截短显示 et al.
参考链接:http://tug.ctan.org/biblio/bibtex/contrib/IEEEtran/IEEEtran_bst_HOWTO.pdf
首先在 tex 文件开头插入:
% redefine the standard IED list environments to their IEEE versions
\usepackage{IEEEtrantools}
并在 \begin{document} 所在行下面加一行:
\bstctlcite{IEEEexample:BSTcontrol} % place this line right below \begin{document}
然后在 bib 文件的开头添加下列代码即可:
% CTLuse_url: whether to display URLs, defult=yes
% CTLdash_repeated_names: Setting this to "no" turns off the use of dashes for entries with names that are identical to those of the previous entry (repeated names); default=yes
% CTLuse_forced_etal: Setting this to "yes" enables IEEEtran.bst to automatically truncate a list of author names and force the use of "et al." if the number of authors in an entry exceeds a set limit; default=no
% CTLmax_names_forced_etal: This value is the maximum number of names that can be present beyond which "et al." usage is forced (if forced "et al." is enabled); default=10
% CTLnames_show_etal: The number of names that are shown with a forced "et al"; must be smaller than CTLmax_names_forced_etal; default=1
@IEEEtranBSTCTL{IEEEexample:BSTcontrol,
CTLuse_url = "yes",
CTLdash_repeated_names = "yes",
CTLuse_forced_etal = "yes",
CTLmax_names_forced_etal = "3",
CTLnames_show_etal = "1"
}
采用会议/期刊名缩写的格式:
% in xxx.bib
@string{icassp = "Proc. IEEE ICASSP"}
@string{interspeech = "Proc. ISCA Interspeech"}
@string{asru = "Proc. IEEE ASRU"}
@string{lrec = "Proc. LREC"}
@string{ieee-taslp = "IEEE Trans. Audio, Speech, anguage Process."}
@string{ieee-acm-taslp = "IEEE/ACM Trans. ASLP."}
@string{icml = "Proc. ICML"}
@string{mlsp = "Proc. MLSP"}
@string{nips = "Proc. NIPS"}
@string{csl = "Comput. Speech Lang."}
@string{slt = "Proc. IEEE SLT"}
@string{acl = "Proc. ACL"}
@string{naacl = "Proc. NAACL"}
@string{emnlp = "Proc. EMNLP"}
采用作者首字母缩写的格式:
\bibliographystyle{IEEEtran}
An easy trick to get a few lines is to remove the page numbers (pp. xxx-xxx) for some of the papers.
减少参考文献的行间距:
% reduce the space between references
\let\oldthebibliography\thebibliography
\let\endoldthebibliography\endthebibliography
\renewenvironment{thebibliography}[1]{
\begin{oldthebibliography}{#1}
\setlength{\itemsep}{0.1em}
\setlength{\parskip}{0.1em}
}
{
\end{oldthebibliography}
}
减小数学符号的大小:
\usepackage{graphicx}
\begin{document}
...
$\scalebox{.7}{$\scriptscriptstyle abc$}$
...
\end{document}
减少每小节标题(section、subsection、subsubsection、paragraph、subparagraph)前后的间距:
\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
% {-3.5ex \@plus -1ex \@minus -.2ex}% default
% {2.3ex \@plus.2ex}% default
{-2.5ex \@plus -1ex \@minus -.2ex}%
{1.75ex \@plus.2ex}%
{\normalfont\Large\bfseries}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
% {-3.25ex\@plus -1ex \@minus -.2ex}% default
% {1.5ex \@plus .2ex}% default
{-1.5ex\@plus -1ex \@minus -.2ex}%
{1.ex \@plus .2ex}%
{\normalfont\large\bfseries}}
\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
{-3.25ex\@plus -1ex \@minus -.2ex}%
{1.5ex \@plus .2ex}%
{\normalfont\normalsize\bfseries}}
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
{3.25ex \@plus1ex \@minus.2ex}%
{-1em}%
{\normalfont\normalsize\bfseries}}
\renewcommand\subparagraph{\@startsection{subparagraph}{5}{\parindent}%
{3.25ex \@plus1ex \@minus .2ex}%
{-1em}%
{\normalfont\normalsize\bfseries}}
\makeatother
为正文中的参考文献和交叉引用添加超链接:
% add hyperlink to citations and references
% hide boxes; add bookmarks; allow auto line break in \url{long_url}
\usepackage[bookmarks=true,hypertexnames=true,pagebackref=true]{hyperref}
\hypersetup{
colorlinks=true, % Colors links instead of ugly boxes
urlcolor=black, % Color for external hyperlinks
linkcolor=blue, % Color of internal links
citecolor=red % Color of citations
}
\usepackage{breakurl}
缩进每节标题下的第一段文字:
% Indent first paragraph after the section header.
\usepackage{indentfirst}
设置图片的标题标签为粗体:
\usepackage[labelfont=bf]{caption} % for the figure and Tables Catption
在行内插入图片
\usepackage{graphicx,scalerel} % for scaling inline figures with vertical center alignment
...
% when used in certain enviroments (e.g. \caption{}), a preceding `\project` is needed to prevent strange errors.
some text \protect\scalerel*{\includegraphics[height=15pt]{figs/yellow_block.pdf}}{\strut} some other text
设置表格的标题标签为粗体:
\usepackage[labelfont=bf]{caption} % for the figure and Tables Catption
生成较复杂的表格:http://www.tablesgenerator.com
在表格中使用脚注,并使脚注显示在页面底部
方法一
在表格中某处放入 \protect\footnotemark
然后在表格之后填写脚注内容:\footnotetext{xxxxx}
方法二
使用 footnote 包提供的 savenotes 环境
...
\usepackage{footnote}
...
\begin{document}
...
\begin{savenotes}
\begin{table}
...
\begin{tabular}
...\footnote{xxx}
\end{tabular}
\end{table}
\end{savenotes}
...
\end{document}
方法三
使用 threeparttable 包提供的 tablenotes 环境
...
\usepackage{threeparttable}
...
\begin{document}
...
\begin{table}[t]
...
\begin{threeparttable}
\begin{tabular}{ll|ccc}
...
\end{tabular}
\begin{tablenotes}[flushleft]\footnotesize
\item[*] The footnote you want to add.
\end{tablenotes}
\end{threeparttable}
\end{table}
...
\end{document}
设置表格中的几个连续列为相同宽度:
参考链接:https://tex.stackexchange.com/a/60604
% for formatting tables
\usepackage{tabularx,booktabs}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
...
% set column 2 - 4 to be equal-width
\begin{tabularx}{\textwidth}{ |c| *{4}{Y|} }
col 1 & col 2 & col 3 & col 4 & col 5 \\
\end{tabularx}
公式块中对部分公式取消编号:
使用 \nonumber 或 \notag 在相应公式行标注即可
...
% in the equaiton environment
line 1 \\
line 2 \notag \\ % do not number this equation
line3 \\
...
修改正文中引用的样式:
默认样式是 [1, 2, 3, ..., 10]
自动合并范围:[1-3, ..., 10]
% change the citation format from [1,2,3] to [1-3]
\usepackage{cite}
手动设置引用参考文献的编号:
Note that when using hyperref you should replace \item by \H@item in the first \xpatchcmd to make it compatible (and hyperref should be imported before the patch).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Customize bibtex numbering
\usepackage{xpatch} % also loads expl3
\makeatletter
\xpatchcmd{\@bibitem}
{\item}
{\item[\@biblabel{\changekey{#1}}]}
{}{}
\xpatchcmd{\@bibitem}
{\the\value{\@listctr}}
{\changekey{#1}}
{}{}
\makeatother
\ExplSyntaxOn
\cs_new:Npn \changekey #1
{
\str_case:nVF {#1} \g_changekey_list_tl { ?? }
}
\cs_new_protected:Npn \setchangekey #1 #2
{
\tl_gput_right:Nn \g_changekey_list_tl { {#1}{#2} }
}
\tl_new:N \g_changekey_list_tl
\cs_generate_variant:Nn \str_case:nnF { nV }
\ExplSyntaxOff
\setchangekey{Knuth1984texbook}{9}
\setchangekey{Chomsky1957}{3}
\setchangekey{Chomsky1965}{7}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
\begin{document}
% Force all references to be listed in the order as in the bib file.
% NOTE: this will also force all references in the bib file to be listed,
% even if they are not cited.
\notice{*}
...
\bibliographystyle{IEEEtran}
\bibliography{xxx}
使用 ~ 来代替空格可以避免交叉引用或者输入人名时尴尬地被打破成两行,例如 如图~\ref{Fig1} 所示,或者 as A.~Einstein said...
斜杠用来表示「或者」的关系时,最好不要简单地使用 /,比如 read/write,因为这样 TeX 会认为这两个单词是一个整体,不允许在它们之间加入断号,导致有些情况下一行文字过密或过疏。这个时候推荐使用 read\slash write,即允许排版时把这两个单词隔在两行。
在正文中输入 LaTeX 特殊符号(如 ~, ^, \ 等):
\textasciitilde % ~ (a raised tilde)
$\sim$ % ~ (a lower and wider tilde)
{\raise.17ex\hbox{$\scriptstyle\sim$}} % ~ (a lower tilde)
\textasciicircum % ^
\textbackslash % \
\textless{} % <
\textgreater{} % >
LaTeX 数学模式中的各种空格符号:
% thin space
\,
\thinspace
% negative thin space
\!
% medium space (\: and \> are equivalent)
\:
\>
% large space
\;
% 0.5em space
\enspace
% 1em space
\quad
% 2em space
\qquad
% custom space
\hspace{3em}
% fill empty space
\hfill
在渲染下划线时确保它是一个字符,而不是空格(默认的 OT1 字体会导致下划线实际复制时变成空格):
% (1) choose a font that is available as T1
% for example:
\usepackage{lmodern}
% (2) specify encoding (you can just try including this package only)
\usepackage[T1]{fontenc}
% (3) load symbol definitions
\usepackage{textcomp}
解决中文生僻字无法在默认字体下正确显示的问题
\usepackage{fontspec}
\newCJKfontfamily\unicodefont{STHeiti}
% \newCJKfontfamily\unicodefont{[/path/to/SourceHanSerifCN-Regular.otf]}
...
{\unicodefont 钱彦旻}
生成带圆圈的文字:
...
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,inner sep=1pt] (char) {#1};}}
...
\begin{document}
...
\circled{1}
...
\end{document}
快速比较两个版本的 tex 文件,并生成相应的 tex 文件:
latexdiff old.tex new.tex > diff.tex # do not use texdiff
删除 tex 文件中的所有注释:
latexpand --empty-comments main.tex > main_nocomments.tex
sed -i '/^\s*%/d' main_nocomments.tex