LaTeX 中的 array 宏包提供了多种参数和选项,用于自定义表格的各个方面。以下是一些常见的参数和选项,可以设置和调整表格的属性:
-
列格式(Column Format): 您可以使用
c、l、r等来定义列的对齐方式,也可以自定义列格式。例如,|c|l|r|表示三列,分别为居中对齐、左对齐和右对齐,每列都包含竖线作为分隔符。 -
列宽度(Column Width): 使用
p{宽度}可以设置列的固定宽度,例如p{2cm}。使用m{宽度}也可以设置固定高度和宽度的列。 -
列间距(Column Separation): 使用
@{间距}可以定义列之间的间距,例如@{\hspace{1cm}}表示列之间的间距为1厘米。 -
表格宽度(Table Width): 使用
tabular环境的可选参数可以设置表格的总宽度,例如\begin{tabular}{|c|} ... \end{tabular}中的|c|可以设置表格宽度为单元格的总宽度。 -
行高(Row Height): 使用
\extrarowheight命令可以增加行高,以改善表格的可读性。例如,\setlength{\extrarowheight}{10pt}会增加每行的高度。 -
单元格内部对齐(Cell Alignment): 使用
>{\centering}、>{\raggedright}、>{\raggedleft}等命令可以设置单元格内部的文本对齐方式。 -
水平线条(Horizontal Lines): 使用
\hline插入水平线,使用\\换行。使用cline{i-j}可以创建从第 i 列到第 j 列的局部水平线。 -
垂直线条(Vertical Lines): 使用
|插入垂直线,例如|c|l|r|。也可以使用@{}来调整垂直线的位置和间距。 -
多行单元格(Multi-row Cells): 使用
multirow宏包可以创建跨多行的单元格,例如\multirow{2}{*}{内容}。 -
单元格合并(Cell Merging): 使用
\multicolumn{列数}{对齐方式}{内容}可以合并多列单元格,例如\multicolumn{2}{|c|}{合并单元格}。
\begin{document}
\begin{tikzpicture}[font=\huge] % 创建表格
\matrix[ampersand replacement=\&] { \node (species1) [shape=rectangle,draw] {
\begin{tabular}{c c c}
\multicolumn{3}{c}{{Species 1}} \\
\colorbox{red}{G1t} & \colorbox{blue}{G2a} & \colorbox{green}{G3t} \\
\colorbox{blue}{G1b} & \colorbox{red}{G2b} &
\end{tabular}
}; \& \node {b}; \\ \node {c}; \& \node {d}; \\ };
\end{tikzpicture}
\end{document}\begin{document}
\begin{tikzpicture}[scale=5, font=\huge] % 创建表格
\matrix[ampersand replacement=\&]{\node(a){a}; \& \node {b}; \\ \node {c}; \& \node(d) {d}; \\ };
\draw[->](a) -- (d);
\end{tikzpicture}
\end{document}\begin{document}
\begin{tikzpicture}[font=\huge] % 创建表格
\node at(0,0) (a){a};
\node[below] at(10,0) (species1) [shape=rectangle, draw] {
\fontsize{32}{32}\selectfont
\begin{tabular}{ c | c | c}
\multicolumn{3}{c}{{Species 1}} \\
\hline
{G1t} & {G2a} & {G3t} \\
\hline
{G1b} & {G2b} &
\end{tabular}
};
\end{tikzpicture}
\end{document}
\usepackage{array}
\begin{document}
\begin{tikzpicture}[font=\huge] % 创建表格
\node at(0,0) (a){a};
\node[below] at(10,0) (species1) [shape=rectangle, draw] {
\fontsize{32}{32}\selectfont
\begin{tabular}{ c | c | c}
\multicolumn{3}{c}{{Species 1}} \\
\hline
{G1t} & {G2a} & {G3t} \\
\hline
{G1b} & {G2b} &
\end{tabular}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{tabular}{|M{1em}|M{1em}|}
\hline
a & b \\ \hline
c & d \\ \hline
e & f \\ \hline
\end{tabular}
};
\end{tikzpicture}
\end{document}