QQ群:91940767/145316219/141877998/80300084/194770436
淘宝店:http://latexstudio.taobao.com
技巧续篇:http://latexstudio.net/
常见数学公式问题集下载
有些用户想让自己的表格更加美观,精致,做了一些修饰。但是转又一看,表格各个长宽不一不很美观,想让全文的表格都一致宽度该如何处理?
例如:
我想创建两个表具有相同的列的宽度。这两个表包括6个行和3列。在这两个表,第1行和第4行是解释性的,应扩大在各个列。在第一个表,列2,3,5和6应该有三个相同的宽度列。在第二个表,列2和3应该有两列相同的宽度和行5和6应该有三个相同的宽度列。
代码如下:
\begin{table}[h]
\caption{Distribution of mappings for the SLA parameter
$\pi$.}
\label{tab:distPi} \centering
\begin{tabular*}{0.45\textwidth}{@{\extracolsep{\fill}}|c|c|c|}
\hline
\multicolumn{3}{|c|}{\textbf{Name of the SLA parameter $\pi$}}
\\
\hline
\emph{Cost} & \emph{Charge} &
\emph{Rate} \\
\hline
15\% & 15\% & 40\% \\
\hline
\hline
\multicolumn{3}{|c|}{\textbf{Unit of the SLA parameter $\pi$}}
\\
\hline
\emph{USD} & \emph{GBP} &
\emph{YPI} \\
\hline
38\% & 2\% & 40\% \\
\hline
\end{tabular*}
\vspace{-0.3cm}
\end{table}
\begin{table}[h]
\caption{Distribution of mappings for the SLA parameter
$\mu$.}
\label{tab:distMu} \centering
\begin{tabular*}{0.45\textwidth}{@{\extracolsep{\fill}}|c|c|c|c|c|c|}
\hline
\multicolumn{6}{|c|}{\textbf{Name of the SLA parameter $\mu$}}
\\
\hline
\multicolumn{3}{|c|}{\emph{MemoryConsumption}} &
\multicolumn{3}{|c|}{\emph{Consumption}} \\
\hline
\multicolumn{3}{|c|}{70\%} &
\multicolumn{3}{|c|}{30\%} \\
\hline
\hline
\multicolumn{6}{|c|}{\textbf{Unit of the SLA parameter $\mu$}}
\\
\hline
\multicolumn{2}{|c|}{\emph{Mbit}} &
\multicolumn{2}{|c|}{\emph{Gbit}} &
\multicolumn{2}{|c|}{\emph{Tbit}} \\
\hline
\multicolumn{2}{|c|}{5\%} &
\multicolumn{2}{|c|}{55\%} &
\multicolumn{2}{|c|}{40\%} \\
\hline
\end{tabular*}
\vspace{-0.3cm}
\end{table}
得到的效果如下:

【解决方案】
实际上这一问题,涉及到了我们平时不会触碰的重定义表格列格式的内容。这里给出一个样例,我们对表格的列格式进行重定义和新定义,看看怎么样:

演示代码如下:
\documentclass[10pt,letterpaper]{article}
\usepackage{array}
\newlength{\onesixth}
\setlength{\onesixth}{.18 \linewidth}
\setlength{\onesixth}{.5 \onesixth}
\newcolumntype{C}{>{\begin{minipage}{2\onesixth}\begin{center}}{c}<{\end{center}\end{minipage}}}
\newcolumntype{D}{>{\begin{minipage}{3\onesixth}\begin{center}}{c}<{\end{center}\end{minipage}}}
\newcolumntype{E}{@{}l@{}} %I don't understand why this is
needed...but without it the code doesn't compile
\begin{document}
\begin{table}[h]
\caption{Distribution of mappings for the SLA parameter
$\pi$.}
\label{tab:distPi}\centering
\begin{tabular}{|C|C|C|E}
\hline
\multicolumn{3}{|c|}{\textbf{Name of the SLA parameter
$\pi$}}
\\\hline
\emph{Cost} & \emph{Charge}
&\emph{Rate}&
\\\hline
1 & 15 & 40
&\\
\hline
\hline
\multicolumn{3}{|c|}{\textbf{Unit of the SLA parameter $\pi$}}
\\
\hline
\emph{USD} & \emph{GBP} &
\emph{YPI}& \\
\hline
38\% & 2\% & 40\%
&\\
\hline
\end{tabular}
\vspace{-0.3cm}
\end{table}
\begin{table}[h]
\caption{Distribution of mappings for the SLA parameter
$\mu$.}
\label{tab:distMu} \centering
\begin{tabular}{|c|c|c|c|c|c|}