对 Org 模式表中的列进行永久求和

在 Emacs Org-mode 表中,当你有一列整数时,我知道你可以做 C-c +后跟 C-y来粘贴列中值的和。我想知道公式放在最后一行的 一直都是和整列。

我什么都试过了。 医生告诉你如何把两列相加,但不是一列。

42452 次浏览

Assign a field-name using the ^ mark:

|---+---|
|   | 1 |
|   | 2 |
|   | 3 |
|---+---|
|   | 6 |
| ^ | x |
|---+---|
#+TBLFM: $x=vsum(@1..@-1)

See The Org Manual, Section-3.5.9 Advanced Features.

The last row of a table is @> For example to get the sum for the third column in the last line, you can use the formula

@>$3=vsum(@2..@-1)

Maybe you have to adapt the @2, if you don't have a header line...

Yet another possibility makes use of horizontal lines (@I, @II, etc.) which are useful anyways to structure your table:

| What  |    $$ |
|-------+-------|
| Ice   |  3.00 |
| Soda  |  6.49 |
| Gin   |  4.99 |
|-------+-------|
| Total | 14.48 |
#+TBLFM: @>$2=vsum(@I..@II)

Without a header, hust let the sum start at @0 as suggested by others already.

Edit: I just saw that you wrote this yourself already in a comment to your question.

You can try this:

$<col_num>=<func>(@2..@-1))

@2 is static. It refers to the 2nd row onwards. @-1 refers to the second to last row.

I think this was the easiest and non-intrusive way. It preserves your column names and does not clutter up the visual space. It does not require you to address the last row. It is addressed by default.

Rows can be added/removed. No other markers.

eg.
#+TBLFM: $3=vmean(@2..@-1)::$4=vsum(@2..@-1))

Sample table

   | Time                   | Input             | Test      | InQty |
| <2018-03-13 Tue 06:15> | Water             |           |   200 |
| <2018-03-13 Tue 07:03> |                   |           |       |
|                        |                   |           |       |
| <2018-03-13 Tue 07:31> | Water             |           |   180 |
| <2018-03-13 Tue 09:00> | Chai              |           |   240 |
| <2018-03-13 Tue 11:30> | Chai              |           |   240 |
| <2018-03-13 Tue 16:01> | Water             |           |    60 |
|                        |                   |           |       |
|------------------------+-------------------+-----------+-------|
|                        |                   |           |   920 |
#+TBLFM: $4=vsum(@2..@-1)
|  3 |
|  2 |
|  5 |
| 10 |
#+TBLFM: @4$1=vsum(@1..@-1)

@1 refers to the 1st row, and @-1 to the row preceding the one holding the formula. That formula ignores hlines:

|  3 |
|  2 |
|  5 |
|----|
| 10 |
#+TBLFM: @4$1=vsum(@1..@-1)

Something which may not be apparent to a reader is the function is vsum() not sum()

The other thing, is that the @2..@-1 thing, is a reference to the row-specific label for the column being summed. The $A$1 thing in Excel is like @1$1 so a reference to vsum(@2..@-1) is saying "do a sum of the values from the column, using as the row index the @ value in the range 2, to the -1th (ie second last) row, but the column is a "given" in this so its vsum applied over [@2$col @3$col @4$col... @-1$col] if you try to map these concepts into Excel