9

I have a long word inside my tabular I need to break. The other rows and columns look perfect, but since this is only 1 word, the actual word overlaps on the other column. Not ideal.

Is there a SIMPLE fix? Basically here's how I make the tabular:

\begin{tabular}{|p{3.5cm}|p{3.5cm}|}
\hline

Header 
& 
Header 2\\


\hline
Marketingdivisiontesttesttest  
&
Some more text\\
\hline

\end{tabular}

Microsoft Word breaks the word easily.

8
  • You don't really give us enough information to address the issue. Could you provide the code that demonstrates the issue? Commented Nov 10, 2016 at 14:12
  • @StevenB.Segletes Added an example of what I mean. Commented Nov 10, 2016 at 14:18
  • Marketingdivision\-testtesttest Commented Nov 10, 2016 at 14:23
  • @StevenB.Segletes Seems very... odd to do it that way, right? Isn't there a simple way of saying "when the word hits the right border of this table, break it into a new line"? Commented Nov 10, 2016 at 14:24
  • TeX's paragraph setting routines require the existence of breakpoints. Obviously spaces between words are the common place to find them. What I suggested is manually telling TeX how to break a long non-word. If it can't find a rational place to break text, it won't. Commented Nov 10, 2016 at 14:26

3 Answers 3

9

The first word in a paragraph isn't hyphenated. Use \hspace{0pt} or lualatex whichwill hyphenate also the first word.

\documentclass{article}
\usepackage{array}
\newcolumntype{P}[1]{>{\hspace{0pt}}p{#1}}
\begin{document}
    \begin{tabular}{|P{3.5cm}|p{3.5cm}|}
        \hline
        Header 
        & 
        Header 2\\
        \hline
        Marketingdivisiontesttesttest  
        &
        Some more text\\
        \hline
    \end{tabular}
\end{document}

enter image description here

3

One way to do this quite simply is to add \newline.

Code:

\documentclass{article}
\begin{document}
\begin{tabular}{|p{3.5cm}|p{3.5cm}|}
\hline
Header 
& 
Header 2\\
\hline
Marketingdivision-\newline testtesttest  
&
Some more text\\
\hline
\end{tabular}
\end{document}

This yields:

enter image description here

2
  • 1
    Doesn't scale that well to be honest. Commented Nov 10, 2016 at 18:02
  • @Snorlax After the first word the table breaks the lines automatically, so you would only have to use this a max of once every cell.
    – Dan
    Commented Nov 10, 2016 at 18:20
0

That the first word in a paragraph is not hyphenated is true for TeX, pdfTeX, and XeTeX. LuaTeX behaves differently, there the first word can also be hyphenated.

The example comes from a duplicate question:

\documentclass{book}
\begin{document}
\begin{table}
\begin{tabular}{|p{1.7cm}|p{1.7cm}|}
A LongHorribleAndPointlessMess & ALongHorribleAndPointlessMess \\ \hline
\end{tabular}
\end{table}
\end{document}

Result

You must log in to answer this question.

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