# squeeze the text in table

I had gone thro this question and still in my case, i have the overlapping text in the table

Here is my MWE

\documentclass[a4paper,10pt]{book}
\usepackage{pdflscape}    % to change certain pages to landscape mode
\usepackage{longtable}  % for tables spanning multiple pages
\begin{document}

This is my example

\begin{landscape}
\begin{tabular}{|p{5cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
\hline
ABCD EFGH  ABCD EFGH  ABCD EFGH ABCD EFGH  ABCD EFGH  & H & H & H & H & OCH2-CH=C(CH3)CH2CH2CH=C(CH3)2 & H  \tabularnewline
\hline
\end{tabular}
\newline
\end{landscape}
\end{document}


I can not expand / compress the column size.

The question is how to fix the overflowing text in 6th column. Whereas column 1 fits properly.

Should i manually hyphenate the text to fit into the desired cell width?

-
I think that the problem is related to the hyphenation. As TeX doesn't know how to split that long string. If you hyphenate it, then it doesn't overflow. –  adn Mar 20 '12 at 7:17

This version switches category codes, so can not be used in the argument to another command, but works OK here I think. The penalty0 allows breaks at those points, if some are more desirable than others you could give the desirable ones negative penalties and the undesirable ones positive penalties.

\documentclass[a4paper,10pt]{book}
\usepackage{pdflscape}    % to change certain pages to landscape mode
\usepackage{longtable}  % for tables spanning multiple pages
\usepackage{array}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash\hspace{0pt}\mybreaks}p{#1}}

\begingroup
\catcode=\active
\catcode-\active
\catcode)\active
\gdef\mybreaks{%
\catcode=\active\edef={\string=\penalty0 }%
\catcode)\active\edef){\string)\penalty0 }%
\catcode-\active\edef-{\string-\penalty0 }}
\endgroup
\begin{document}

This is my example

\begin{landscape}
\begin{tabular}{|P{5cm}|P{2cm}|P{2cm}|P{2cm}|P{2cm}|P{2cm}|P{2cm}|}
\hline
ABCD EFGH  ABCD EFGH  ABCD EFGH ABCD EFGH  ABCD EFGH  & H & H & H & H & OCH2-CH=C(CH3)CH2CH2CH=C(CH3)2 & H  \tabularnewline
\hline
\end{tabular}
\newline
\end{landscape}
\end{document}

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8762118220329285, "perplexity": 4632.1574719715045}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2015-27/segments/1435375094662.41/warc/CC-MAIN-20150627031814-00011-ip-10-179-60-89.ec2.internal.warc.gz"}