emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* 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; 12+ 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] 12+ messages in thread
* Re: Re: How to specify column alignment in LaTeX table output?
@ 2025-01-10  6:13 Pedro Andres Aranda Gutierrez
  2025-01-10 17:04 ` Richard H Stanton
  0 siblings, 1 reply; 12+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2025-01-10  6:13 UTC (permalink / raw)
  To: hallo, rhstanton; +Cc: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 1286 bytes --]

Hi,

For org tables generated in Python, I use python-tabulate. Actually, I
forked the original library to include the possibility of generating the
latex attributes from Python too.

Something like:

--- cut here ---
#+BEGIN_SRC python :results value raw :exports results
import math
import pandas as pd
import tabulate

xvals = [math.pi * i / 5 for i in range(10)]
df = pd.DataFrame({
    'x': xvals,
    'sin(x)' : [math.sin(xvals[i]) for i in range (10)],
    'cos(x)' : [math.cos(xvals[i]) for i in range (10)]
})

attrs=':environment longtable :align p{2cm}p{2cm}p{2cm} :placement [h]
:center t'
return tabulate.tabulate(
    df,
    headers=df.columns, tablefmt='orgtbl', floatfmt=".3f",
    caption='Table exported from Python with extended tabulate',
    label='labextend',
    attr_latex=attrs,
    showindex=False)
#+END_SRC
#+RESULTS:
--- cut here ---

Take a look at https://github.com/paaguti/python-tabulate if it sounds
interesting.

CAVEAT: the author of python-tabulate wasn't very excited about this ;-)

Best, /PA
-- 
Fragen sind nicht da, um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet

[-- Attachment #2: Type: text/html, Size: 1948 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-01-10 19:43 UTC | newest]

Thread overview: 12+ 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
2025-01-10  9:47     ` Rens Oliemans
2025-01-10  9:53       ` Rens Oliemans
2025-01-10 16:59       ` Richard H Stanton
2025-01-10 18:59         ` Rens Oliemans
2025-01-10 19:16           ` Richard H Stanton
2025-01-10 19:38           ` Richard H Stanton
2025-01-10 19:45             ` Ihor Radchenko
2025-01-10 19:04         ` Richard H Stanton
  -- strict thread matches above, loose matches on Subject: below --
2025-01-10  6:13 Pedro Andres Aranda Gutierrez
2025-01-10 17:04 ` Richard H Stanton

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).