LaTeX表格绘制备忘之Go语言中的几个表

  以下绘制的表格选自《Go语言 云动力》一书。这些表格比较简单,LaTeX语句也比较简单。

完整代码:

% 博客园陆巍的博客 https://www.cnblogs.com/atthefirst/
\documentclass{article}
%
\usepackage{ctex} % 汉字支持
\usepackage{geometry} % 页面布局支持
\usepackage{array}% 表格增强
\usepackage{tabularx}
\usepackage{booktabs}% 支持表格上下横线加粗
%
% 设置页面为A4纸,并按WPS默认值设置页边距
\geometry{a4paper,left=3.18cm,right=3.18cm,top=2.54cm,bottom=2.54cm}
%
\setlength{\parindent}{2em}% 缩进为两个字符宽度
%
% 表格列居中
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
%
\begin{document}
\begin{center}
  \heiti 表2-1 整数算术操作符表\songti\\
  \begin{tabular}{C{7cm}m{6cm}}
  \bottomrule[2pt]
  + & 加法\\
  - & 减法\\
  $*$ & 乘法\\
  / & 除法取整数商\\
  \% & 除法取余数\\
  \hline
  \& & 按位与\\
  | & 按位或\\
  \textasciicircum & 按位异或\\
  \&\textasciicircum & 按位与非\\
  \hline
  << & 按位左移\\
  >> & 按位右移\\
  \toprule[2pt]
  \end{tabular}
\end{center}
\begin{center}
  \heiti 表2-2 优先级表\songti\\
  \begin{tabular}{C{9cm}m{4cm}}
  \bottomrule[2pt]
  级别 & \hfil 操作符\\
  \hline
  5 & $*$ / \% << >> \& \& \textasciicircum \\
  4 & + - | \textasciicircum \\
  3 & == != < <= > >= \\
  2 & \&\& \\
  1 & || \\
  \toprule[2pt]
  \end{tabular}
\end{center}
\begin{center}
  \heiti 表2-3 一元操作符表\songti\\
  \begin{tabular}{C{6cm}m{7cm}}
  \bottomrule[2pt]
  操作符 & \hfil 代表\\
  \hline
  + & 忽略,+(-1)==-1 \\
  - & 以负数,-(-1)==1 \\
  ! & 逻辑非,!true == false\\
  \textasciicircum & 逐位取反,\textasciicircum 0 == 1\\
  $*$ & 取指针变量的值,$*$p是变量p指向的值\\
  \& & 取变量的指针,\& p是变量p的指针\\
  <- & 通信操作。发送或者接收\\
  \toprule[2pt]
  \end{tabular}
\end{center}
\begin{center}
  \heiti 表2-4 转义字符表\songti\\
  \begin{tabular}{C{9cm}m{4cm}}
  \bottomrule[2pt]
  字符 & \hfil 表示\\
  \hline
  $\setminus$a & 铃音\\
  $\setminus$b & 退格\\
  $\setminus$f & 进表\\
  $\setminus$n & 换行\\
  $\setminus$r & 回车\\
  $\setminus$t & 横向制表\\
  $\setminus$v & 纵向制表\\
  $\setminus\setminus$ & 反斜线\\
  $\setminus$' & 单引号\\
  \toprule[2pt]
  \end{tabular}
\end{center}
\begin{center}
  \heiti 表2-5 切片操作\songti\\
  \begin{tabular}{m{4cm}|m{9cm}}
  \bottomrule[2pt]
  添加切片b & a = append(a, b...)\\
  \hline
  复制 & b = make([]T, len(a))\newline copy(b, a)\\
  \hline
  删除[i:j] & a = append(a[:i], a[j:]...)\\
  \hline
  删除第i个元素 & a = append(a[:i], a[i+1:]...)\\
  \hline
  扩展j个空元素 & a = append(a, make([]T, j)...)\\
  \hline
  插入j个空元素 & a = append(a[:i], append(make([]T, j), a[i:]...)...)\\
  \hline
  插入元素x & a = append(a[:i], append([]T(x), a[i:]...)...)\\
  \hline
  插入切片b & a = append(a[:i], append(b, a[i:]...)...)\\
  \hline
  弹出最后一个元素 & x, a = a[len(a)-1], a[:len(a)-1]\\
  \hline
  压入x & a = append(a, x)\\
  \toprule[2pt]
  \end{tabular}
\end{center}
\end{document}

效果如下
LaTeX表格绘制备忘之Go语言中的几个表_第1张图片

LaTeX表格绘制备忘之Go语言中的几个表_第2张图片

LaTeX表格绘制备忘之Go语言中的几个表_第3张图片

LaTeX表格绘制备忘之Go语言中的几个表_第4张图片

LaTeX表格绘制备忘之Go语言中的几个表_第5张图片

说明

  1、固定宽度列的居中方法是通过\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}实现的。

  2、在绘制表2-5时,有一行的内容存在换行,使用\newline命令实现。

你可能感兴趣的:(LaTeX表格绘制备忘之Go语言中的几个表)