From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id MM8GO41TgWfuRgEAe85BDQ:P1 (envelope-from ) for ; Fri, 10 Jan 2025 17:06:22 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id MM8GO41TgWfuRgEAe85BDQ (envelope-from ) for ; Fri, 10 Jan 2025 18:06:22 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=berkeley.edu header.s=google header.b=hSbicOBC; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=reject) header.from=berkeley.edu ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1736528781; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=NHLnIsUGNrVb5UZOsxR5Ay8np3GXiQT0rvlTqIJllUU=; b=TaO5CfcQaiztHYwV+XOZNBj3e7uGeuFdoUQuqgbuFYA9W75O8O359xNQNzk+7RplnQAn1B buwd2YlFDphE0INzr5oe7lVmb9iNQXv/pqP/EEohYFTl3eySO7Qq6fUP6A6AZlmE9bnN7/ 9fbcbOU3RBUG3/Ir9QPiBgHo8Nt55HasncXd68N6si2a5xfWyrs+np6mrhwI02IuQTwYc3 Vuqft3Enhy0f5P+2d98Qq8lYyh1mAJZ/Ze0Ye8NNnyo/hiW/q9kfMqcVc4kJMYVT17P2ut yHwR3/sAp9s3YBQIwLwg8l4JWro8CJH8VzvH4yO9HaYPuV3gssUYMXarCRfr+g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=berkeley.edu header.s=google header.b=hSbicOBC; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=reject) header.from=berkeley.edu ARC-Seal: i=1; s=key1; d=yhetil.org; t=1736528781; a=rsa-sha256; cv=none; b=TW++3GJs2h+Azmx09LPjSxZHrK/LgzcRiQZXMQBKtoZoj6kwHG4OJyN1Fpm8UPT56Fnlal /T5+E/BTx+AX2qr6zRibFY5aaY8wRJ74U4dTnCmC1WtE0TRdDSfrlyqiw53taYU5Rq8mtf 7h87MbZEeR3df03UbLmIFQr6We0tXE8IerYHtXfA1Ymbu7MP5QchngE7F9A5NYs2yU6Geu FnirJTkCssRGyH8wuzYEDy3jfrTccEmbAKBGmVUmanJ1S+BkPAR1exFp72Ne44m4xERrhf p/RrDZEzdsA8xQimqHrIqbSvpENuNCuh/Jr+aulQH+AiLWylaAGHWVAQoRmGFQ== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id AAAC4539AF for ; Fri, 10 Jan 2025 18:06:21 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tWIS3-0004ot-Gg; Fri, 10 Jan 2025 12:05:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tWIRb-0004Ts-63 for emacs-orgmode@gnu.org; Fri, 10 Jan 2025 12:05:11 -0500 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tWIRY-0004DN-2q for emacs-orgmode@gnu.org; Fri, 10 Jan 2025 12:05:10 -0500 Received: by mail-pl1-x643.google.com with SMTP id d9443c01a7336-21675fd60feso51120835ad.2 for ; Fri, 10 Jan 2025 09:05:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=berkeley.edu; s=google; t=1736528706; x=1737133506; darn=gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=NHLnIsUGNrVb5UZOsxR5Ay8np3GXiQT0rvlTqIJllUU=; b=hSbicOBCZPyYvw2D2qI06LTEQPIfB1BrNSA/DZvUNOI6cg9Zz9E/efPOqphjJjsCax NeznN0Ea9jeid6O2oApiRgvPBLCguGkiO/WZ0EEEa2kXhtUhwlsYvRJigjHHBU67bz86 nx11xPrq5nurjTmOYhDkF69LVKMCrpMQiZpYqRVXHzUpGbOql/4PTBlG4r9TNaHCs+5I 12LNDoQC4heXykIlCtdtDmhhzH79obNzjA3WAvaG0go/kynBCP6+d0UqT15mliJEnR9o 5aTXpgiqDDCRXWZmthROQ/paE59tAQkw9xNwa8buxY7JDH75m6lgUEDBELgcs2NRaLNQ Qmdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736528706; x=1737133506; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NHLnIsUGNrVb5UZOsxR5Ay8np3GXiQT0rvlTqIJllUU=; b=QK4jsB4CTquong6vQxoWfRzsPKt8wFIUjJm3VZlsrxkxFgLx/C+9/2Hqbe4wyUtSaw HvhdZpfvtxAzV1s7pm8VgUQ2y1zMoscHlimosE7GWBhEPErQKX66WjkxeIC8xz0/SWQj 8HSN+KaHr3NAGlgyF1Do5obDCkYWP0nwF1VPxihrcSFCTods2VpuWb6YY4PH749uyNVG +7GXkKOLdqw/X/dVWnQGjWdbpHcpqvCt2AYwAnHOOKFLfKzaOYTixKmNqaNjCbdk9sbz h8Rg3s1itoiNVKvS7Zj9E354eM+vtFAUxWbFELrZvLB5DZDZI9SS4+sFdTM6NICBpRa+ o+9w== X-Forwarded-Encrypted: i=1; AJvYcCU+7i7SoqmyBtrkTBaF4D8Ru58w8LbNtef72MpFcbMiAornhngySLrOb3BnYbE27GRDy8xbXTH7hv+JiYlQ@gnu.org X-Gm-Message-State: AOJu0Yx9ztYwrRdE3lemXbKKUDPFvBUZwA91aEaYkb7sGBqObpRBW9Uq +NZG4PVyZIcHBUmiX9FdMZiL9jDaRcGMalOW9rbcoHRCiRkL4aWQbq+EIBQ5Kg== X-Gm-Gg: ASbGncv7GA2itKrsUdinTqlEautyAQFfgsboqV6qDgIeTNJ6glolIu7OMdTEQkVsfCN ViCAFz05h+5OPalm1UmRlOdR86fvGKRzTOetyTTdXrSX8mglZg+OXdHPQw+CVampFUFDtLu1BRc +R1PJArR/8QD1LiQ5GRhlULDqy7872aou7HO3jRfYlVEGh8axq3b2xPmSusOCjXZi1V0Bl2xhrL O/5cKEyHIw1LN5B+yJBc0gkDgttFNl7sC2f9+TH7S1QI21pivDKVVD7V0gGS9+vamBXg8/XhKbW 2TtlZeng8aNp6TTiOgMvM2C7bVK8vk7FflUl6/3XQA2EbkU= X-Google-Smtp-Source: AGHT+IFcJbGf9bB3of1q98AR3qDD9bcPA3t+LM76SSluI4YVvHljAdcN7OD+04dr3mLccYZ/uBTknA== X-Received: by 2002:a05:6a21:789a:b0:1e1:9bea:659e with SMTP id adf61e73a8af0-1e88d3612e6mr21783093637.35.1736528705269; Fri, 10 Jan 2025 09:05:05 -0800 (PST) Received: from smtpclient.apple (157-131-199-171.fiber.dynamic.sonic.net. [157.131.199.171]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-a317a07cc24sm3099312a12.1.2025.01.10.09.05.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Jan 2025 09:05:04 -0800 (PST) From: Richard H Stanton Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_9C3BE534-A2D6-4616-9C7E-4FE4B05296D7" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.300.87.4.3\)) Subject: Re: How to specify column alignment in LaTeX table output? Date: Fri, 10 Jan 2025 09:04:53 -0800 In-Reply-To: Cc: hallo@rensoliemans.nl, Org Mode List To: Pedro Andres Aranda Gutierrez References: X-Mailer: Apple Mail (2.3826.300.87.4.3) Received-SPF: pass client-ip=2607:f8b0:4864:20::643; envelope-from=rhstanton@berkeley.edu; helo=mail-pl1-x643.google.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.369, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: AAAC4539AF X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -1.96 X-Spam-Score: -1.96 X-TUID: BS9dzbbUEZx4 --Apple-Mail=_9C3BE534-A2D6-4616-9C7E-4FE4B05296D7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 On Jan 9, 2025, at 10:13=E2=80=AFPM, Pedro Andres Aranda Gutierrez = wrote: >=20 > Hi, >=20 > 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. >=20 > Something like: >=20 > --- cut here --- > #+BEGIN_SRC python :results value raw :exports results > import math > import pandas as pd > import tabulate >=20 > xvals =3D [math.pi * i / 5 for i in range(10)] > df =3D 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)] > }) >=20 > attrs=3D':environment longtable :align p{2cm}p{2cm}p{2cm} :placement = [h] :center t' > return tabulate.tabulate( > df, > headers=3Ddf.columns, tablefmt=3D'orgtbl', floatfmt=3D".3f", > caption=3D'Table exported from Python with extended tabulate', > label=3D'labextend', > attr_latex=3Dattrs, > showindex=3DFalse) > #+END_SRC > #+RESULTS: > --- cut here --- >=20 > Take a look at https://github.com/paaguti/python-tabulate if it sounds = interesting.=20 >=20 > CAVEAT: the author of python-tabulate wasn't very excited about this = ;-) >=20 > Best, /PA Thanks for the suggestion! I was creating the output in a rather similar = way, using the pandas to_markdown() function, which calls tabulate to do = the work. Using the orgtbl output option, it only prints one horizontal = line under the header, so I created a simple wrapper function to add = additional horizontal lines at top and bottom (and optionally between = the last and penultimate lines, for when there=E2=80=99s a =E2=80=9CTotal=E2= =80=9D row): ----- def add_hlines(table, total_row=3DFalse): """Add horizontal lines to markdown table.""" table_markdown =3D table.to_markdown(index=3DFalse, = tablefmt=3D"orgtbl", floatfmt=3D",.2f") table_lines =3D table_markdown.split("\n") hline =3D table_lines[1] table_lines.insert(0, hline) if total_row: table_lines.insert(-1, hline) table_lines.append(hline) return "\n".join(table_lines) ----- --Apple-Mail=_9C3BE534-A2D6-4616-9C7E-4FE4B05296D7 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 On Jan 9, = 2025, at 10:13=E2=80=AFPM, Pedro Andres Aranda Gutierrez = <paaguti@gmail.com> wrote:

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 =3D [math.pi * i / 5 for i = in range(10)]
df =3D 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=3D':environment longtable :align = p{2cm}p{2cm}p{2cm} :placement [h] :center t'
return = tabulate.tabulate(
    df,
    = headers=3Ddf.columns, tablefmt=3D'orgtbl', floatfmt=3D".3f",
  =   caption=3D'Table exported from Python with extended = tabulate',
    label=3D'labextend',
    = attr_latex=3Dattrs,
    = showindex=3DFalse)
#+END_SRC
#+RESULTS:
--- cut here = ---

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

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

Best, = /PA

Thanks for the = suggestion! I was creating the output in a rather similar way, using the = pandas to_markdown() function, which calls tabulate to do the work. = Using the orgtbl output option, it only prints one horizontal line under = the header, so I created a simple wrapper function to add additional = horizontal lines at top and bottom (and optionally between the last and = penultimate lines, for when there=E2=80=99s a =E2=80=9CTotal=E2=80=9D = row):

-----

def = add_hlines(table, total_row=3DFalse):
    """Add = horizontal lines to markdown table."""
    = table_markdown =3D table.to_markdown(index=3DFalse, tablefmt=3D"orgtbl", = floatfmt=3D",.2f")
    table_lines =3D = table_markdown.split("\n")
    hline =3D = table_lines[1]
    table_lines.insert(0, = hline)
    if total_row:
    =     table_lines.insert(-1, hline)
    = table_lines.append(hline)
    return = "\n".join(table_lines)

-----

=



= --Apple-Mail=_9C3BE534-A2D6-4616-9C7E-4FE4B05296D7--