From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id mAOVATLygGdHdgEAe85BDQ:P1 (envelope-from ) for ; Fri, 10 Jan 2025 10:10:58 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id mAOVATLygGdHdgEAe85BDQ (envelope-from ) for ; Fri, 10 Jan 2025 11:10:58 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=rensoliemans.nl header.s=soverin header.b=iTVJPHoD; 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=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1736503857; 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=gkV3jw3YlHjCTjk70F3bCySrjV1g5iZw8JJlon2un+Y=; b=qHaLMn9R+RHsUZkMjB02FzlpuETj2/HpN/6LoEGZQTvvGxfT5Styw57iZe91h1gaHPZFtC y15MRIce0dIx7Z6QXoCe9OlFF/5mssYkVg7FtSeYaiiti1NdRKM+n8kb0kV+F96x39bORk lxTdsCPtCGd+hHy1VsAhNV1KWyBvZr7PMuZgBbmP/bNQRCUju2hd1evmE9tzGj0CX8rapQ ROnAYktv4yTNRUf3xPUHIRfvnQeOoWQMCFMy9XlI2AGgiVqQ5YEj90SDrtyn7tjDN+XpqL k4mlU9eQHVMAAvGod5EuZk3FZIIPosoMaaRkdmKztMFVrtfmBEKyGlVPdvK/Ow== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=rensoliemans.nl header.s=soverin header.b=iTVJPHoD; 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=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1736503857; a=rsa-sha256; cv=none; b=ncAsj46ERql74sJpDFqdUAb8Vy+FbzWZGsPl84HmCexdxOshTtQjsdLHAfpuS3gj8UEGXL M8tkesNlNgdr+kY/z/O1KIcP5M6OesJLH8zLLM4F1yrOSOnXGmaSa+SqOt5jV2Pvpaxbxd IoKtDlrNNSqCLOOhf2Gacs1OOhTSqt7DsUghbUaxS8rndM2uVmGm+oklKWHiRGZbR1Mn71 OsBWAp+bxDneKQ0KmZxbBDHVy52dYnV5FzfqaZxxU+IwW2WtUNdXvPdFyt9Xz72KlcOn4e 0r9CU0X4XAVLsoVL/uEI5s6XeGs+nXUg6JN/K4MkP0XIboyleGvToCOcugeXVg== 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 9CA3F7B929 for ; Fri, 10 Jan 2025 11:10:56 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tWBbd-0002aX-Ud; Fri, 10 Jan 2025 04:47:05 -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 1tWBbb-0002aI-AF for emacs-orgmode@gnu.org; Fri, 10 Jan 2025 04:47:03 -0500 Received: from outbound.soverin.net ([2a10:de80:1:4092:b9e9:2292:0:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tWBbY-0002Cc-Ib for emacs-orgmode@gnu.org; Fri, 10 Jan 2025 04:47:03 -0500 Received: from smtp.soverin.net (c04cst-smtp-sov01.int.sover.in [10.10.4.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 4YTxdB3cbcz4H; Fri, 10 Jan 2025 09:46:54 +0000 (UTC) Received: from smtp.soverin.net (smtp.soverin.net [10.10.4.99]) by soverin.net (Postfix) with ESMTPSA id 4YTxd96P1Lz7h; Fri, 10 Jan 2025 09:46:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=rensoliemans.nl; s=soverin; t=1736502414; bh=Fj7EcUq2l2+xQhXOBz94wkVTjwkSHPrxemNrhqAqtQo=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=iTVJPHoDbsC8Mm2kyN5WbqUv1Dfni8QN/p+EclZmxkRWMO/SnJeAMMvQMGt3AJR01 y0RIYMQA6CaNEc12UT3KhjlMc/zj0IQp/OVoFLvdW+gcCZ2LSsu63DdRvMceD1sEXB hYUMbWsiPjUjA71as8AoVspqoMaJF3EUUYsmlwTwEDGjb6hPmbpOml/wNPU3XZLuPm pwVb98mfWYUUEY6bS/n3wZ2xW3X4o3jFxQyn05s5u3Drs2/Y0Gsng+7V4pd1QuY4fv rbqC79BN4rDPL3Bv0+rdQR+AYBKss03FhSsiQW54WMiJwVKwYlJuoO63+XYHIuxeL6 mcijwgE98yfog== X-CMAE-Score: 0 X-CM-Envelope: MS4xfK9TLgNacjg66M9f0EjkUQXdltJsM/HxhhfaqmHLI1bXBVR70TS95Urqrn5jIaIXl4X9FpN2DUY4fXEu1kCSX9orIlTn5uKpQqZQXj5XPBJLXDX16PW7 madiE6HK8Qws4G/JAQ17SZQbqnh7PLnTAzavnrL+Cx2QnLvCyyDG2RdCtPQ6JH/Q8VG/E62IUYH0CpeJWoWFuQ2fwvAATj3rNkF8552JYSh2ddKbq6THTSRY 9y7h4X48FC/DXa1Sy2DWGgPX9UFn1peQ6PRz4NZyYVYax50pZuUQuYJOJ2t1UBL+ X-CM-Analysis: v=2.4 cv=WMmFXmsR c=1 sm=1 tr=0 ts=6780ec8e a=4bom3OyIvp8zk49k3DLuvQ==:617 a=xqWC_Br6kY4A:10 a=NjIK7znJAAAA:8 a=Q7hQi6m9kjy3cfSUCOcA:9 a=QEXdDO2ut3YA:10 a=Owg2AOh6GawA:10 a=JnOD8IjZYglDcH5qPrMA:9 a=O1c1nmEkCxIQdeELtU9r:22 From: Rens Oliemans To: Richard H Stanton Cc: emacs-orgmode@gnu.org Subject: Re: How to specify column alignment in LaTeX table output? In-Reply-To: <9F2C7295-E505-47DA-BF76-078F0C28B9E6@berkeley.edu> References: <87wmf4qoju.fsf@rensoliemans.nl> <9F2C7295-E505-47DA-BF76-078F0C28B9E6@berkeley.edu> Date: Fri, 10 Jan 2025 10:47:45 +0100 Message-ID: <87wmf3vw3i.fsf@rensoliemans.nl> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spampanel-Class: ham Received-SPF: pass client-ip=2a10:de80:1:4092:b9e9:2292:0:1; envelope-from=hallo@rensoliemans.nl; helo=outbound.soverin.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: 1.53 X-Spam-Score: 1.53 X-Migadu-Queue-Id: 9CA3F7B929 X-TUID: e0/75fPhMYaP --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Richard H Stanton writes: > what are the recommended headers for a Python code block that exports a t= able? For example, ":results output raw=E2=80=9D and ":results output drawe= r=E2=80=9D both seem to work (without :wrap), while =E2=80=9C:results outpu= t=E2=80=9D puts everything in an example block, which then seems to get exp= orted verbatim, not as a LaTeX table. Take a look at https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-python.html. I = found this link in the Org manual, "(org) Results of Evaluation", and then to "Documentation" link of python. From that page: :results {output, value}: Output results come from whatever the python = code prints on stdout. Value results are the value of the last expression evaluated in the code block. Value mode is the default (as with other languages). In value mode you can use the following subtypes: verbatim: value is returned as string. In particular, use this to prevent conversion of lists and tuples to tables. table: (Org 9.7+) Try to convert the result to an Org table. Dicts, numpy arrays, and pandas DataFrames/Series can be returned as tables this way (by default, they are printed verbatim). Note that lists a= nd tuples are already converted to table by default (use verbatim to prevent that). So, ':results output' will output whatever python prints to stdout. With 'print()', I think that this will just be a string, and no conversion will = take place. If you specify 'output raw', python will still just print the string= , but *Org mode* will now interpret it as raw Org mode. This will probably work f= ine, but you'll have to add '|' and newlines in your string correctly. Alternati= ve: ':results value', the default. In this case ob-python will convert lists and tuples to tables by default (and optionally, dicts and DataFrames as well). That would be my recommendation: a code block with the default headers, whi= ch returns a list of lists. I've attached an org file which does this. > I actually generate this table from a Python code block. In the past, I= =E2=80=99ve often run into problems with raw output (like this), where runn= ing the code block multiple times causes the output to appear multiple time= s, rather than overwriting. ':results append' will cause the output to appear multiple times, but I exp= ect that it happened due to other circumstances (':results replace' is default = and I expect you didn't change that). One such circumstance is when you, say, add= a ':results output' header argument, and then change it back. For reasons unk= nown to me, Org mode will then see the previous #+RESULTS: block as unrelated to= the current one, and will not replace it. This is then kind of annoying, because you'll have to add the #+ATTR_LATEX:= line to the table again. I'd fix this manually, but if it gets annoying you can = use the suggestion by PA. --=-=-= Content-Type: text/org Content-Disposition: attachment; filename=test.org #+begin_src python import random from collections import namedtuple Tier = namedtuple('Tier', ['number', 'total']) def generate_table(tiers): total = sum(tier.total for tier in tiers) total_numbers = sum(tier.number for tier in tiers) # A None in a list will result in a hline in org tables return [ None, # Header separator ('Tier', 'Number', 'Total', '% of Total'), None, # Column header separator ,*[ (i+1, tier.number, f'{tier.total:,.2f}', f'{100 * tier.total / total:.2f}') for i, tier in enumerate(tiers) ], None, # Footer separator ('Total', total_numbers, f'{total:,.2f}', '100.00'), None, # Final separator ] tiers = [ Tier(4, random.uniform(1000, 10000)), Tier(19, random.uniform(1000, 10000)), Tier(24, random.uniform(1000, 10000)), ] return generate_table(tiers) #+end_src #+RESULTS: |-------+--------+-----------+------------| | Tier | Number | Total | % of Total | |-------+--------+-----------+------------| | 1 | 4 | 8,022.65 | 65.45 | | 2 | 19 | 1,549.71 | 12.64 | | 3 | 24 | 2,685.28 | 21.91 | |-------+--------+-----------+------------| | Total | 47 | 12,257.65 | 100.00 | |-------+--------+-----------+------------| #+ATTR_LATEX: :align rrrr :float t :placement [htbp] #+RESULTS: --=-=-=--