Scissor LaTeX 中的 array、tabularx、longtable 和 tabulary
array 和 tabularx 套件及相關套件在 Scissor LaTeX 中部分可用:tabularx、tabulary、longtable 和 xltabular 表格會像 tabular 一樣排版,表格比行寬還寬時,長儲存格會自動換行;欄寬(p{3cm}、X、表格寬度)和 >{...}/<{...} 程式碼會被忽略,\newcolumntype 無法辨識,longtable 的標題列也不會重複。
套件的用途
array提供m{width}和b{width}等欄類型、用>{...}和<{...}在每個儲存格前後加入程式碼,以及用來定義自己欄字母的\newcolumntype。tabularx提供\begin{tabularx}{\textwidth}{lX},其中的X欄會延伸,讓表格達到指定的寬度。tabulary也一樣,但使用L、C、R、J欄,依內容分配寬度。longtable讓表格可以跨頁,並有會重複的標題列(\endhead)。xltabular結合了longtable和tabularx。
在這裡可用的功能
| 功能 | 在 Scissor LaTeX 中 | 備註 |
|---|---|---|
tabularx, tabulary, xltabular, longtable, tabular* | 部分支援 | 像 tabular 一樣排版。總寬度參數會被忽略。 |
X、L、C、R、J 欄 | 部分支援 | X 和 L 靠左對齊,C 置中,R 靠右對齊。 |
p{3cm}, m{3cm}, b{3cm} | 部分支援 | 靠左對齊;寬度會被忽略。 |
| 長的儲存格文字 | 可用 | 表格原本會比行寬還寬時會自動換行。 |
>{\bfseries}l, r<{\%} | 忽略 | 儲存格前後的程式碼會被忽略。 |
\newcolumntype{C}{...} | 不支援 | 會被略過並在「問題」分頁中註記,而它的定義會以文字印出。請直接寫出欄類型。 |
\endhead, \endfirsthead, \endfoot, \endlastfoot | 忽略 | 長表格會跨頁,但標題列不會重複。 |
\tabularnewline | 可用 | 和 \\ 相同。 |
\arraybackslash | 不支援 | 會被略過並在「問題」分頁中註記;除此之外沒有影響。 |
範例
有延伸欄的 tabularx 表格。長文字會在文字區的邊緣換行,就像在 TeX 安裝環境中一樣:
有 X 欄的 tabularx
\begin{tabularx}{\textwidth}{lX}
\hline
Name & Notes \\
\hline
Erika Mustermann & Leads the project, writes the reports and checks
every one of the 44 measurements twice before they are published. \\
John Doe & Builds the test setup. \\
\hline
\end{tabularx}有標題列的 longtable。表格可以排版;在長文件中,標題列不會在下一頁重複:
使用 \endhead 的 longtable
\begin{longtable}{lr}
\hline
Item & Count \\
\hline
\endhead
Pencils & 44 \\
Erasers & 12 \\
Rulers & 7 \\
\hline
\end{longtable}>{...} 中的程式碼會被忽略,所以這一欄不是粗體,百分比符號也不見了:
>{...} 和 <{...} 會被忽略
\begin{tabular}{>{\bfseries}l r<{\,\%}}
Growth & 44 \\
Share & 12 \\
\end{tabular}請改把格式寫進儲存格中。這在這裡和 TeX 安裝環境中都能用:
把格式寫進儲存格
\begin{tabular}{lr}
\textbf{Growth} & 44\,\% \\
\textbf{Share} & 12\,\% \\
\end{tabular}相容性
- 從 TeX 安裝環境搬到這裡:表格可以排版並保持對齊,但不會保留欄寬。請留意
\newcolumntype定義的自訂欄字母。 - 從這裡搬到 TeX 安裝環境:文件在那裡不需修改就能編譯,寬度也會在那裡套用。
完整手冊在 CTAN 上:ctan.org/pkg/array、ctan.org/pkg/tabularx、ctan.org/pkg/tabulary、ctan.org/pkg/longtable 和 ctan.org/pkg/xltabular。關於表格的一般說明,請見 LaTeX 表格。
另請參閱表格、multirow、booktabs 和 LaTeX 表格產生器。
常見問題
為什麼我的 p{3cm} 欄寬度不是 3 公分?
欄寬目前還不會套用。長文字仍會在文字區的邊緣換行,所以表格不會超出頁面。
longtable 會跨頁嗎?
會,長表格會在下一頁繼續,但標記為 \endhead 的列不會在那裡重複。
本頁的每個範例都在建置網站時由 Scissor LaTeX 排版。 最後更新:2026-11-07