前言
这里把常用的LaTeX的知识总结一下:
设置页面大小
\documentclass[a4paper]{article}
这是设置纸张大小为A4纸。
设置页面边距
\usepackage{geometry}
\geometry{left=3.18cm,right=3.18cm,top=2.54cm,bottom=2.54cm}
\begin{document}
LaTex
\end{document}
使用包geometry,然后就可以设置了。
插入C++等语言的代码
\documentclass[a4paper]{article}
\usepackage{listings}
\lstset{breaklines} %让LaTeX自动将长的代码行换行排版
\lstset{extendedchars=false} %这一条命令可以解决代码跨页时,章节标题,页眉等汉字不显示的问题
\lstset{language=C++, %用于设置语言为C++
identifierstyle=,
basicstyle=\ttfamily,
stringstyle=\ttfamily,
showstringspaces=false,
%frame=shadowbox, %边框
captionpos=b
}
\begin{document}
\noindent The Code is Here!
\begin{lstlisting}
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello LaTex"<<endl;
}
\end{lstlisting}
\end{document}
使用包listings,然后在这插入代码即可。
\begin{lstlisting}
//Insert your code here!
\end{lstlisting}
这里需要注意的是代码缩进要使用空格,最好不要使用Tab键,否则排版效果超差!
运行结果如下:
设置行距
\documentclass{article}
\usepackage{setspace}
\begin{document}
\begin{spacing}{1.0}
If I were to fall in love,It would have to be with youYour eyes, your smile,The way you laugh,The things you say and do
Take me to the places,My heart never knew
So, if I were to fall in love,It would have to be with you.\\
Ed Walter
\end{spacing}
\begin{spacing}{2.0}
If I were to fall in love,It would have to be with youYour eyes, your smile,The way you laugh,The things you say and do
Take me to the places,My heart never knew
So, if I were to fall in love,It would have to be with you.\\
Ed Walter
\end{spacing}
\end{document}
使用包setspace,运行结果如下:
设置页眉页脚及页码
\documentclass[UTF8]{ctexart}
\usepackage{fancyhdr} % 添加页眉页脚
\begin{document}
\pagestyle{fancy}
\lhead{} %左边页眉
\chead{开始的开始} %中间页眉
\rhead{} %右边页眉
\lfoot{} %页码居左
\cfoot{\thepage} %页码居中
%\rfoot{\thepage} 页码靠右
\renewcommand{\headrulewidth}{0pt} %改为0pt即可去掉页眉下面的横线
\renewcommand{\footrulewidth}{0pt} %改为0pt即可去掉页脚上面的横线
\end{document}