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

7
  • 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, 2014 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, 2014 at 20:07
  • 1
    there might be something useful in this: Wrapping long lines that contain no spaces Nov 25, 2014 at 20:10
  • why do you use \seqsplit in the second column but not the first? Nov 25, 2014 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, 2014 at 20:11

1 Answer 1

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

3
  • Thanks for your help, seqsplit does work, but how to add hyphen when the word breaks?
    – SteveM
    Nov 25, 2014 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:-) Nov 25, 2014 at 20:28
  • 1
    Thanks! this seems to be working. and the \obeyspaces is a nice little trick!
    – SteveM
    Nov 25, 2014 at 20:31

You must log in to answer this question.

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