2

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}
1
  • @Shrina, your second colum is to wide to be fit on the page. You need to limited its width on the way, which will broke to long lines to acceptable width. As you can see from received answers, you have more possibilities to do this.
    – Zarko
    Sep 25, 2015 at 9:40

2 Answers 2

2

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

1
  • Thx @zarko I find this very helpful as my other tables consist of long digits. Great! Sep 25, 2015 at 9:50
3

You can use p{width} with width the size of the column you want(for example 10 cm):

\documentclass{article}


%===============================
\begin{document}

\begin{tabular}{| c | p{10cm} |}
\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}

\end{document}

Output produced:

enter image description here

4
  • great this helped a lot!! by the way, I notice you edited my code because what i did was copy and paste. How did you do that? do i need to use some special command? How to insert the grey box for the latex code. thx. Sep 25, 2015 at 9:35
  • @Sharina when creating/editing a post, you have clickable pictures. One of them is code sample (or something near). You select all the code and click on it and it's done :-) Sep 25, 2015 at 9:39
  • 1
    thank you so much for explaining this.. :-) and thank you for correcting my table. It is working perfectly. Sep 25, 2015 at 9:43
  • @Sharina Select the code and press Cntrl + K
    – user11232
    Sep 25, 2015 at 10:09

You must log in to answer this question.

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