1

I have started learning Latex and writing my thesis. I want to typeset a long table.

\begin{centering}
\begin{longtable}{p{3.5cm}p{10cm}}
AdsBot-Google&209.85.238.1,209.85.238.107,209.85.238.116,209.85.238.119,209.85.238.16,209.85.238.163,209.85.238.185,209.85.238.200,209.85.238.232,209.85.238.241,209.85.238.246,209.85.238.249,209.85.238.25,209.85.238.33,209.85.238.39,209.85.238.45,209.85.238.68,209.85.238.7,209.85.238.71,209.85.238.74,209.85.238.81,209.85.238.86,209.85.238.89,72.14.199.10,72.14.199.107,72.14.199.113,72.14.199.116,72.14.199.122,72.14.199.2,72.14.199.23,72.14.199.26,72.14.199.37,72.14.199.46,72.14.199.5,72.14.199.55,72.14.199.58,72.14.199.66,72.14.199.75,72.14.199.81,72.14.199.84,72.14.199.87,72.14.199.98\\
        AdsBot-Google-Mobile&209.85.238.206,209.85.238.232,209.85.238.241,209.85.238.68,209.85.238.86,72.14.199.100,72.14.199.115,72.14.199.122,72.14.199.23,72.14.199.26,72.14.199.46,72.14.199.5,72.14.199.81,72.14.199.84\\
        AhrefsBot/1.0&212.113.37.105,212.113.37.106,213.186.122.2\\
\end{longtable}
\end{centering}

But the last column width seems not to be working. I tested with small lengths and even it shows the table as in the image. What is wrong here?

enter image description here

  • Welcome to TeX.SE! I assume the right-hand column contains mostly IP addresses and that IP addresses shouldn't be broken up across lines. Is there a reason for not having spaces after the commas? Actually, could you just replace all commas with spaces? – Mico Nov 24 '14 at 06:44
  • The only way the column entries can properly break is if you introduce some spaces (say 209.85.238.1, 209.85.238.107, ...). – Werner Nov 24 '14 at 06:49
  • @Werner : Thanks, yes it worked after replacing comma with spaces. :) – Nilani Algiriyage Nov 24 '14 at 07:19
  • 4
    This question appears to be off-topic because it is about the typographic consequences of a stylistic choice. – ChrisS Nov 24 '14 at 07:54

1 Answers1

2

If you don't want to manually add spaces in the text to define points where you can break lines you can adapt the solution from How to wrap text in a table when there are no spaces at which to break the line? to define a comma as a breakable character:

enter image description here

Notes:

  • The showframe package was used just to show the page margins. It is not needed in your actual use case.

Code:

\documentclass{article}

\usepackage{longtable} \usepackage{array} \usepackage{showframe}

\usepackage{hyphenat} \usepackage{xstring} \usepackage{forloop} \usepackage{collcell}

\newsavebox\MyBreakChar% \sbox\MyBreakChar{}% char to display the break after non char \newsavebox\MySpaceBreakChar% \sbox\MySpaceBreakChar{-}% char to display the break after space \makeatletter% \newcommand*{\BreakableChar}[1][\MyBreakChar]{% \leavevmode% \prw@zbreak% \discretionary{\usebox#1}{}{}% \prw@zbreak% }%

\newcounter{index}% \newcommand{\AddBreakableChars}[1]{% \StrLen{#1 }[\stringLength]% \forloop[1]{index}{1}{\value{index}<\stringLength}{% \StrChar{#1}{\value{index}}[\currentLetter]% \IfStrEq{\currentLetter}{,} {\currentLetter\BreakableChar[\MyBreakChar]}% {\currentLetter}% }% }%

\newcolumntype{P}[1]{>{\collectcell\AddBreakableChars}p{#1}<{\endcollectcell}}

\begin{document} \noindent \begin{longtable}{@{}p{3.5cm}P{8cm}@{}} AdsBot-Google&209.85.238.1,209.85.238.107,209.85.238.116,209.85.238.119,209.85.238.16,209.85.238.163,209.85.238.185,209.85.238.200,209.85.238.232,209.85.238.241,209.85.238.246,209.85.238.249,209.85.238.25,209.85.238.33,209.85.238.39,209.85.238.45,209.85.238.68,209.85.238.7,209.85.238.71,209.85.238.74,209.85.238.81,209.85.238.86,209.85.238.89,72.14.199.10,72.14.199.107,72.14.199.113,72.14.199.116,72.14.199.122,72.14.199.2,72.14.199.23,72.14.199.26,72.14.199.37,72.14.199.46,72.14.199.5,72.14.199.55,72.14.199.58,72.14.199.66,72.14.199.75,72.14.199.81,72.14.199.84,72.14.199.87,72.14.199.98\ AdsBot-Google-Mobile&209.85.238.206,209.85.238.232,209.85.238.241,209.85.238.68,209.85.238.86,72.14.199.100,72.14.199.115,72.14.199.122,72.14.199.23,72.14.199.26,72.14.199.46,72.14.199.5,72.14.199.81,72.14.199.84\ AhrefsBot/1.0&212.113.37.105,212.113.37.106,213.186.122.2\ \end{longtable}% \end{document}

Peter Grill
  • 223,288