29

recently I am using table to do some statistics, and I want the first column of the table to indicate the row number, as this.

   |  | title|
   |--| -----|
   | 1| A    |
   | 2| B    |

and I want the number of first column grow automatically after creating a new row.

Are there good suggestions about it?

Luis404
  • 511
  • 5
  • 7
  • 30
    Place `#+tblfm: $1=@#-1` under the table. Now when you move your mouse to the formula and `C-c C-c` on it, it will recalculate the contents of the first column s.a. to create a sequence of increasing integers. – wvxvw Aug 12 '15 at 08:51
  • 1
    wooo, great.... – Luis404 Aug 13 '15 at 01:39
  • 1
    I was looking for exactly the same thing (@#). Sometimes searching is faster than asking... ;-D –  Aug 13 '15 at 03:53
  • It's possible, but time-consuming, to figure this out from the manual by piecing together info from two sections (sometimes asking is faster than searching, reading, and thinking :) Go to the info-mode manual in emacs (`C-h I`), Section 3.5.1 of the manual, in an unnumbered sub-section called "Field coordinates in formulas," explains `@#-1`. Then section 3.5.6, "Column Fomulas," explains the `$1=`. – Reb.Cabin Jul 14 '19 at 17:50
  • 1
    Note that with @wvxvw's answer you can have 0-based indexing with `$1=@#-2`. – colelemonz Jan 02 '20 at 18:12

1 Answers1

32

Press S-ENTER in the first column after having put in '1' or another number and it will auto-increment in a new row. Not quite as clever as a formula, but is easier (for me) to remember.

Stuart Hickinbottom
  • 2,343
  • 14
  • 16