表格宽度超出右边距

表格宽度超出右边距

我有以下表格。我不知道如何编辑表格,使其不会超出右边距的末尾。换句话说,我希望表格在边距(或页面宽度)内。在此处输入图片描述

\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

您需要将表格中的长行拆分为多行。一种方法是使用p{>width>}(参见 Roman Picot 的回答),另一种方法是使用\begin{tabularx}{<table width>}{...}而不是\begin{tabular}{...}环境。它能够自动调整列宽以保留表格宽度的空间。当然,要使用它,您应该tabularx在序言中添加包:

\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}

在此处输入图片描述

答案2

您可以使用p{width}所需列的宽度大小(例如 10 厘米):

\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}

产生的输出:

在此处输入图片描述

相关内容