org-mode如何将表格导出为HTML时设置列宽?

8
我使用emacs org-mode来编写文档,并将其导出为html。
对于表格,我想设置列宽(宽度的百分比),例如以下方式:
#+attr_html: :border 1 :rules all :frame border :width 100%
|----+-------------------------------------+-----------------|
| ID | BUG                                 | Result          |
|----+-------------------------------------+-----------------|
|  1 | jdkkskdjskdsdjsdljskdjfskfjksdjfksf | ok              |
|  2 | 823jjsljfdkjsdskkkkkuuffggg         | not bug         |
|  3 | aaaaahhaaaaa                        | can't reproduct |
|----+-------------------------------------+-----------------|

当导出为HTML时,我希望将3个标签(ID、BUG、Result)的宽度百分比设置为(2%、80%、18%)。如何实现?
1个回答

3
你可以通过在头部插入CSS来实现这一点。(如果你想更加花哨,你还可以添加一个CSS代码块。)通过给表格和CSS添加一个类,你可以确保只有那个表格受到CSS的影响。
这是你想要的表格(我还添加了一些背景颜色,以便清楚地显示样式实际上已经应用):

a table with coloured columns that have the right width

#+HTML_HEAD: <style type="text/css">
#+HTML_HEAD: .styledtable col:nth-of-type(1) { width:  2%; background: orange; }
#+HTML_HEAD: .styledtable col:nth-of-type(2) { width: 80%; background: dodgerblue; }
#+HTML_HEAD: .styledtable col:nth-of-type(3) { width: 18%; background: hotpink; }
#+HTML_HEAD: </style>

#+ATTR_HTML: :class styledtable
#+attr_html: :border 1 :rules all :frame border :width 100%
|----+-------------------------------------+-----------------|
| ID | BUG                                 | Result          |
|----+-------------------------------------+-----------------|
|  1 | jdkkskdjskdsdjsdljskdjfskfjksdjfksf | ok              |
|  2 | 823jjsljfdkjsdskkkkkuuffggg         | not bug         |
|  3 | aaaaahhaaaaa                        | can't reproduct |
|----+-------------------------------------+-----------------|

有一个类似的问题,具有一个类似的答案


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接