4
\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{array}
\begin{document}
\begin{table}
\begin{center}
\caption{Results.}\label{tab1}
\begin{tabular}{|p{0.5cm}|p{0.5cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{0.5cm}|}
\hline
N & KS & g & n & C & $\lambda(n)$ & $\mu$ & R\\
\hline
1 &
 32 &
 1572324240 &
 1572324239 &
 943290716551438163 &
 1572244920 &
 1470930645&6\\
\hline
2 &
 64 &
 4159540661949250490 &
 4159540661949250489 &
 14726610731536157220276939497631624989 &
 4159171243689855120&3091093397568475626 &
 6\\
\hline
3 &
 96 &
 17921013728107489666861417152 &
 17921013728107489666861417151 &
 319644167630919465013897831470640254404402368723868992349 &
 17918883386300536523002183680&
 8310947063368032641748342092 &
 6\\
\hline
4 &
 128 &
 10960388158297871697330151881871037028 &
 10960388158297871697330151881871037027 &
 106925141663462215096945420078312037311355711106757002541655645931678791491 &
 10958297067198453652392990431562024960 & 
 3253082388973481812242917579299455335 &
 6\\ 
\hline
5 &
 160 &
 11181085000393941012433719385538976929750386340 &
 11181085000393941012433719385538976929750386339 &
 79684675709633819762973841355295907051437943828599200481216296703376032895835669790667255501 &
 11178266769966960229108283302064411639808000000 &
 4208406996756154635702287087616339813762920102 &
 6\\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}
Skillmon
  • 60,462
yogesh
  • 43
  • See this thread : https://tex.stackexchange.com/q/2441/121944 – AML May 06 '18 at 13:49
  • 1
    The problem is, that TeX doesn't find any break points in your cells, since line wrapping in a number is not allowed. If you specify break points (or use different cell content, that includes breakpoints) the contents will be wrapped. – Skillmon May 06 '18 at 13:51
  • I tried all type of cells p,m,b,l,c,r but its not working. need something auto kind as in HTML – yogesh May 06 '18 at 13:54
  • @yogesh as I wrote the problem lies in the specific contents you have. And a table with such long numbers wouldn't be very comprehensible either. Is the posted content your real use case? Do the numbers have to be precise to the last digit, or is shortening like 1.09e15 viable? – Skillmon May 06 '18 at 13:56
  • @Skillmon I got your point, but I need all numbers to be printed, is there any way to typecast numbers to text – yogesh May 06 '18 at 13:59
  • @yogesh I'll try some things. – Skillmon May 06 '18 at 14:01
  • Have you tried seqsplit? https://tex.stackexchange.com/a/13688/121944 – AML May 06 '18 at 14:05

2 Answers2

4

I defined a new column type, which introduces a valid break point after each token in a cell. Funny enough this is very similar to an answer provided in the link AML posted (that I've seen after writing the code):

\documentclass{article}

\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{array}
\usepackage{collcell}

\newcolumntype{N}[1]{>{\collectcell\everytokenbreak}p{#1}<{\endcollectcell}}
\makeatletter
\newcommand\everytokenbreak[1]
  {%
    \everytokenbreak@#1&%
  }
\long\def\everytokenbreak@#1%
  {%
    \ifx&#1
    \else
      #1\hspace{0pt plus 1pt minus 1pt}%
      \expandafter\everytokenbreak@
    \fi
  }
\makeatother

\begin{document}
\begin{table}
\begin{center}
\caption{Results.}\label{tab1}
\begin{tabular}{|N{0.5cm}|N{0.5cm}|N{2cm}|N{2cm}|N{2cm}|N{2cm}|N{2cm}|N{0.5cm}|}
\hline
N & KS & g & n & C & $\lambda(n)$ & $\mu$ & R\\
\hline
1 &
 32 &
 1572324240 &
 1572324239 &
 943290716551438163 &
 1572244920 &
 1470930645&6\\
\hline
2 &
 64 &
 4159540661949250490 &
 4159540661949250489 &
 14726610731536157220276939497631624989 &
 4159171243689855120&3091093397568475626 &
 6\\
\hline
3 &
 96 &
 17921013728107489666861417152 &
 17921013728107489666861417151 &
 319644167630919465013897831470640254404402368723868992349 &
 17918883386300536523002183680&
 8310947063368032641748342092 &
 6\\
\hline
4 &
 128 &
 10960388158297871697330151881871037028 &
 10960388158297871697330151881871037027 &
 106925141663462215096945420078312037311355711106757002541655645931678791491 &
 10958297067198453652392990431562024960 & 
 3253082388973481812242917579299455335 &
 6\\ 
\hline
5 &
 160 &
 11181085000393941012433719385538976929750386340 &
 11181085000393941012433719385538976929750386339 &
 79684675709633819762973841355295907051437943828599200481216296703376032895835669790667255501 &
 11178266769966960229108283302064411639808000000 &
 4208406996756154635702287087616339813762920102 &
 6\\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}

enter image description here

Skillmon
  • 60,462
3

You can also load the seqsplit package and that wrap big numbers in \seqsplit{} as demonstrated here.

\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{array}
\usepackage{seqsplit} % added this package
\begin{document}
\begin{table}
\begin{center}
\caption{Results.}\label{tab1}
\begin{tabular}{|p{0.5cm}|p{0.5cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{0.5cm}|}
\hline
N & KS & g & n & C & $\lambda(n)$ & $\mu$ & R\\
\hline
1 &
 32 &
 1572324240 &
 1572324239 &
 \seqsplit{943290716551438163} &
 1572244920 &
 1470930645&6\\
\hline
2 &
 64 &
 \seqsplit{4159540661949250490} &
 \seqsplit{4159540661949250489} &
 \seqsplit{14726610731536157220276939497631624989} &
 \seqsplit{4159171243689855120} & \seqsplit{3091093397568475626} &
 6\\
\hline
3 &
 96 &
 \seqsplit{17921013728107489666861417152} &
 \seqsplit{17921013728107489666861417151} &
 \seqsplit{319644167630919465013897831470640254404402368723868992349} &
 \seqsplit{17918883386300536523002183680} &
 \seqsplit{8310947063368032641748342092} &
 6\\
\hline
4 &
 128 &
 \seqsplit{10960388158297871697330151881871037028} &
 \seqsplit{10960388158297871697330151881871037027} &
 \seqsplit{106925141663462215096945420078312037311355711106757002541655645931678791491} &
 \seqsplit{10958297067198453652392990431562024960} & 
 \seqsplit{3253082388973481812242917579299455335} &
 6\\ 
\hline
5 &
 160 &
 \seqsplit{11181085000393941012433719385538976929750386340} &
 \seqsplit{11181085000393941012433719385538976929750386339} &
 \seqsplit{79684675709633819762973841355295907051437943828599200481216296703376032895835669790667255501} &
 \seqsplit{11178266769966960229108283302064411639808000000} &
 \seqsplit{4208406996756154635702287087616339813762920102} &
 6\\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}

enter image description here

AML
  • 2,265