5

Im trying to wrap long words in a longtable and its not quite working right. some of the words spill over to the next cell. any help would be great thanks!

\documentclass{report}
\usepackage[left=65pt,top=28pt,right=65pt,bottom=65pt]{geometry}% http://ctan.org/pkg/geometry
\usepackage{longtable}% http://ctan.org/pkg/longtable
\usepackage{seqsplit}% http://ctan.org/pkg/seqsplit
\usepackage{array}

\begin{document}
\begin{longtable}{m{50pt} | m{360pt} | m{50pt}}
  & \seqsplit{thisisareallylongexamplethisisareallylongexamplethisisareallylongexamplethisisareallylongexample with a space} & test1 \\
  & \seqsplit{thisisareallylongexamplethisisareallylongexamplethisisareallylongexamplethisisareallylongexample\ with\ a\ space} & test2 \\
  & \seqsplit{thisisareallylongexamplethisisareallylongexamplethisisareallylongexamplethisisareallylongexample~with~a~space} & test3 \\
  \hline
  klhd ldgdddddddksjd fkldjs fldjs fkldjs lfkj sdlkf jlksjdf lkdsj fkldsj fkldsj fkldsj fklj sfkljds fdfdfdfdgddddddhghgghghdflkj & kjshfd ksj fdkjshf kjds hfkdjs hfkjds h &
    jsdh kkjhdskkjsfhhdsfhjdsfh dskj dkjshf dskjjkhs hjsd kjfkdshf kjdsh  
  \\
\end{longtable}
\end{document}

enter image description here

  • 1
    Well there's your problem. How should that word be broken across the line when it doesn't fit? Moreover, there is no hyphenation pattern for fdfdfdfdgddddddhghgghghdflkj. – Werner Nov 25 '14 at 20:05
  • Should it not know when to break the word and were? This report is dynamically generated, these words could be anything of any size. Thanks – SteveM Nov 25 '14 at 20:07
  • 1
    there might be something useful in this: Wrapping long lines that contain no spaces – barbara beeton Nov 25 '14 at 20:10
  • why do you use \seqsplit in the second column but not the first? – David Carlisle Nov 25 '14 at 20:11
  • If that word forms part of a regular language, then you can load that language's babel, which should include hyphenation patterns. However, if the word doesn't exist with a hyphenation pattern, certain assumptions are made and it may be broken at the wrong point. – Werner Nov 25 '14 at 20:11
7

the hyphenation patterns for English do not help here. That's the problem seqsplit is trying to fix, but you are not using it in all the cell.

enter image description here

Note it is unrelated to longtable you would get the same behavior in a paragraph on the main page.

\documentclass{report}
\usepackage[left=65pt,top=28pt,right=65pt,bottom=65pt]{geometry}% http://ctan.org/pkg/geometry
\usepackage{longtable}% http://ctan.org/pkg/longtable
\usepackage{seqsplit}% http://ctan.org/pkg/seqsplit
\usepackage{array}

\begin{document}
\begin{longtable}{m{50pt} | m{360pt} | m{50pt}}
  & \seqsplit{thisisareallylongexamplethisisareallylongexamplethisisareallylongexamplethisisareallylongexample with a space} & test1 \\
  & \seqsplit{thisisareallylongexamplethisisareallylongexamplethisisareallylongexamplethisisareallylongexample\ with\ a\ space} & test2 \\
  & \seqsplit{thisisareallylongexamplethisisareallylongexamplethisisareallylongexamplethisisareallylongexample~with~a~space} & test3 \\
  \hline\obeyspaces\seqsplit{klhd ldgdddddddksjd fkldjs fldjs fkldjs lfkj sdlkf jlksjdf lkdsj fkldsj fkldsj fkldsj fklj sfkljds fdfdfdfdgddddddhghgghghdflkj} & 
\obeyspaces\seqsplit{kjshfd ksj fdkjshf kjds hfkdjs hfkjds h}&
\obeyspaces\seqsplit{jsdh kkjhdskkjsfhhdsfhjdsfh dskj dkjshf dskjjkhs hjsd kjfkdshf kjdsh}\\
\end{longtable}
\end{document}

If you want hyphenation, add

 \def\seqinsert{\-}

before the table

  • Thanks for your help, seqsplit does work, but how to add hyphen when the word breaks? – SteveM Nov 25 '14 at 20:26
  • @SteveM I just added that in an updated answer (I have never used seqsplit before, I just went texdoc seqsplit and did what it said:-) – David Carlisle Nov 25 '14 at 20:28
  • Thanks! this seems to be working. and the \obeyspaces is a nice little trick! – SteveM Nov 25 '14 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.