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

Werner
  • 603,163
SteveM
  • 137
  • 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
  • i was just playing around with \seqspilt, and it does not add hyphenation when it breaks a word. i would like to get this working with the length of the word...if the length is greater then the cell width, break it. something tells me this is not something simple :P – SteveM Nov 25 '14 at 20:16
  • @SteveM are your real examples words in some language (there are hyphenation tables for most) or are they really just random strings, in which case something like seqsplit is what you want – David Carlisle Nov 25 '14 at 20:23

1 Answers1

8

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

David Carlisle
  • 757,742