New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better display of Chinese #49
Comments
There seems to be no way to achieve it, so I closed it |
If it is compatible with Chinese, alphanumeric characters need to be converted into full angle characters, and the calculated character length is 1 size. Fill the left and right sides with spaces (or lpad or rpad) with chr(12288). Finally, use "-" as the line divider. +------+----------+------+------+------------+------+---------+------+-----------+---------+---------+---------+----+
| 会计月份 | 凭证日期 | 凭证种类 | 凭证编号 | 会计科目编码 | 辅助类型 | 辅助编码 | 辅助名称 | 摘要 | 借方金额 | 贷方金额 | 余额 | 方向 |
+------+----------+------+------+------------+------+---------+------+-----------+---------+---------+---------+----+
| 1 | | | | | | | | 期初余额 | 0.0 | 0.0 | 0 | 平 |
| 1 | | | | | | | | 本月合计 | 0 | 0 | 0 | 平 |
| 1 | | | | | | | | 本年累计 | 0 | 0 | 0 | 平 |
| 2 | 20190228 | 记账 | 11 | 1001010201 | 功能科目 | 2013201 | 行政运行 | 提取备用金 | 10000.0 | 0.0 | 10000.0 | 借 |
| 2 | 20190228 | 记账 | 35 | 1001010201 | 功能科目 | 2013201 | 行政运行 | 何某某住院慰问金 | 0.0 | 2000.0 | 8000.0 | 借 |
| 2 | 20190228 | 记账 | 35 | 1001010201 | 功能科目 | 2013201 | 行政运行 | 陈某配偶住院慰问金 | 0.0 | 2000.0 | 6000.0 | 借 |
| 2 | 20190228 | 记账 | 35 | 1001010201 | 功能科目 | 2013201 | 行政运行 | 林某某住院慰问金 | 0.0 | 2000.0 | 4000.0 | 借 |
| 2 | | | | | | | | 本月合计 | 10000.0 | 6000.0 | 4000.0 | 借 |
| 2 | | | | | | | | 本年累计 | 10000.0 | 6000.0 | 4000.0 | 借 |
| 3 | | | | | | | | 本月合计 | 0.0 | 0.0 | 4000.0 | 借 |
| 3 | | | | | | | | 本年累计 | 10000.0 | 6000.0 | 4000.0 | 借 |
| 4 | 20190430 | 记账 | 58 | 1001010201 | 功能科目 | 2013201 | 行政运行 | 张某某住院慰问金 | 0.0 | 1500.0 | 2500.0 | 借 |
| 4 | 20190430 | 记账 | 58 | 1001010201 | 功能科目 | 2013201 | 行政运行 | 张某某去世慰问金 | 0.0 | 3000.0 | 500.0 | 贷 |
| 4 | | | | | | | | 本月合计 | 0.0 | 4500.0 | 500.0 | 贷 |
| 4 | | | | | | | | 本年累计 | 10000.0 | 10500.0 | 500.0 | 贷 |
| 5 | 20190531 | 记账 | 61 | 1001010201 | 功能科目 | 2013201 | 行政运行 | 老干大学学习费 | 0.0 | 100.0 | 600.0 | 贷 |
| 5 | 20190531 | 记账 | 62 | 1001010201 | 功能科目 | 2013201 | 行政运行 | 临时饭卡充值 | 0.0 | 100.0 | 700.0 | 贷 |
| 5 | | | | | | | | 本月合计 | 0.0 | 200.0 | 700.0 | 贷 |
| 5 | | | | | | | | 本年累计 | 10000.0 | 10700.0 | 700.0 | 贷 |
| 6 | 20190630 | 记账 | 42 | 1001010201 | 功能科目 | 2013201 | 行政运行 | 高某某住院慰问金 | 0.0 | 2000.0 | 2700.0 | 贷 |
| 6 | 20190630 | 记账 | 44 | 1001010201 | 功能科目 | 2013201 | 行政运行 | 何某某住院慰问金 | 0.0 | 2000.0 | 4700.0 | 贷 |
| 6 | 20190630 | 记账 | 45 | 1001010201 | 功能科目 | 2013201 | 行政运行 | 潘某住院慰问金 | 0.0 | 2000.0 | 6700.0 | 贷 |
| 6 | 20190630 | 记账 | 46 | 1001010201 | 功能科目 | 2013201 | 行政运行 | 王某某住院慰问金 | 0.0 | 1500.0 | 8200.0 | 贷 |
| 6 | | | | | | | | 本月合计 | 0.0 | 7500.0 | 8200.0 | 贷 |
| 6 | | | | | | | | 本年累计 | 10000.0 | 18200.0 | 8200.0 | 贷 |
| 7 | | | | | | | | 本月合计 | 0.0 | 0.0 | 8200.0 | 贷 |
| 7 | | | | | | | | 本年累计 | 10000.0 | 18200.0 | 8200.0 | 贷 |
| 8 | | | | | | | | 本月合计 | 0.0 | 0.0 | 8200.0 | 贷 |
| 8 | | | | | | | | 本年累计 | 10000.0 | 18200.0 | 8200.0 | 贷 |
+------+----------+------+------+------------+------+---------+------+-----------+---------+---------+---------+----+ |
Please could you provide a minimal code snippet including PrettyTable that reproduces it? Does it happen with latest |
|
from prettytable import PrettyTable
x = PrettyTable()
x.field_names = ["城市名称", "城市名称编码", "人员", "人均工资(元)"]
x.add_row(["广州", 1295, 1158259, 600.5])
x.add_row(["石家庄", 5905, 1857594, 1146.4])
x.add_row(["加利福利亚", 112, 120900, 1714.7])
x.add_row(["呼和浩特", 1357, 205556, 619.5])
print(x) released as 1.0.0
|
I get the same (with both PrettyTable 0.7.2 and 1.0.0), it looks good for me in the terminal (iTerm2): But not in GitHub monospace:
|
Thank you for your quick reply. In addition, I noticed that every Chinese character in the command window has extra display width, but not under "pycharm", which should be the cause of the problem. |
@vrza Hi! Do you by any chance know what's up here? |
I think my pycharm settings are different from yours. |
In some other applications, like Gedit, Kate and Slack on Linux (pictured below), however, it is problematic. Chinese characters that should be rendered to be exactly 2 "cells" wide (where cell is the width of a single monospace font character) are rendered with width < 2. Vim, Emacs and most terminal emulators seem to render it nicely. On first glance, the issue seems to be in the application that's rendering the text or the rendering engine it uses. This is not a bug in prettytable or the wcwidth library. In the terminal we can only work with whole cells, and we rely on the application (e.g. terminal emulator) to align all characters to integer multiples of 1 cell. |
It seems like quite a complex issue as some character widths when printed in monospaced font are not standardized. This blog post may have some useful information (do notice how many times it was edited): https://denisbider.blogspot.com/2015/09/when-monospace-fonts-arent-unicode.html |
The display width of one Chinese character is not equal to the display width of two space characters. I recommend using chr (12288) as a filler for Chinese content.
[中文] [ ] [ ]
The text was updated successfully, but these errors were encountered: