我有一本 booktabs (longtable) 并且我制作了一列命令我必须手动输入数字 1、2、3……。我怎样才能创建自动计数的列?我的代码是
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{array,longtable,fourier}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{booktabs}
\begin{document}
\begin{longtable}{*{5}{>{$}c<{$}}}
\endfirsthead % blank header on first page
\multicolumn{5}{@{}l}{(\emph{array continued from previous page})}
\endhead
\multicolumn{5}{r@{}}{(\emph{array continued on next page})}
\endfoot
\endlastfoot
\begin{tabular}{@{}cllll@{}}
\toprule[1pt]
Order & point $A$ & point $B$ & point $C$ & point $D$ \\ \midrule
1 & $(1,2,-6)$ & $(1,2,-6)$ & $(1,2,-6)$ & $(1,2,-6)$ \\
2 & $(1,2,-6)$ & $(1,2,-6)$ & $(1,2,-6)$ & $(1,2,-6)$ \\
3 & $(1,2,-6)$ & $(1,2,-6)$ & $(1,2,-6)$ & $(1,2,-6)$ \\ \bottomrule
\end{tabular}
\end{longtable}
\end{document}
答案1
以下解决方案自动在环境主体的第一列中插入行号longtable
,以便使用基本系统交叉引用行\label
。\ref
解决方案的关键部分是创建专用的列类型,N
在下面的代码中调用。
该解决方案还消除了tabular
环境里面环境longtable
。tabular
在 内拥有环境longtable
完全违背了使用环境的目的longtable
,即允许在 内部根据需要进行分页longtable
。
\documentclass[12pt,a4paper]{article}
\usepackage[margin=2cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{fourier} % change font
\usepackage{amsmath,array,longtable,booktabs}
\newcounter{rownum}
\newcolumntype{N}{>{\refstepcounter{rownum}\therownum}l}
\newcolumntype{C}{>{$}c<{$}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macros
\newcommand\ml[1]{\multicolumn{1}{l}{#1}}
\begin{document}
\begin{longtable}{ N *{4}{C} }
%% headers and footers
\toprule[1pt]
\ml{Order} & \mc{point $A$} & \mc{point $B$} & \mc{point $C$} & \mc{point $D$} \\
\midrule
\endfirsthead % blank header on first page
\multicolumn{5}{@{}l}{(\emph{array continued from previous page})}\\
\addlinespace
\ml{Order} & \mc{point $A$} & \mc{point $B$} & \mc{point $C$} & \mc{point $D$} \\
\midrule
\endhead
\midrule
\multicolumn{5}{r@{}}{(\emph{array continued on next page})}
\endfoot
\bottomrule
\endlastfoot
%% body of longtable
%% Note the generally "empty" first column -- empty except for \label directives
& (1,2,-6) & (1,2,-6) & (1,2,-6) & (1,2,-6) \\
& (1,2,-6) & (1,2,-6) & (1,2,-6) & (1,2,-6) \\
& (1,2,-6) & (1,2,-6) & (1,2,-6) & (1,2,-6) \\
& (1,2,-6) & (1,2,-6) & (1,2,-6) & (1,2,-6) \\
\label{row:v} & (1,2,-6) & (1,2,-6) & (1,2,-6) & (1,2,-6) \\
& (1,2,-6) & (1,2,-6) & (1,2,-6) & (1,2,-6) \\
\end{longtable}
A cross-reference to row \ref{row:v} of the table.
\end{document}