Tabulate provides comprehensive support for UTF-8 and multi-byte characters, enabling you to create tables with international text, special symbols, and Unicode content. The library usesDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/p-ranav/tabulate/llms.txt
Use this file to discover all available pages before exploring further.
wcswidth on Unix systems to accurately compute the display width of multi-byte characters.
Enabling Multi-byte Support
To work with multi-byte characters, you must explicitly enable multi-byte character support using.format().multi_byte_characters(true):
Multi-byte character support is opt-in because calculating column width for multi-byte characters requires additional processing. Only enable it when your table contains multi-byte characters.
Complete Example: Multilingual Table
This example displays “I love you” in different languages, demonstrating UTF-8 support:The source code for this example is available at
samples/unicode.cpp in the repository.When to Enable Multi-byte Support
Identify multi-byte content
Determine which columns or cells contain non-ASCII characters (CJK languages, emoji, special symbols).
Apply formatting
Enable multi-byte support on those specific columns or cells, not the entire table.
Setting Locale for Cells
You can explicitly set the locale for individual cells or columns using.format().locale(value):
Common Multi-byte Use Cases
Special Symbols
Multi-byte characters are useful for decorative borders and symbols:Emoji Support
CJK Languages
Chinese, Japanese, and Korean characters require multi-byte support:Platform Considerations
Unix/Linux/macOS
- Uses
wcswidthfor character width calculation - Requires appropriate locale support
- Check available locales with
locale -a
Locale Availability
On some systems (like older macOS versions), certain locales may not be available. For example, Arabic locale might be missing, which can cause alignment issues with Arabic text.Best Practices
- Enable selectively: Only enable multi-byte support on columns/cells that need it
- Test locales: Verify locale availability before using
.format().locale() - Use consistent encoding: Ensure your source files are saved as UTF-8
- Consider performance: Multi-byte character width calculation has a performance cost
- Check alignment: Test your tables on the target system to ensure proper alignment
Troubleshooting
Alignment Issues
If text doesn’t align properly:- Enable multi-byte character support:
.multi_byte_characters(true) - Verify the locale is available on your system
- Check that your terminal supports UTF-8 encoding