Latex表格换行垂直居中对齐

最近在用Latex绘制表格,遇到了两个问题,记录一下。

1、一个是某一单元格内容过长,换行的问题

关键代码:\begin{tabular}{|l|p{7.3cm}|}

网上查找说可以用p{}来控制列的宽度,如p{7.3cm}表示控制表格的最大宽度为7.3cm,超过则换行。

上代码:

\begin{table}[H]
\centering
 \caption{\textcolor{red}{Summary of notations.}}
\label{T1}
\begin{tabular}{|l|p{7.3cm}|}
\hline
{\bf \small Notation}& {\bf\small Description}\\
\hline
$G = (N, E)$     & Undirected graph where $N$ is the set of switches and hosts (i.e., servers) and $E$ is the set of links\\
\hline
$S$      &    Set of switches\\
\hline
$H$      &   Set of hosts\\
\hline
$C_{u}$     &  TCAM size of switch $u$\\
\hline
$B_{(u,v)}$     & Capacity of link $(u,v)$\\
\hline
$p(u,v)$      &  Power consumption of link $(u,v)$\\
\hline
$p(u)$      &   Power consumption of switch $u$\\
\hline
$K$     &    Set of all traffic flows, each flow $k\in K$\\
\hline
$r_{k}$      &  Traffic demand by flow $k$ from host $s_{k}$ to $d_{k}$\\
\hline
$X(u,v)$      &  Binary variable indicating whether link $(u,v)$ is powered on\\
\hline
$Y(u)$      &   Binary variable indicating whether switch $u$ is powered on\\
\hline
$f_{uv}^{k}$  &  The amount of flow $k$ that is routed through link $(u,v)$\\
\hline
$x_{uv}^{k}$  &  Binary variable indicating whether flow $k$ goes through switch $u$ on outgoing link $(u,v)$\\
\hline
\end{tabular}
\end{table}

效果图

Latex表格换行垂直居中对齐

换行实现了,再看第一列,符号没有居中对齐。

2、左对齐垂直居中的问题

我们只要把上述关键代码改为:

关键代码:\begin{tabular}{|l|m{7.3cm}|}

即p改为m,应该m是一个居中的意思。

效果如下图

Latex表格换行垂直居中对齐