【1.1】latex入门
>>为了达到自动化对文本标记的目的,花点时间琢磨一下latex,这样标记后的t`ex文件能自动生成.pdf文件。`
(latex的安装略)
拓展阅读:
文档: https://www.tug.org/texlive/doc/texlive-en/texlive-en.html#x1-50001.3
一、安装:
wget -c http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz tar -zxvf install-tl-unx.tar.gz cd install-tl-20180201/ ./install-tl
一、创建一个文本test.tex,保存类型为utf-8
\documentclass{article}
\begin{document}
hello,word
\end{document}
终端运行
xelatex test.tex
二、标题、作者、注释
\documentclass{article}
\author{Sam}
\title{Learn latex}
\begin{document}
\maketitle
hello,word %么么哒
\end{document}
注释掉N行代码
\iffalse
.....
\fi
三、章节和段落
\documentclass{article}
\author{Sam}
\title{Learn latex}
\begin{document}
\maketitle
\section{Hello GenoWise} GenoWise is a great company
\subsection{Hello sam} Sam is here!
\paragraph{Honesty} is Sam's quality.
\subparagraph{Fortune} will be brought by Honesty.
\subsection{Hello Semal}
\paragraph{Smart} is Semal's quality.
\end{document}
内容连续空行
\vspace{1\baselineskip}
修改数字即可控制空行数
四、加目录
\documentclass{article}
\author{Sam}
\title{Learn latex}
\begin{document}
\<span style="color: #ff0000;">tableofcontents</span> %加一个就行,不用每个section前都加
\clearpage %开始新的页
\section{Hello GenoWise} GenoWise is a great company
\subsection{Hello sam} Sam is here!
\paragraph{Honesty} is Sam's quality.
\subparagraph{Fortune} will be brought by Honesty.
\subsection{Hello Semal}
\paragraph{Smart} is Semal's quality.
\end{document}
xelatex **.tex 需要多运行几次,才可以
五、换行
\documentclass{article}
\begin{document}
Sam is
a good boy.
Semal is
also
a good boy.
GenoWise is \\ a great\\
company.
\end{document}
空行代表换行,\\代表打头换行。
六、表格
\documentclass{article}
\begin{document}
\begin{tabular}{|c|c|}
a & b \\
c & d \\
\end{tabular}
\begin{tabular}{|c|c|}
\hline
a & b \\
\hline
c & d \\
\hline
\end{tabular}
\begin{center}
\begin{tabular}{|c|c|}
\hline
a & b \\
\hline
c & d \\
\hline
\end{tabular}
\end{center}
\end{document}
合并水平表格
\begin{tabular}{|c|c|c|c|}
\hline
Location: & \<span style="color: #ff0000;">multicolumn{3}{</span>|c|}{13:111111}\\
\hline
Allele1: & G & Frequency: & 0.111 \\
\hline
Allele2: & C & Frequency & 0.111\\
\hline
\end{tabular}
合并竖直表格
Latex里面的表格默认是没有边框的,如果想要让表格有边框的话需要使用命令进行设置。 Latex插入水平边框的命令是\hline,这会在出现这个命令的表格位置针对整个表格水平范围插入一个水平边框。如果想要在表格的部分内容上面插入水平边框的话可以使用命令\cline{i-j}, 其中i-j指边框跨越i到j这几个单元格。需要注意的是,如果你只需要在一个单元格上面插入边框,你也需要使用{i-i}的格式,i为需要插入的单元格,不能只写{i}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
名字 & 序列 & 长度 & GC & Tm & Delata Tm \\
\hline
Probe1 & CATTGTACCTGCCACAGTAGATGCTC &\multicolumn{2}{|c|}{13:111111} & {\textcolor{red}{60}} &1 \\
\hline
Probe2 & CATTGTACCTGCCACAGTAGATGCTC & 20 & 57 & {\textcolor{red}{60}} &1 \\
\hline
Probe2 & CATTGTACCTGCCACAGTAGATGCTC & 20 & \multirow{2}{*}{57} & {\textcolor{red}{60}} &1 \\
\cline{1-3}
\cline{5-6}
Probe2 & CATTGTACCTGCCACAGTAGATGCTC & 20 & & {\textcolor{red}{60}} &1 \\
\hline
\end{tabular}
注意:
\multicolumn{2}{|c|}{13:111111}
c左右的|,加或者不加,根据左右是否有|来决定
效果如下图
表格内单元格内容强制换行
\newcommand{\tabincell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}%放在导言区
然后使用 &\tabincell{c}{第一行内容\\第二行内容}& 就可以在表格中自动换行
第二种换行的方式
\documentclass{article}
\usepackage{array}
\newcolumntype{L}{>{\centering\arraybackslash}m{3cm}}
\begin{document}
\begin{table}
\begin{tabular}{|L|c|L|}\hline
one & two & three \\\hline
This is two line thing and centered & only one line& \multicolumn{1}{m{3cm}|}{This is justified and may go to second line as well, neatly}\\\hline
one & two & three \\\hline
one & two & three \\\hline
\end{tabular}
\end{table}
\end{document}
参考资料:http://tex.stackexchange.com/questions/54069/table-with-text-wrapping
七、加颜色
\documentclass{article}
\usepackage{color}
\begin{document}
\begin{tabular}{|c|c|}
a & b \\
c & d \\
\end{tabular}
\begin{tabular}{|c|c|}
\hline
a & b \\
\hline
c & d \\
\hline
\end{tabular}
\begin{center}
\begin{tabular}{|c|c|}
\hline
a & b \\
\hline
{\color{red}{c}} & d \\
\hline
\end{tabular}
\end{center}
\end{document}
两点:
\usepackage{color} 调用颜色包
{\color{red}{c}} 对c加颜色
表格中加颜色
用\textcolor{red}{内容}
如果\color{red}{...} 容易导致内容跨行
加背景色
\colorbox{yellow}{yellow background}
\colorbox[rgb]{1,0,0}{red background}
\fcolorbox{blue}{yellow}{red background with a blue frame}
加下划线
\underline{aaaaaa}
八、定义长字符串的宽度
latex不能区分长字符串,出来的都是乱码。
\usepackage{seqsplit}
\newcommand\foo[2]{%
\begin{minipage}{#1}
\seqsplit{#2}
\end{minipage}
}
\foo{\textwidth}
{CCAAGTCGTGTGTTTACCTATATAACAAACTGCACATACATCCCTGAACCTAAAATAAAAGTTAAAATATTTTTAAAAAGAGAGAAACATCAATCCTTAAtATTAACTAAATAGGAAAATACCAGCTTCATAGACAAAGGTTCTCTTTGACTCACCTGCAATAAGTTG{\colorbox{yellow}{CCTTATTAAcgGTATC}}TTCAGAAGAATCAGAT[C/-]CTAAAAAATTTCCCCCCAAAAAATAAATCAATAAAAGTTTTCTTAATTAAAAGGGTTaAAAAAATGTACTTGTTGAAAAACAGATATTCAACTAGAAATATTTACTGAGCATCTACTGTGGCAGGTACAATGCTAGTTAAGCTAGTATGTAATACAGAGAAGTGGTTAAAGGCATGGGCTTCGCCAGGCACAGTGGCTCT}
报错:
! Undefined control sequence
\SQSPL@end
解决办法: 最后一个}要跟字符串在一行,否则就会报错,什么原因,我也没搞清楚。
如果需要在里面给字体加上红色背景或者红色字体,或者下划线,需要
{\underline{AACTGCA}}CATACA{{\color{red}{60}}}TCCC{\colorbox{yellow}{TGAAC}}CT
特别注意color需要外包两层颜色。
九、中文编辑问题
\usepackage{xeCJK, fontspec}
% set font
\setmainfont{Arial}
\setCJKmainfont{Microsoft YaHei}
折腾了半天,最后发现我本地上传的文件是GBK的编辑方式,而服务器默认的是utf-8
dos2unix latex_test.tex
将GBK文档转码成utf-8
Latex 换行顶格、不缩进,使用的命令为: \noindent
十、加空格
如果需要多个空格, 可以使用多个
\hspace{ 长度 } , 例如 \hspace{1cm}
其中的长度单位cm 可以换成 mm, em, in, pt等.
如果\hspace命令在一行的开始则需要改用\hspace*{1cm}来产生空格. 如果要产生垂直方向的空白, 可使用命令
\vspace{ 长度 } 和 \vspace*{ 长度 } , 使用方法同\hspace.
十一、开启新页
\clearpage
十二、加链接跳转
需要加载包
\usepackage{hyperref}
需要跳转到的位置加上label
\label{rs6754640}
需要进行跳转的加上ref
\ref{rs6754640}
十三、插入图片
\usepackage{graphicx}
\includegraphics[width=\linewidth,height=2pt]{图片文件}
出入的图片加入caption
\usepackage{graphicx}
\begin{figure}[htbp]
\centering
\includegraphics[width=\linewidth,height=2pt]{图片文件}\caption{这是图片标题}
\end{figure}
如果在tcolorbox中插入图片
\usepackage{caption}
\usepackage{graphicx}
\begin{minipage}{\linewidth}
\includegraphics[width=\linewidth,height=200pt]{Mean_amplicons_depth_cv.pdf}
\captionof{figure}{Mean-depth and depth-CV of amplicons}
\end{minipage}
参考资料:http://blog.sina.com.cn/s/blog_976290d401014bv1.html
十四、清除一页中的页码标记
\thispagestyle{empty}
十五、调整margin
\usepackage[a4paper]{geometry}
全局的margin
\geometry{
left=0.8cm,
right=0.8cm,
top=2.5cm,
bottom=2.63cm,
footskip=1.48cm,
headsep=.5cm,
headheight=1.5cm
}
单页的margin
\newgeometry{left=0.3cm,right = 0.3cm,top=0.1cm,bottom=0.1cm}
....
\restoregeometry
参考资料
