前段时间,我参考了这个 stack exchange 来解决 longtabu 单元格中长文本换行的问题。提供的解决方案有效,但现在我的要求已经改变,必须能够打印西班牙语字符和英语。因此,换行功能不再有效。我想知道如何实现这一点?我能够在换行功能之外打印西班牙语字符,如示例所示。谢谢!
\documentclass[6pt]{extarticle}
%%%%%%%%%%%%%%%%%%%%%%
% Package Inclusions %
%%%%%%%%%%%%%%%%%%%%%%
\usepackage{longtable, tabu}
\usepackage{xparse} % used for \ExplSyntaxOn
%used to print Spanish characters in the text
\usepackage[utf8x]{inputenc}
\usepackage{amssymb}
\usepackage[english,spanish]{babel}
%%%%%%%%%%%%%%%%%%%
% CONFIGURATIONS %
%%%%%%%%%%%%%%%%%%%
\tabulinesep=5mm % used to set the space between bottem and top of cell in a longtabu using option m in column definition
%%%%%%%%%%%%%%%%%%%
% Custom Commands %
%%%%%%%%%%%%%%%%%%%
\ExplSyntaxOn
\NewDocumentCommand{\separator}{ }
{
\mode_if_math:TF { \allowbreak } { \- }
}
\NewDocumentCommand{\wrap}{ m } % use this command to wrap text \wrap{text goes here}
{
\mathers_wrap:n { #1 }
}
\seq_new:N \l_mathers_input_seq
\seq_new:N \l_mathers_output_seq
\seq_new:N \l_mathers_temp_seq
\cs_new_protected:Npn \mathers_wrap:n #1
{
\seq_clear:N \l_mathers_output_seq
\seq_set_split:Nnn \l_mathers_input_seq { ~ } { #1 }
\seq_map_inline:Nn \l_mathers_input_seq
{
\seq_set_split:Nnn \l_mathers_temp_seq { } { ##1 }
\seq_put_right:Nx \l_mathers_output_seq
{ \seq_use:Nn \l_mathers_temp_seq { \separator } }
}
\seq_use:Nn \l_mathers_output_seq { ~ }
}
\ExplSyntaxOff
%%%%%%%%%%%%%%%%
% Report Start %
%%%%%%%%%%%%%%%%
\begin{document}
Spanish Characters: á, é, í, ó, ú, ü, ñ, ¿, ¡
\begin{longtabu} to \textwidth {
|X[1,l,m]|
X[1,l,m]|
X[1,l,m]|
}
\hline
\wrap{á tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt} &
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt} &
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt}
\\\hline
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt} &
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt} &
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt}
\\\hline
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt} &
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt} &
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt}
\\\hline
\end{longtabu}
\end{document}
答案1
对于 Unicode 字符,要使用的例程更复杂。这似乎有效,至少对于您需要的字符而言。请不要使用utf8x
。
\documentclass[6pt]{extarticle}
%%%%%%%%%%%%%%%%%%%%%%
% Package Inclusions %
%%%%%%%%%%%%%%%%%%%%%%
\usepackage{longtable, tabu}
\usepackage{xparse} % used for \ExplSyntaxOn
%used to print Spanish characters in the text
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage[english,spanish]{babel}
%%%%%%%%%%%%%%%%%%%
% CONFIGURATIONS %
%%%%%%%%%%%%%%%%%%%
\tabulinesep=5mm % used to set the space between bottem and top of cell in a longtabu using option m in column definition
%%%%%%%%%%%%%%%%%%%
% Custom Commands %
%%%%%%%%%%%%%%%%%%%
\ExplSyntaxOn
\NewDocumentCommand{\separator}{ }
{
\mode_if_math:TF { \allowbreak } { \- }
}
\NewDocumentCommand{\wrap}{ m } % use this command to wrap text \wrap{text goes here}
{
\mathers_wrap:n { #1 }
}
\seq_new:N \l_mathers_input_seq
\seq_new:N \l_mathers_output_seq
\seq_new:N \l_mathers_temp_seq
\tl_new:N \l_mathers_word_seq
\cs_new_protected:Npn \mathers_wrap:n #1
{
\seq_clear:N \l_mathers_output_seq
\seq_set_split:Nnn \l_mathers_input_seq { ~ } { #1 }
\seq_map_inline:Nn \l_mathers_input_seq
{
\mathers_scan_word:n { ##1 }
}
\seq_use:Nn \l_mathers_output_seq { ~ }
}
\cs_new_protected:Npn \mathers_scan_word:n #1
{
\tl_clear:N \l_mathers_word_tl
\__mathers_scan_word_aux: #1 \q_stop
\seq_put_right:NV \l_mathers_output_seq \l_mathers_word_tl
}
\cs_new_protected:Npn \__mathers_scan_word_aux:
{
\peek_meaning:NTF { \q_stop }
{
\use_none:n
}
{
\peek_meaning:NTF ^^c3
{ \mathers_eat:NN }
{
\peek_meaning:NTF ^^c2
{ \mathers_eat:NN }
{ \mathers_eat:N }
}
}
}
\cs_generate_variant:Nn \peek_meaning:NTF { c }
\cs_new_protected:Npn \mathers_eat:NN #1 #2
{ \tl_put_right:Nn \l_mathers_word_tl {#1#2\separator}\__mathers_scan_word_aux: }
\cs_new_protected:Npn \mathers_eat:N #1
{ \tl_put_right:Nn \l_mathers_word_tl {#1\separator}\__mathers_scan_word_aux: }
\ExplSyntaxOff
%%%%%%%%%%%%%%%%
% Report Start %
%%%%%%%%%%%%%%%%
\begin{document}
Spanish Characters: á, é, í, ó, ú, ü, ñ, ¿, ¡
\begin{longtabu} to \textwidth {
|X[1,l,m]|
X[1,l,m]|
X[1,l,m]|
}
\hline
\wrap{á éíóúüñ¿¡áé íóúüñ¿¡áé í óúüñ¿¡áéíóúüñ¿¡áéíóúüñ¿¡áéíóúüñ¿¡áéíóúüñ¿¡ é} &
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt} &
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt}
\\\hline
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt} &
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt} &
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt}
\\\hline
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt} &
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt} &
\wrap{ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt}
\\\hline
\end{longtabu}
\end{document}
支持其他字符可能需要更多检查\peek_meaning:NTF
;这些对于西班牙语字符来说已经足够了。