latex-tables

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

LaTeX Tables with tabularray

使用tabularray制作LaTeX表格

When to Use This Skill

何时使用该技能

Use this skill when:
  • Creating tables with fixed-width columns
  • Formatting complex table layouts
  • Need precise column alignment
  • Migrating from tabular/tabularx/longtable/booktabs
  • Troubleshooting table overflow issues
当你需要以下操作时使用该技能:
  • 创建带固定宽度列的表格
  • 格式化复杂表格布局
  • 需要精确的列对齐
  • 从tabular/tabularx/longtable/booktabs迁移
  • 解决表格溢出问题

Quick Reference

快速参考

Why tabularray?

为什么选择tabularray?

Modern LaTeX3 package (replaces old solutions):
  • Fixed-width columns with proper alignment
  • Clean, consistent syntax
  • Replaces:
    tabular
    ,
    tabularx
    ,
    longtable
    ,
    booktabs
  • Better performance than legacy packages
  • Part of TeX Live 2025

现代LaTeX3包(替代旧解决方案):
  • 支持固定宽度列且对齐方式合理
  • 简洁、一致的语法
  • 可替代:
    tabular
    tabularx
    longtable
    booktabs
  • 比传统包性能更优
  • 已纳入TeX Live 2025

Installation

安装

bash
undefined
bash
undefined

Check if installed

Check if installed

kpsewhich tabularray.sty
kpsewhich tabularray.sty

If not found, install:

If not found, install:

sudo tlmgr install tabularray
undefined
sudo tlmgr install tabularray
undefined

Basic Usage

基础用法

latex
\documentclass{article}
\usepackage{tabularray}  % Modern table package

\begin{document}
% Simple table
\begin{tblr}{colspec={ccc}, hlines, vlines}
  Header 1 & Header 2 & Header 3 \\
  Data 1   & Data 2   & Data 3   \\
\end{tblr}
\end{document}

latex
\documentclass{article}
\usepackage{tabularray}  % Modern table package

\begin{document}
% Simple table
\begin{tblr}{colspec={ccc}, hlines, vlines}
  Header 1 & Header 2 & Header 3 \\
  Data 1   & Data 2   & Data 3   \\
\end{tblr}
\end{document}

Quick Reference Card

快速参考卡片

latex
% Minimal table
\begin{tblr}{colspec={ccc}}
  A & B & C \\
\end{tblr}

% With all lines
\begin{tblr}{colspec={ccc}, hlines, vlines}
  A & B & C \\
\end{tblr}

% Fixed widths
\begin{tblr}{colspec={Q[2cm] Q[3cm] Q[2cm]}, hlines}
  A & B & C \\
\end{tblr}

% Bold header
\begin{tblr}{
  colspec={ccc},
  row{1}={font=\bfseries}
}
  Header & Header & Header \\
  Data   & Data   & Data   \\
\end{tblr}

latex
% Minimal table
\begin{tblr}{colspec={ccc}}
  A & B & C \\
\end{tblr}

% With all lines
\begin{tblr}{colspec={ccc}, hlines, vlines}
  A & B & C \\
\end{tblr}

% Fixed widths
\begin{tblr}{colspec={Q[2cm] Q[3cm] Q[2cm]}, hlines}
  A & B & C \\
\end{tblr}

% Bold header
\begin{tblr}{
  colspec={ccc},
  row{1}={font=\bfseries}
}
  Header & Header & Header \\
  Data   & Data   & Data   \\
\end{tblr}

Best Practices

最佳实践

  1. Use Q[width] for fixed columns instead of p{width}
  2. Specify widths explicitly when text might overflow
  3. Use X for flexible columns that should expand
  4. Style headers with row{1} instead of manual formatting
  5. Use colspec for column properties, not inline commands
  6. Check package version:
    kpsewhich tabularray.sty
    (should be recent)

  1. 使用Q[width]定义固定列,替代p{width}
  2. 当文本可能溢出时,显式指定宽度
  3. 使用X定义可灵活扩展的列
  4. 使用row{1}设置表头样式,替代手动格式化
  5. 使用colspec定义列属性,而非行内命令
  6. 检查包版本:
    kpsewhich tabularray.sty
    (需为最新版本)

Reference Documentation

参考文档

For detailed information, see:
  • Table Patterns - 5 common table patterns with examples
  • Column Specification - Alignment options and width control
  • Lines and Borders - All lines, selective lines, thick lines
  • Troubleshooting - Table too wide, text not wrapping, alignment issues
  • Migration - Migrating from tabular and tabularx
Official Docs: Run
texdoc tabularray
for complete package documentation
See Also:
  • Use
    latex/setup
    skill for installing tabularray package
  • Use
    latex/build
    skill for compilation workflows

如需详细信息,请查看:
  • 表格模式 - 5种常见表格模式及示例
  • 列规格说明 - 对齐选项与宽度控制
  • 线条与边框 - 全线条、选择性线条、粗线条
  • 问题排查 - 表格过宽、文本不换行、对齐问题
  • 迁移指南 - 从tabular和tabularx迁移
官方文档:运行
texdoc tabularray
查看完整包文档
另请参阅
  • 使用
    latex/setup
    技能安装tabularray包
  • 使用
    latex/build
    技能了解编译工作流

Troubleshooting

问题排查

IssueCauseSolution
Package not foundtabularray not installed
sudo tlmgr install tabularray
Table too wideFixed widths exceed pageUse smaller Q[width] values or X for flexible
Text not wrappingColumn spec missing widthUse Q[width] instead of c/l/r for wrapping
Alignment issuesMixed column typesEnsure all columns have consistent spec
Compile error on colspecInvalid syntaxCheck for missing commas or typos in column spec
hlines not appearingMissing from specAdd
hlines
to the spec:
{colspec={...}, hlines}
Row style not appliedWrong row indexRemember row{1} is first row (1-indexed)
Package version too oldTeX Live outdated
sudo tlmgr update --self --all
问题原因解决方案
未找到包未安装tabularray
sudo tlmgr install tabularray
表格过宽固定宽度超出页面范围使用更小的Q[width]值,或用X定义灵活列
文本不换行列规格未指定宽度使用Q[width]替代c/l/r以实现换行
对齐问题列类型混合使用确保所有列的规格一致
colspec编译错误语法无效检查列规格中是否缺少逗号或拼写错误
hlines未显示规格中未包含在规格中添加
hlines
{colspec={...}, hlines}
行样式未应用行索引错误记住row{1}是第一行(从1开始索引)
包版本过旧TeX Live已过时
sudo tlmgr update --self --all