最近在用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}
效果圖
換行實現了,再看第一列,符號沒有居中對齊。
2、左對齊垂直居中的問題
我們只要把上述關鍵代碼改爲:
關鍵代碼:\begin{tabular}{|l|m{7.3cm}|}
即p改爲m,應該m是一個居中的意思。
效果如下圖