LaTeX 学习笔记

文章目录

    • 前言
    • 之前的笔记
    • 如何制作子标题(subtitle)
    • 怎么给目录打点(dotfill)
    • 长字符串自动换行(automatic line breaking)
    • url自动换行
    • 修改页边距
    • 修改列表(item,enumerate)里面的行距
    • 空格(缩进,或者quote中的空格)
    • 显示\n
    • 发现TeXstudio新技能,自动转换代码格式(如\n,)
    • 表格内容居中
    • 添加文本框

标题:LaTeX 学习笔记

前言

最近又要用到latex,之前写过一篇latex相关的笔记文章,但是我感觉还不够,所以在此补充。

本文旨在:
1)对 LaTeX 文档中的各个元素(如\usepackage)进行介绍;
2)其他。(查漏补缺)

之前的笔记

  • LaTex 操作手册 (方便查找) https://blog.csdn.net/weixin_39278265/article/details/88406290
    写作日期:2019年04月10日
  • [LaTeX] jpg转eps https://blog.csdn.net/weixin_39278265/article/details/88708117
    写作日期:2019年03月21日
  • LaTeX (MikTeX+TeXstudio) 在win10上的配置教程 https://blog.csdn.net/weixin_39278265/article/details/81348752
    写作日期:2018年08月01日

如何制作子标题(subtitle)

一开始搜 latex small title ,second title 。。。有点尬。

实际上是:latex subtitle

  • How to set maintitle and subtitle? [duplicate] https://tex.stackexchange.com/questions/153169/how-to-set-maintitle-and-subtitle/279167

LaTeX 学习笔记_第1张图片

这样就行。\large

怎么给目录打点(dotfill)

搜索关键字:latex table of contents dotfill

  • Table of contents not dotfilling? https://tex.stackexchange.com/questions/101695/table-of-contents-not-dotfilling

加上这两行就行。

\usepackage{tocloft}

\renewcommand\cftsecleader{\cftdotfill{\cftdotsep}}

效果:

LaTeX 学习笔记_第2张图片

长字符串自动换行(automatic line breaking)

搜索:;latex long string
(我的关键词有点。。。弱)

  • Automatic line breaking of long lines of text? https://tex.stackexchange.com/questions/33526/automatic-line-breaking-of-long-lines-of-text

主要靠这个:
\usepackage{seqsplit}

url自动换行

关键词:latex url line break
(也有点挫。。)

解决方案:

\PassOptionsToPackage{hyphens}{url}\usepackage{hyperref}

\usepackage{xurl}

二者缺一不可,用了之后感觉还挺好看的。。。链接变好看了。。。(终于知道别人文章里面的框框是怎么来的了)

  • Forcing linebreaks in \url https://tex.stackexchange.com/questions/3033/forcing-linebreaks-in-url

这个latex社区还是强,什么都有,还很详细。

修改页边距

关键词:latex margins
(不是很准确。凑合…)

  • How can I change the margins in LaTeX? http://kb.mit.edu/confluence/pages/viewpage.action?pageId=3907057

我的设定是:
\usepackage[margin=1.2in]{geometry}

还是很方便的,不喜欢太复杂的方案。一切从简。

修改列表(item,enumerate)里面的行距

关键词:latex enumerate distance

  • Reduce space between enumerated items https://tex.stackexchange.com/questions/6081/reduce-space-between-enumerated-items

方案1:

\vspace{-0.2cm} + \itemsep0em

\vspace{-0.2cm}
\begin{enumerate}
	\itemsep0em 
	\item 跨站脚本(Cross-site Scripting);
	\item 不恰当身份验证(Improper Authentication);
	\item 信息披露(Information Disclosure);
	\item 提权(Privilege Escalation);
	\item SQL注入(SQL Injection);
	\item 代码注入(Code Injection);
	\item 服务器端请求伪造 (Server-side Request Forgery);
	\item 不安全直接对象引用 (Insecure Direct Object Reference);
	\item 不恰当访问控制(Improper Access Control);
	\item 跨站请求伪造(Cross-site Request Forgery)。
\end{enumerate}

方案2:
前提是:\usepackage{enumitem} 先添加这个包,
然后在\begin{enumerate}后面加上[noitemsep]就行。如下:

\begin{enumerate}[noitemsep]

\end{enumerate}

我更喜欢方案1,因为灵活。

空格(缩进,或者quote中的空格)

\begin{quote}
	\#include \\
	\#include \\
	asmlinkage long sys\_deheng\_test(int arg0)\{
	
	\hspace{0.7cm} printk("I am syscall");
	
	\hspace{0.7cm} printk("syscall arg \%d",arg0);
	
	\hspace{0.7cm} return ((long)arg0);\\
	\}\\
	asmlinkage long sys\_hello(void)\{\\
		printk("hello my kernel worldn");\\
		return 0;\\
	\}\\
	asmlinkage long strcpy\_deheng(char*dest, const char* src)\\
	\{\\
		int i=0;\\
		while(src[i]!=0)\\
		dest[i]=src[i++];\\	
		dest[i]=0;\\
		return i;\\
	\}\\
	
\end{quote}

要注意的地方:
1)要缩进,上一行就不能打\\,应该用空行代替。
2)\quad\hspace{0.7cm} 都可以。

LaTeX 学习笔记_第3张图片

参考:

  • Line breaks and blank spaces https://www.overleaf.com/learn/latex/Line_breaks_and_blank_spaces#Horizontal_blank_spaces

显示\n

关键词:latex print \n

