\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{fourier}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\renewcommand*{\arraystretch}{2.0}
\usepackage{longtable}
\setlength\LTleft{15pt}
\setlength\LTright{0pt}
\usepackage{enumerate}
\begin{document}
\begin{longtable}{@{\extracolsep{\fill}}@{}ll}
first line& 1\\
second line & 2\\
add line& 3\\
add line & 4\\
add line& 5\\
add line & 6\\
add line& 7\\
add line & 8\\
add line& 9\\
add line & 10\\
\end{longtable}
\end{document}
现在我想将长篇故事的所有行从 1 到末尾进行编号。我无法自动转换。我手工解决了。
\begin{enumerate}[\quad 1)]
\item first line \hfill 1
\item second line \hfill 2
\item add line \hfill 3
\item add line \hfill 4
\item add line \hfill 5
\item add line \hfill 6
\item add line \hfill 7
\item add line \hfill 8
\item add line \hfill 9
\item add line \hfill 10
\end{enumerate}
答案1
最小化你的例子以消除无关紧要的内容,也许这样的事情会起作用?
\documentclass{article}
\usepackage{array}
\renewcommand*{\arraystretch}{2.0}
\usepackage{longtable}
\setlength\LTleft{15pt}
\setlength\LTright{0pt}
\newcounter{myconversion}
\setcounter{myconversion}{0}
\newcommand*\convertme{\refstepcounter{myconversion}\themyconversion)\hskip 1.5em}
\begin{document}
\begin{longtable}{@{\extracolsep{\fill}}@{}>{\convertme\arraybackslash}ll}
first line& 1\\
second line & 2\\
add line& 3\\
add line & 4\\
add line& 5\\
add line & 6\\
add line& 7\\
add line & 8\\
add line& 9\\
add line & 10\\
\end{longtable}
\end{document}
如果不想让引用受到影响,只需更改\refstepcounter
为\stepcounter
。
要右对齐数字:
\documentclass{article}
\usepackage{array}
\renewcommand*{\arraystretch}{2.0}
\usepackage{longtable}
\setlength\LTleft{15pt}
\setlength\LTright{0pt}
\newcounter{myconversion}
\setcounter{myconversion}{0}
\newcommand*\convertme{\refstepcounter{myconversion}\makebox[1.5em]{\hfill\themyconversion)}\hskip 1em}
\begin{document}
\begin{longtable}{@{\extracolsep{\fill}}@{}>{\convertme\arraybackslash}lr}
first line& 1\\
second line & 2\\
add line& 3\\
add line & 4\\
add line& 5\\
add line & 6\\
add line& 7\\
add line & 8\\
add line& 9\\
add line & 10\\
\end{longtable}
\end{document}
答案2
这是一个简单的解决方案,只需使用行计数器和eqparbox
包来对齐行号。
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{fourier}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\renewcommand*{\arraystretch}{2.0}
\usepackage{longtable, array}
\setlength\LTleft{15pt}
\setlength\LTright{0pt}
\usepackage{eqparbox}
\newcounter{rowno}
\begin{document}
\setcounter{rowno}{0}
\begin{longtable}{@{\extracolsep{\fill}}@{} >{\refstepcounter{rowno}\quad\eqmakebox[R][r]{\therowno)}\hskip\labelsep}ll}
first line & 1 \\
second line & 2 \\
add line & 3 \\
add line & 4 \\
add line & 5 \\
add line & 6 \\
add line & 7 \\
add line & 8 \\
add line & 9 \\
add line & 10 \\
\end{longtable}
\end{document}