seqsplit-保留空格

seqsplit-保留空格

嘿,我正在寻找创建一个文本换行命令,用于在表格内进行长单词换行。到目前为止我有这个:

\renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi}
\newcommand{\wrap}[1]{\seqinsert{\seqsplit{#1}}} % used to wrap really long words

效果很好。问题是 seqsplit 删除了空格。如何保留文本中的空格?表中的数据是动态的,因此用“~”或“/”将单词粘合在一起是行不通的。

我尝试过使用:

\newcommand{\wrap}[1]{\seqinsert{\seqsplit{\StrSubstitute{#1}{ }{\~{}}}}} % used to wrap really long words

但这样会出错。我想在 latex 端实现这一点,这样使用我的模板的程序员就不必担心格式问题。任何帮助都将非常感谢

示例代码:

\documentclass{report}

%%%%%%%%%%%%%%%%%%%%%%
% Package Inclusions %
%%%%%%%%%%%%%%%%%%%%%%

\usepackage{lastpage}
\usepackage{caption}
\usepackage{geometry}
\usepackage{tabularx}
\usepackage{hhline}
\usepackage[table]{xcolor}
\usepackage{placeins}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage{float}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{seqsplit}
\usepackage{xstring}
\usepackage{multicol}
\usepackage{multirow}


%%%%%%%%%%%%%%%%%%%%%%
%   Configurations   %
%%%%%%%%%%%%%%%%%%%%%%

\captionsetup[table]{labelformat=empty}
\definecolor{lightgray}{gray}{0.9}
\newcolumntype{Y}{>{\centering\arraybackslash}X} % Use Y to center align a column
\geometry{
  top=0.75in,            
  inner=0.25in,
  outer=0.25in,
  bottom=0.75in,
  headheight=3ex,      
  headsep=6ex,          
}
\pagestyle{fancy}
\renewcommand{\baselinestretch}{1}
\renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi}
\newcommand{\wrap}[1]{\seqinsert{\seqsplit{#1}}} % used to wrap really long words
\newcommand{\wrapb}[1]{\textbf{\seqinsert{\seqsplit{#1}}}} % used to wrap really long words and bold it

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   Titles, Headers and Footers   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\author{XXXXXXXXXX}
\title{XXXXXXX}
\lhead{XXXXXXXXXXXXXXX}
\chead{XXXXXXXXXXXXXX}
\rhead{XXXXXXXXXXXXXXXXXX}
\lfoot{Page \thepage\ of \pageref{LastPage}}
\cfoot{XXXXXXXXXXXXXXXXXXXXXXXX}
\rfoot{\fancyplain{}{\today}}


%%%%%%%%%%%%%%%%%%%%%%
%    Report Start    %
%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\maketitle
\section*{XXXXXXXXXXXXXXXXXXXX}


\begin{table}[H]
\rowcolors{1}{}{lightgray}
\begin{longtabu} to \textwidth {YYYYYYYYYYYYY}
    \hline
    \textbf{XXX} & 
    \textbf{XX} & 
    \textbf{XXX} & 
    \textbf{XXX} &
    \textbf{XXX} &
    \textbf{XXX} &
    \textbf{XXXX} &
    \textbf{XX} &
    \textbf{XXX} &
    \textbf{XXX} &
    \textbf{XXX} &
    \textbf{X} &
    \textbf{XXX}
    \\ \hline \hline \hline 
    12:28:33 & 1 & \wrap{tyry ery,CVBBBdsgsdgsdgdsgsg} & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\      
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\      
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    \hline
\end{longtabu}
\end{table} 

\end{document}

答案1

这是 的不同实现,\wrap它不依赖于\seqsplit,并且不尊重空格。

\documentclass{report}

%%%%%%%%%%%%%%%%%%%%%%
% Package Inclusions %
%%%%%%%%%%%%%%%%%%%%%%

\usepackage{lastpage}
\usepackage{caption}
\usepackage{geometry}
\usepackage{tabularx}
\usepackage{hhline}
\usepackage[table]{xcolor}
\usepackage{placeins}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage{float}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{seqsplit}
\usepackage{xstring}
\usepackage{multicol}
\usepackage{multirow}

\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\separator}{ }
 {
  \mode_if_math:TF { \allowbreak } { \- }
 }
\NewDocumentCommand{\wrap}{ m }
 {
  \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

%%%%%%%%%%%%%%%%%%%%%%
%   Configurations   %
%%%%%%%%%%%%%%%%%%%%%%

\captionsetup[table]{labelformat=empty}
\definecolor{lightgray}{gray}{0.9}
\newcolumntype{Y}{>{\centering\arraybackslash}X} % Use Y to center align a column
\geometry{
  top=0.75in,            
  inner=0.25in,
  outer=0.25in,
  bottom=0.75in,
  headheight=3ex,      
  headsep=6ex,          
}
\pagestyle{fancy}
\renewcommand{\baselinestretch}{1}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   Titles, Headers and Footers   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\author{XXXXXXXXXX}
\title{XXXXXXX}
\lhead{XXXXXXXXXXXXXXX}
\chead{XXXXXXXXXXXXXX}
\rhead{XXXXXXXXXXXXXXXXXX}
\lfoot{Page \thepage\ of \pageref{LastPage}}
\cfoot{XXXXXXXXXXXXXXXXXXXXXXXX}
\rfoot{\fancyplain{}{\today}}


%%%%%%%%%%%%%%%%%%%%%%
%    Report Start    %
%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\maketitle
\section*{XXXXXXXXXXXXXXXXXXXX}


\begin{table}[H]
\rowcolors{1}{}{lightgray}
\begin{longtabu} to \textwidth {YYYYYYYYYYYYY}
    \hline
    \textbf{XXX} & 
    \textbf{XX} & 
    \textbf{XXX} & 
    \textbf{XXX} &
    \textbf{XXX} &
    \textbf{XXX} &
    \textbf{XXXX} &
    \textbf{XX} &
    \textbf{XXX} &
    \textbf{XXX} &
    \textbf{XXX} &
    \textbf{X} &
    \textbf{XXX}
    \\ \hline \hline \hline 
    12:28:33 & 1 & \wrap{tyry ery,CVBBBdsgsdgsdgdsgsg} & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\      
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\      
    12:28:33 & 1 & tyryery, CVBBB & -3750.00 & 1110.00 & 1110.00 & 1 to 20 & 1109.93 &
        1109.93 & 1 to 20 & 1 to 20 & 4651.59 & 4651.59 \\ 
    \hline
\end{longtabu}
\end{table} 

\end{document}

在此处输入图片描述

相关内容