%----------------------------------------------------------------
\usepackage{lmodern}
\newcommand*{\escape}[1]{\texttt{\textbackslash#1}}
%----------------------------------------------------------------


	\hspace{0.7cm} printk("I am a syscall.\escape{n}");
	
	\hspace{0.7cm} printk("Syscall arg is: \%d\escape{n}",arg0);

在这里插入图片描述

参考:

  • How can I print escape characters in LaTeX? [duplicate] https://tex.stackexchange.com/questions/108865/how-can-i-print-escape-characters-in-latex

此外,使用\textbackslash也可以输出\

发现TeXstudio新技能,自动转换代码格式(如\n,)

原代码:


#include 
#include 
#include 
int main(int argc,char **argv)
{
        printf("\nTest sys_deheng(a self-defined system call) now:\n\n");
        syscall(337,1337);

	printf("\n");
	syscall(338);

//	char *dest=NULL,*src="HelloDeheng";
	char *dest=NULL,*src=argv[1];

	printf("\n\nBefore copy:%s\n",dest);

	dest=(char*)malloc(strlen(src)+1);
	syscall(339,dest,src);
	printf("After copy:%s\n",dest);

        return 0;
}

在复制这段代码后,在TeXstudio中按下:crtl+shift+v,即可得到如下自动转换的格式,太强了!!!
LaTeX 学习笔记_第4张图片

表格内容居中

  • Horizontal and vertical alignment int tabular cell https://stackoverflow.com/questions/25163873/horizontal-and-vertical-alignment-int-tabular-cell

(还是很厉害的,简单有效。)

\begin{table}[!ht]
	\centering
	\sffamily \begin{tabularx}{1\textwidth}{>{\centering\arraybackslash}m{3cm}|>{\centering\arraybackslash}m{11cm}}
%	{p{3cm}<{\centering}p{11cm}<{\centering}}
%	p{2cm}<{\centering}p{1.5cm}<{\centering}
	\hline\hline\noalign{\smallskip}
    \textbf{搜索关键词}&\textbf{搜索结果}\\
\noalign{\smallskip} \hline \noalign{\smallskip}
    Linux内核漏洞 & 直至第四页才看到相关新闻:"Linux内核曝出'脏奶牛'漏洞:已存在9年,数百万用户受影响" \url{https://www.ithome.com/html/it/266554.htm} \\
    \noalign{\smallskip} \hline \noalign{\smallskip}
    Linux内核经典漏洞 & 第二页最后一个搜索结果显示上述新闻  \\
    \noalign{\smallskip} \hline \noalign{\smallskip}
    Linux内核漏洞 提权 & 第二页第一个为:"linux本地内核提权漏洞 Dirty COW 成因分析" \url{https://blog.csdn.net/softgmx/article/details/79772772} 在该链接中,CSDN社区又提供了一大片有关脏牛漏洞的描述,如复现过程,调试过程等等 \\
    \noalign{\smallskip} \hline \noalign{\smallskip}
    linux kernel 4.4.6 vulnerability & 在第一页能发现:"Dirty COW (CVE-2016-5195)" \url{https://dirtycow.ninja/} 等四个和dirty cow相关的搜索结果 \\ 
    \noalign{\smallskip} \hline \noalign{\smallskip}
    linux kernel vulnerability & 第一页仅含"Dirty COW" \url{https://en.wikipedia.org/wiki/Dirty\_COW}一个网页 \\
\hline\hline
\end{tabularx}\normalfont
\caption{搜索关键词及其结果} \label{tab-search}
\end{table}

\begin{table}[h]
	\centering
	\sffamily \begin{tabularx}{1\textwidth}{>{\centering\arraybackslash}m{3cm}|>{\centering\arraybackslash}m{3.7cm}|>{\centering\arraybackslash}m{3.7cm}}
		\hline
		~ & \textbf{Helpful} & \textbf{Harmful} \\
		\hline
		\textbf{Internal origin} (organization) & Item 1 ~\textbullet~ Item 2 ~\textbullet~ Item 3 ~\textbullet~ Item 4 ~\textbullet~ Item 5 ~\textbullet~ Item 6 ~\textbullet~ Item 7 ~\textbullet~ Item 8 ~\textbullet~ Item 9 & Item 1 ~\textbullet~ Item 2 ~\textbullet~ Item 3 ~\textbullet~ Item 4 ~\textbullet~ Item 5 ~\textbullet~ Item 6 ~\textbullet~ Item 7 ~\textbullet~ Item 8 ~\textbullet~ Item 9 \\
		\hline
		\textbf{External origin} (environment) & Item 1 ~\textbullet~ Item 2 ~\textbullet~ Item 3 ~\textbullet~ Item 4 ~\textbullet~ Item 5 ~\textbullet~ Item 6 ~\textbullet~ Item 7 ~\textbullet~ Item 8 ~\textbullet~ Item 9 & Item 1 ~\textbullet~ Item 2 ~\textbullet~ Item 3 ~\textbullet~ Item 4 ~\textbullet~ Item 5 ~\textbullet~ Item 6 ~\textbullet~ Item 7 ~\textbullet~ Item 8 ~\textbullet~ Item 9 \\
		\hline
	\end{tabularx} \normalfont
	\caption{SWOT matrix}
	\label{tab:swot-matrix}
\end{table}



添加文本框

关键词:

latex text box


\vspace{0.5cm}\noindent\fbox{%
	\parbox{\textwidth}{%

adduser deheng

su deheng

cd usr

./poc\_null

}}\vspace{0.5cm}
  • How to put a long piece of text in a box? https://tex.stackexchange.com/questions/25903/how-to-put-a-long-piece-of-text-in-a-box

LaTeX 学习笔记_第5张图片

你可能感兴趣的:(研二下)