9

Hey im looking to create a text wrap command to be used inside a table for long word wrapping. so far i have this:

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

This is working good. The problem is the seqsplit is removing the spaces. How to preserve the spaces in the text? The data coming in the table is dynamic, so gluing the words together with "~" or "/ " wont work.

Ive tried using:

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

but this errors out. Id like to achieve this on the latex side so programmers using my template dont have to worry about formatting. any help will be great thanks

sample code:

\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}
6
  • Could you add a complete example? What's \seqsplit?
    – egreg
    Commented Jan 7, 2014 at 22:46
  • sorry i cannot post a full version the information contained is sensitive. info on seqsplit can be found here: ctan.mirror.rafal.ca/macros/latex/contrib/seqsplit/seqsplit.pdf Commented Jan 7, 2014 at 22:50
  • 1
    I didn't ask for a full version; use an arbitrary sequence of letters.
    – egreg
    Commented Jan 7, 2014 at 22:51
  • K i posted a similar setup, have a look at the /wrap command Commented Jan 7, 2014 at 23:03
  • \seqinsert{\seqsplit{#1}} doesn't make any sense.
    – egreg
    Commented Jan 7, 2014 at 23:06

1 Answer 1

4

Here's a different implementation of \wrap that doesn't rely on \seqsplit, which is not made for respecting spaces.

\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}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .