如何在LaTeX中定义可包装的单元格大小?

时间:2018-07-27 16:06:13

标签: latex tabular

我已在LaTex中创建了下表,其中包含Package wrapfigure中的包装表。

\documentclass[a4paper,11pt,oneside,numbers=noendperiod,setspace,parskip=half]{scrbook}
\usepackage[ngerman, english]{babel}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{wrapfig}
\usepackage[table,xcdraw]{xcolor}
\begin{document}

\blindtext

\begin{wraptable}{l}{8cm}
    \begin{tabular}{lcccc}
\hline
\rowcolor[HTML]{656565} 
\multicolumn{1}{|c|}{\cellcolor[HTML]{656565}{\color[HTML]{FFFFFF}
\textbf{Surface geometry}}} & \multicolumn{4}{c|}{\cellcolor[HTML]{656565}{\color[HTML]{FFFFFF} \textbf{Terrain Classes}}} \\ \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{@{}l@{}}fine texture,\\ high convexity\end{tabular}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{643403}\textbf{1}} & \multicolumn{1}{c|}{\cellcolor[HTML]{F8A102}\textbf{5}} & \multicolumn{1}{c|}{\cellcolor[HTML]{009901}\textbf{9}} & \multicolumn{1}{c|}{\cellcolor[HTML]{34FF34}\textbf{13}} \\ \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{@{}l@{}}fine texture,\\ low convexity\end{tabular}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{CE6301}\textbf{3}} & \multicolumn{1}{c|}{\cellcolor[HTML]{FFCC67}\textbf{7}} & \multicolumn{1}{c|}{\cellcolor[HTML]{34CDF9}\textbf{11}} & \multicolumn{1}{c|}{\cellcolor[HTML]{3531FF}\textbf{15}} \\ \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{@{}l@{}}coarse texture,\\ low convexity\end{tabular}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{F007F4}\textbf{2}} & \multicolumn{1}{c|}{\cellcolor[HTML]{A34894}\textbf{6}} & \multicolumn{1}{c|}{\cellcolor[HTML]{C5C783}\textbf{10}} & \multicolumn{1}{c|}{\cellcolor[HTML]{FCFF2F}\textbf{14}} \\ \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{@{}l@{}}coarse texture,\\ low convexity\end{tabular}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{F690E5}\textbf{4}} & \multicolumn{1}{c|}{\cellcolor[HTML]{F6C8EC}\textbf{8}} & \multicolumn{1}{c|}{\cellcolor[HTML]{DFE360}\textbf{12}} & \multicolumn{1}{c|}{\cellcolor[HTML]{FFFC9E}\textbf{16}} \\ \hline
& \multicolumn{1}{l}{\textit{steep}} & \multicolumn{2}{l}{} & \multicolumn{1}{l}{\textit{gentle}}
\end{tabular}
\end{wraptable}

\blindtext

\end{document}

当前看起来像这样:

文档中的表格:
Table in document

如何为所有“地形类别” 1至16更改或设置列的特定单元格大小?像所有单元格一样宽1.5厘米吗?

1 个答案:

答案 0 :(得分:0)

这是我建议对您的代码进行的更改:

  1. 将表格命令更改为固定宽度的列
  2. 将单元格从\multicolumn{1}{c}{<stuff>}更改为简单的<stuff>
  3. 将表格行末尾的\\更改为\tabularnewline

我还可以选择1厘米而不是1.5厘米(太宽),并增加包装尺寸以容纳更宽的桌子。

\documentclass[a4paper,11pt,oneside,numbers=noendperiod,setspace,parskip=half]{scrbook}
\usepackage[ngerman, english]{babel}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{wrapfig}
\usepackage[table,xcdraw]{xcolor}
\begin{document}

\blindtext

\begin{wraptable}{l}{10cm}
    \begin{tabular}{|l*{4}{|>{\centering}p{1cm}}|}
\hline
\rowcolor[HTML]{656565} 
\multicolumn{1}{|c|}{\cellcolor[HTML]{656565}{\color[HTML]{FFFFFF}
\textbf{Surface geometry}}} & \multicolumn{4}{c|}{\cellcolor[HTML]{656565}{\color[HTML]{FFFFFF} \textbf{Terrain Classes}}} \\ \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{@{}l@{}}fine texture,\\ high convexity\end{tabular}}} & 
\cellcolor[HTML]{643403}\textbf{1} & 
\cellcolor[HTML]{F8A102}\textbf{5} & 
\cellcolor[HTML]{009901}\textbf{9} & 
\cellcolor[HTML]{34FF34}\textbf{13} \tabularnewline \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{@{}l@{}}fine texture,\\ low convexity\end{tabular}}} & 
\cellcolor[HTML]{CE6301}\textbf{3} & 
\cellcolor[HTML]{FFCC67}\textbf{7} & 
\cellcolor[HTML]{34CDF9}\textbf{11} & 
\cellcolor[HTML]{3531FF}\textbf{15} \tabularnewline \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{@{}l@{}}coarse texture,\\ low convexity\end{tabular}}} & 
\cellcolor[HTML]{F007F4}\textbf{2} & 
\cellcolor[HTML]{A34894}\textbf{6} & 
\cellcolor[HTML]{C5C783}\textbf{10} & 
\cellcolor[HTML]{FCFF2F}\textbf{14} \tabularnewline \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{@{}l@{}}coarse texture,\\ low convexity\end{tabular}}} & 
\cellcolor[HTML]{F690E5}\textbf{4} & 
\cellcolor[HTML]{F6C8EC}\textbf{8} & 
\cellcolor[HTML]{DFE360}\textbf{12} & 
\cellcolor[HTML]{FFFC9E}\textbf{16} \tabularnewline \hline
\multicolumn{1}{l}{} & \multicolumn{1}{l}{\textit{steep}} & \multicolumn{2}{l}{} & \multicolumn{1}{l}{\textit{gentle}}
\end{tabular}
\end{wraptable}

\blindtext

\end{document}

结果如下:

enter image description here