* How to specify column alignment in LaTeX table output? @ 2025-01-09 9:38 Richard H Stanton 2025-01-09 10:17 ` Rens Oliemans 0 siblings, 1 reply; 3+ messages in thread From: Richard H Stanton @ 2025-01-09 9:38 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 1261 bytes --] Here’s a table in my org document: #+ATTR_LATEX: :align rrrr :options [htbp] #+begin_table |-------+--------+-----------+------------| | Tier | Number | Total | % of Total | |-------+--------+-----------+------------| | 1 | 4 | 8,700.00 | 57.39 | | 2 | 19 | 5,398.00 | 35.61 | | 3 | 24 | 1,061.40 | 7.00 | |-------+--------+-----------+------------| | Total | 47 | 15,159.40 | 100.00 | |-------+--------+-----------+------------| #+end_table I want all the columns to be right-aligned (as they are in the org document), but when exported to LaTeX/PDF, the “Total” column in the output table is left aligned instead. Here’s the relevant section of the .tex document generated during PDF export: \begin{table}[htbp] \begin{center} \begin{tabular}{rrlr} \hline Tier & Number & Total & \% of Total\\ \hline 1 & 4 & 8,700.00 & 57.39\\ 2 & 19 & 5,398.00 & 35.61\\ 3 & 24 & 1,061.40 & 7.00\\ \hline Total & 47 & 15,159.40 & 100.00\\ \hline \end{tabular} \end{center} \end{table} What am I missing? If relevant, org-version returns Org mode version 9.8-pre (release_9.7.18-223-g7ef659 @ /Users/stanton/.emacs.d/straight/build/org/) Thanks for any suggestions. [-- Attachment #2: Type: text/html, Size: 2967 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to specify column alignment in LaTeX table output? 2025-01-09 9:38 How to specify column alignment in LaTeX table output? Richard H Stanton @ 2025-01-09 10:17 ` Rens Oliemans 2025-01-09 15:02 ` Richard H Stanton 0 siblings, 1 reply; 3+ messages in thread From: Rens Oliemans @ 2025-01-09 10:17 UTC (permalink / raw) To: Richard H Stanton, emacs-orgmode Richard H Stanton <rhstanton@berkeley.edu> writes: > Here’s a table in my org document: > > #+ATTR_LATEX: :align rrrr :options [htbp] > #+begin_table > |-------+--------+-----------+------------| > | Tier | Number | Total | % of Total | > |-------+--------+-----------+------------| > | 1 | 4 | 8,700.00 | 57.39 | > | 2 | 19 | 5,398.00 | 35.61 | > | 3 | 24 | 1,061.40 | 7.00 | > |-------+--------+-----------+------------| > | Total | 47 | 15,159.40 | 100.00 | > |-------+--------+-----------+------------| > #+end_table > > I want all the columns to be right-aligned (as they are in the org document), but when exported to LaTeX/PDF, the “Total” column in the output table is left aligned instead. Here’s the relevant section of the .tex document generated during PDF export: Remove the #+begin_table and #+end_table parts: table isn't a valid block type. 'C-C C-,' (org-insert-structure-template) shows you what blocks are valid. A table is simply defined via lines starting with '|'. This should work: #+ATTR_LATEX: :align rrrr |-------+--------+-----------+------------| | Tier | Number | Total | % of Total | |-------+--------+-----------+------------| | 1 | 4 | 8,700.00 | 57.39 | | 2 | 19 | 5,398.00 | 35.61 | | 3 | 24 | 1,061.40 | 7.00 | |-------+--------+-----------+------------| | Total | 47 | 15,159.40 | 100.00 | |-------+--------+-----------+------------| Also, I think your :options is a bit weird. Your exported LaTeX code seems fine, but that's a side effect of you having the #+begin_table blocks, I _think_ Org creates a special 'table' environment based on your block name ('table'), which makes your :options work. See "(org) Special blocks in LaTeX export" in the manual. To make your desired placement work with a "correct" table, see "(org) Tables in LaTeX export" and the documentation of ':placement': ‘:float’ ‘:placement’ The table environments by default are not floats in LaTeX. To make them floating objects use ‘:float’ with one of the following options: ‘t’ (for a default ‘table’ environment), ‘sideways’ (for a ‘sidewaystable’ environment), ‘multicolumn’ (to span the table across multiple columns of a page in a ‘table*’ environment) and ‘nil’. In addition to these three values, ‘:float’ can pass through any arbitrary value, for example a user-defined float type with the ‘float’ LaTeX package. LaTeX floats can also have additional layout ‘:placement’ attributes. These are the usual ‘[h t b p ! H]’ permissions specified in square brackets. Note that for ‘:float sideways’ tables, the LaTeX export backend ignores ‘:placement’ attributes. I think that this org snippet is what you are looking for: #+ATTR_LATEX: :align rrrr :float t :placement [htbp] |-------+--------+-----------+------------| | Tier | Number | Total | % of Total | |-------+--------+-----------+------------| | 1 | 4 | 8,700.00 | 57.39 | | 2 | 19 | 5,398.00 | 35.61 | | 3 | 24 | 1,061.40 | 7.00 | |-------+--------+-----------+------------| | Total | 47 | 15,159.40 | 100.00 | |-------+--------+-----------+------------| -- Best, Rens ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to specify column alignment in LaTeX table output? 2025-01-09 10:17 ` Rens Oliemans @ 2025-01-09 15:02 ` Richard H Stanton 0 siblings, 0 replies; 3+ messages in thread From: Richard H Stanton @ 2025-01-09 15:02 UTC (permalink / raw) To: Rens Oliemans; +Cc: emacs-orgmode On Jan 9, 2025, at 2:17 AM, Rens Oliemans <hallo@rensoliemans.nl> wrote: > > Richard H Stanton <rhstanton@berkeley.edu> writes: > >> Here’s a table in my org document: >> >> #+ATTR_LATEX: :align rrrr :options [htbp] >> #+begin_table >> |-------+--------+-----------+------------| >> | Tier | Number | Total | % of Total | >> |-------+--------+-----------+------------| >> | 1 | 4 | 8,700.00 | 57.39 | >> | 2 | 19 | 5,398.00 | 35.61 | >> | 3 | 24 | 1,061.40 | 7.00 | >> |-------+--------+-----------+------------| >> | Total | 47 | 15,159.40 | 100.00 | >> |-------+--------+-----------+------------| >> #+end_table >> >> I want all the columns to be right-aligned (as they are in the org document), but when exported to LaTeX/PDF, the “Total” column in the output table is left aligned instead. Here’s the relevant section of the .tex document generated during PDF export: > > Remove the #+begin_table and #+end_table parts: table isn't a valid block type. > 'C-C C-,' (org-insert-structure-template) shows you what blocks are valid. > > A table is simply defined via lines starting with '|'. This should work: > > #+ATTR_LATEX: :align rrrr > |-------+--------+-----------+------------| > | Tier | Number | Total | % of Total | > |-------+--------+-----------+------------| > | 1 | 4 | 8,700.00 | 57.39 | > | 2 | 19 | 5,398.00 | 35.61 | > | 3 | 24 | 1,061.40 | 7.00 | > |-------+--------+-----------+------------| > | Total | 47 | 15,159.40 | 100.00 | > |-------+--------+-----------+------------| > > Also, I think your :options is a bit weird. Your exported LaTeX code seems fine, > but that's a side effect of you having the #+begin_table blocks, I _think_ Org > creates a special 'table' environment based on your block name ('table'), which > makes your :options work. See "(org) Special blocks in LaTeX export" in the > manual. > > To make your desired placement work with a "correct" table, see "(org) Tables in > LaTeX export" and the documentation of ':placement': > > ‘:float’ > ‘:placement’ > The table environments by default are not floats in LaTeX. To make > them floating objects use ‘:float’ with one of the following > options: ‘t’ (for a default ‘table’ environment), ‘sideways’ (for a > ‘sidewaystable’ environment), ‘multicolumn’ (to span the table > across multiple columns of a page in a ‘table*’ environment) and > ‘nil’. In addition to these three values, ‘:float’ can pass > through any arbitrary value, for example a user-defined float type > with the ‘float’ LaTeX package. > > LaTeX floats can also have additional layout ‘:placement’ > attributes. These are the usual ‘[h t b p ! H]’ permissions > specified in square brackets. Note that for ‘:float sideways’ > tables, the LaTeX export backend ignores ‘:placement’ attributes. > > I think that this org snippet is what you are looking for: > > #+ATTR_LATEX: :align rrrr :float t :placement [htbp] > |-------+--------+-----------+------------| > | Tier | Number | Total | % of Total | > |-------+--------+-----------+------------| > | 1 | 4 | 8,700.00 | 57.39 | > | 2 | 19 | 5,398.00 | 35.61 | > | 3 | 24 | 1,061.40 | 7.00 | > |-------+--------+-----------+------------| > | Total | 47 | 15,159.40 | 100.00 | > |-------+--------+-----------+------------| > > -- > Best, > Rens Thanks, Rens. That works and looks a lot neater than my version, which I arrived at through trial and (mostly) error... I actually generate this table from a Python code block. In the past, I’ve often run into problems with raw output (like this), where running the code block multiple times causes the output to appear multiple times, rather than overwriting. I found that using :wrap seems to prevent this. I have no idea where “:wrap table” comes from, but org exported this without error, so I stopped thinking about it… Trying it with raw output just now, the table seems to be overwritten just fine when I run the code block multiple times. So maybe I don’t need to worry about this any more, but what are the recommended headers for a Python code block that exports a table? For example, ":results output raw” and ":results output drawer” both seem to work (without :wrap), while “:results output” puts everything in an example block, which then seems to get exported verbatim, not as a LaTeX table. Best, Richard ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-09 15:03 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-01-09 9:38 How to specify column alignment in LaTeX table output? Richard H Stanton 2025-01-09 10:17 ` Rens Oliemans 2025-01-09 15:02 ` Richard H Stanton
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.