# 表格元素 表格元素用于在幻灯片中创建表格。 ## 基本语法 ```yaml - type: table position: [x, y] col_widths: [2, 2, 2] # 每列宽度(英寸) data: - ["表头1", "表头2", "表头3"] - ["数据1", "数据2", "数据3"] - ["数据4", "数据5", "数据6"] font: family: "Arial" size: 14 color: "#333333" header_font: bold: true color: "#ffffff" style: header_bg: "#4a90e2" ``` ## 属性 | 属性 | 类型 | 必需 | 说明 | |------|------|------|------| | `type` | 字符串 | 是 | 必须为 "table" | | `position` | 数组 | 是 | 表格位置 [x, y](英寸) | | `col_widths` | 数组 | 是 | 每列宽度(英寸) | | `data` | 数组 | 是 | 表格数据(二维数组) | | `font` | 对象 | 否 | 数据单元格字体样式 | | `header_font` | 对象 | 否 | 表头单元格字体样式 | | `style` | 对象 | 否 | 表格样式 | ## 字体配置 ### font(数据单元格) 数据单元格的字体样式: ```yaml font: family: "Arial" size: 14 color: "#333333" bold: false ``` ### header_font(表头单元格) 表头单元格的字体样式。如果未定义,继承 `font` 的配置: ```yaml header_font: bold: true color: "#ffffff" # 其他属性继承自 font ``` ### style(表格样式) ```yaml style: header_bg: "#4a90e2" # 表头背景色 ``` ## 示例 ### 基本表格 ```yaml slides: - elements: - type: table position: [1, 1] col_widths: [2, 2, 2] data: - ["姓名", "年龄", "城市"] - ["张三", "25", "北京"] - ["李四", "30", "上海"] ``` ### 样式化表格 ```yaml slides: - elements: - type: table position: [1, 1] col_widths: [2.5, 2.5, 2.5] data: - ["产品", "价格", "库存"] - ["产品A", "100元", "50"] - ["产品B", "200元", "30"] font: family: "sans" size: 14 color: "#333333" header_font: bold: true color: "#ffffff" style: header_bg: "#3498db" ``` ### 使用字体主题 ```yaml metadata: fonts: table-font: family: "sans" size: 14 color: "#333333" slides: - elements: - type: table position: [1, 1] col_widths: [2, 2, 2] data: - ["列1", "列2"] - ["数据1", "数据2"] font: "@table-font" header_font: parent: "@table-font" bold: true color: "#ffffff" style: header_bg: "#4a90e2" ``` ## 注意事项 - `col_widths` 数组长度必须与每行的列数一致 - 所有行的列数必须相同 - 第一行默认为表头 ## 相关文档 - [字体主题系统](../fonts.md) - 字体配置和主题管理 - [坐标系统](../reference/coordinates.md) - 位置和尺寸单位 [返回文档索引](../README.md)