[Tex/LaTex] Table exceeding paper margin

tables

I have the following MWE :

\documentclass{article}
\usepackage{amsmath,setspace}
\usepackage{tabularx,ragged2e,booktabs,caption}
\usepackage{tabu}
\begin{document}
\begin{center}
\begin{tabular}{ |c|c|c|c| } 
 \hline
 $n$ & $nP=(x,y)$ on $E$ & corresponding $\phi$ & $m$ \\ 
\hline
\rule{0pt}{4ex}
 $-4$ & $(339,-6156)$ & $-\dfrac{1}{2}$ & $\pm \dfrac{9}{8}, \pm \dfrac{1}{4}\sqrt{949}$ \\ 
\hline
\rule{0pt}{4ex}
 $-3$ & $(6,162)$ & $0$ & $\pm \dfrac{9}{8}$ \\ 
\hline
\rule{0pt}{4ex}
$-2$ & $(51,108)$ & undefined & undefined \\ 
\hline
\rule{0pt}{4ex}
 $-1$ & $(-21,-324)$ & undefined & undefined \\ 
\hline
\rule{0pt}{4ex}
$0$ & $(0,0)$ & $-4/11$  & $\dfrac{1}{10648}\sqrt{\pm\dfrac{391779925}{2}\sqrt{6829} + \dfrac{32625600067}{2}}$, $\dfrac{-1}{10648}\sqrt{\pm\dfrac{391779925}{2}\sqrt{6829} + \dfrac{32625600067}{2}}$ \\ 
\hline
\rule{0pt}{4ex}
 $3$ & $(6,-162)$ & $0$ & $\pm \dfrac{9}{8}$ \\ 
 \hline
\end{tabular}
\end{center}
\end{document}

which gives the following table:
enter image description here

  1. (Red circle) The second last row has 2 elements in it, unfortunately I can't bring down the second element, it just appear to exceed the table. Is there a way to bring down the second element? I used \\ but it did not work.

  2. (Blue circle) I used \rule{0pt}{4ex} to make sure there's a gap between the fraction and upper line, but I can't seem to use \rule{0pt}{4ex} to create a gap between the fraction and lower line. When I try to compile the latex file shows error. Is there a way to fix this?

Best Answer

Some suggestions, in no particular order:

  • Since you're loading the \booktabs package, do make use of it. I.e., get rid of all vertical rules, replace almost all interior horizontal rules with \addlinespace, and use \toprule, \midrule, and \bottomrule for the remaining three horizontal rules.

  • As a happy side-effect of making the change suggested in the previous paragraph, you can also get rid of all (typographic) struts, since there won't be any horizontal lines "too close" to the fractional expressions.

  • Do increase the value of \arraystretch; its default value is 1, but something like 1.5 appears to be more appropriate here.

  • Since virtually all terms in the table are math formulas of one form or another, use an array environment instead of a tabular environment. This lets you get rid of 52 [!] $ symbols...

  • If you're still pressed for (horizontal) space, consider abbreviating some of the words in the header row, as is done in the example below.

  • Last but definitely not least, you must shorten the big expression in the right-hand cell of the next-to-last row of the table. I would like to suggest that you (a) add \pm to the denominator of the first \frac term and (b) omit the entire second term (as well as the comma that separates the two terms). If you must show the second term in full, put it on a separate line.

enter image description here

\documentclass{article}
\usepackage{amsmath,booktabs,array}
\begin{document}
\begin{center}
\renewcommand\arraystretch{1.5}
$\begin{array}{@{} r c c >{\displaystyle}c @{}} 
\toprule
 n & \text{$nP{=}(x,y)$ on $E$} & \text{corresp.\ $\phi$} & m \\ 
\midrule
\addlinespace
 -4 & (339,-6156) & -\frac{1}{2} & \pm \frac{9}{8},\ \pm \frac{1}{4}\sqrt{949} \\ 
\addlinespace
-3  & (6,162) & 0 & \pm \frac{9}{8} \\ 
\addlinespace
-2  & (51,108) & \text{undefined} & \text{undefined} \\ 
\addlinespace
-1  & (-21,-324) & \text{undefined} & \text{undefined} \\ 
\addlinespace
0  & (0,0) & -4/11  & \frac{\pm1}{10648}\sqrt{\pm\frac{391779925}{2}\sqrt{6829} + \frac{32625600067}{2}} \\
%& & & \frac{-1}{10648}\sqrt{\pm\frac{391779925}{2}\sqrt{6829} + \frac{32625600067}{2}}  \\
\addlinespace 
3  & (6,-162) & 0 & \pm \frac{9}{8} \\ 
\addlinespace
\bottomrule
\end{array}$
\end{center}
\end{document}
Related Question