[Tex/LaTex] table width passes right margin

marginstables

I have the following table. I have no idea how to edit in such a way that it does not overload till the end of the right margin. In other words I want the table within the margins (or page width).enter image description here

\begin{tabular}{| c | l |}
\hline
$d$ & Primes that occurs in the denominator of $d$ \\
\hline
3 & -\\
\hline
6 & 2\\
\hline
12& 2, 11, 127\\
\hline
24  &2, 3, 11, 19, 43, 59, 127, 16490213\\
\hline
51  &29, 3041, 11497, 115565611397334238169231623190182913, 2836028200003852058503272908875165997\\
\hline
102 &2, 29, 557, 1063, 3041, 3331, 5147, 11497,  531847, 8769247, 108649481, 204147583, 1708442713 (cofactor 262 digit)\\
\hline
204 &2, 11, 29, 127, 211, 557, 1063, 3041, 3331, 5147, 8147, 11497, 531847 (cofactor 1256 digit)\\
\hline
267 &173, 28949\\
\hline
408 &2, 3, 11, 19, 29, 43, 59, 127, 211, 557, 1063, 3041, 3331, 5147, 5233, 8147, 11497 \\
\hline
534 &2, 173, 383, 1103, 6863, 20177, 28949\\
\hline
1068    &2, 11, 127, 173, 383, 1103, 2801, 4339, 4993, 6863, 20177, 28949\\
\hline
2136    &2, 3, 11, 19, 43, 59, 127, 173, 383, 1103, 2801, 4339\\
\hline
4539,9078,18156,36312   &   29, 173, 3041, 11497, 28949\\
\hline
\end{tabular}

Best Answer

You need to breack to long rows in your table in multi line rows. One way is usep{>width>} (see Roman Picot answer), the other way is to use \begin{tabularx}{<table width>}{...} instead of \begin{tabular}{...} environment. It is able to automatically adapt column width to remain space of table width. Of course, for its use you should add package tabularx in preamble:

\documentclass{article}
    \usepackage{tabularx}

    \usepackage{showframe}% for show text borders

    \begin{document}
\noindent
\begin{tabularx}{\textwidth}{|c|>{\raggedright\arraybackslash}X |}
\hline
$d$ & Primes that occurs in the denominator of $d$ \\
\hline
3 & -\\
\hline
6 & 2\\
\hline
12& 2, 11, 127\\
\hline
24  &2, 3, 11, 19, 43, 59, 127, 16490213\\
\hline
51  &29, 3041, 11497, 115565611397334238169231623190182913, 2836028200003852058503272908875165997\\
\hline
102 &2, 29, 557, 1063, 3041, 3331, 5147, 11497,  531847, 8769247, 108649481, 204147583, 1708442713 (cofactor 262 digit)\\
\hline
204 &2, 11, 29, 127, 211, 557, 1063, 3041, 3331, 5147, 8147, 11497, 531847 (cofactor 1256 digit)\\
\hline
267 &173, 28949\\
\hline
408 &2, 3, 11, 19, 29, 43, 59, 127, 211, 557, 1063, 3041, 3331, 5147, 5233, 8147, 11497 \\
\hline
534 &2, 173, 383, 1103, 6863, 20177, 28949\\
\hline
1068    &2, 11, 127, 173, 383, 1103, 2801, 4339, 4993, 6863, 20177, 28949\\
\hline
2136    &2, 3, 11, 19, 43, 59, 127, 173, 383, 1103, 2801, 4339\\
\hline
4539,9078,18156,36312   &   29, 173, 3041, 11497, 28949\\
\hline
\end{tabularx}
    \end{document}

enter image description here