5

Formula protruding outside a paragraph

I am writing a document that involves several lengthy mathematical expressions, tables that have to be adjacent, and large algorithms. The documentclass in use is 'book'. Despite the many attempts to alter the margins using the the 'geometry' package, I am unable to arrive at a universal solution for the entire document. Either I find a scattered text with unfavorable white-spaces, an equation protruding outside a paragraph, or an improperly positioned table(s)/figure(s)/algorithm. I have already tried commands like

\newgeometry{margin = 2cm}
% Some text/figure goes here
\restoregeometry

Here is a minimum working example:

\documentclass[11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage[table]{xcolor}  % Modern color package (used for text and tables)

\begin{document}
\chapter{Introduction}
\lipsum

\begin{table}[H]
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}
 \hline
 1 & 2 & 3 & 4 & 5 & 6 \\
 \hline
 7 & 8 & 9 & 10 & 11 & 12 \\
 \hline
 13 & 14 & 15 & 16 & 17 & 18 \\
 \hline
 19 & 20 & 21 & 22 & 23 & \cellcolor{green!25}24 \\
 \hline
 25 & 26 & 27 & 28 & 29 & 30 \\
 \hline
 31 & 32 & 33 & 34 & 35 & 36\\
 \hline
\end{tabular}
$\Longrightarrow$
\begin{tabular}{|c|c|c|c|c|c|}
 \hline
 1 & 2 & 3 & $2 \cdot 2$ & 5 & $2 \cdot 3$ \\
 \hline
 7 & $2 \cdot 2 \cdot 2$ & $3 \cdot 3$ & $2 \cdot 5$ & 11 & $2 \cdot 2 \cdot 3$ \\
 \hline
 13 & $2 \cdot 7$ & $3 \cdot 5$ & $2 \cdot 2 \cdot 2 \cdot 2$ & 17 & $2 \cdot 3 \cdot 3$ \\
 \hline
 19 & $2 \cdot 2 \cdot 5$ & $3 \cdot 7$ & $2 \cdot 11$ & 23 & \cellcolor{green!25} $2 \cdot 2 \cdot 2 \cdot 3$ \\
 \hline
 25 & $2 \cdot 13$ & $3 \cdot 9$ & $2 \cdot 2 \cdot 7$ & 29 & $2 \cdot 3 \cdot 5$ \\
 \hline
 31 & $2 \cdot 2 \cdot 2 \cdot 4$ & $3 \cdot 11$ & $2 \cdot 17$ & 35 & $2 \cdot 2 \cdot 2 \cdot 3 \cdot 3$\\
 \hline
 \end{tabular} \par
\bigskip
\caption{Example of factoring using sieving by $p = 2$ three times, then by $p = 3$.\label{Table:FactoringBySieving}} 
\end{center}
\end{table}

\section{Historical background}

\lipsum

\end{document}

Any suggestions?

  • 1
    A minimal working example would be great. So we have something to work with... – Manuel Dec 12 '13 at 15:29
  • [H] is not a standard float type although latex doesn't report an error it is silently ignored. If you meant to use the H type from the float package, you need to load that package. Other than that I don't see anything wrong? – David Carlisle Dec 12 '13 at 16:50
  • Thank you. Actually I included the float package, removed the 'H' specifier, and vice versa, however, the problem is still standing; i.e., the two tables that look stacked should look adjacent (with the arrow in between). A one-page algorithm, found here is also transgressing over the margins. I am having a total of 15 warnings and 17 bad boxes in a 53-page document. Perhaps a manual solution to be sought is to stretch the margins on a very local scale without influencing the entire page. Is that possible/correct? – Abdullah Heyari Dec 12 '13 at 17:52
  • Unfortunately, didn't work. I couldn't even spot any effect the '\begin{adjustwidth}{-2.0cm}{-2.0cm}' command had on the document. – Abdullah Heyari Dec 12 '13 at 18:46

1 Answers1

3

I can't address the other issues you mention, but in the case of the table you show embedded in your (not so) minimal working example, issuing the command \setlength\tabcolsep{2.5pt} after \begin{table} and before \centering will ensure that the two tabular environments can be typeset side by side. (The default value of \tabcolsep is 6pt; I see no reason to maintain the default.)

In fact, since the tables contain quite a few expressions that require a math environment, I'd recommend you use array environments instead of tabular environments -- and issue the command \setlength\arraycolsep{2.5pt} to shrink the amount of inter-column whitespace. This will save you from having to type lots and lots of $ symbols.

enter image description here

\documentclass[11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
\begin{document}
\begin{table}
\setlength\arraycolsep{2.5pt}
\centering
$\begin{array}{|c|c|c|c|c|c|}
 \hline
 1 & 2 & 3 &  4 &  5 &  6 \\
 \hline
 7 & 8 & 9 & 10 & 11 & 12 \\
 \hline
 13 & 14 & 15 & 16 & 17 & 18 \\
 \hline
 19 & 20 & 21 & 22 & 23 & \cellcolor{green!25}24 \\
 \hline
 25 & 26 & 27 & 28 & 29 & 30 \\
 \hline
 31 & 32 & 33 & 34 & 35 & 36\\
 \hline
\end{array}
\Longrightarrow  
\begin{array}{|c|c|c|c|c|c|}
 \hline
 1 & 2 & 3 &   2 \cdot 2   & 5 &   2 \cdot 3   \\
 \hline
 7 &   2 \cdot 2 \cdot 2   &   3 \cdot 3   &   2 \cdot 5   & 11 &   2 \cdot 2 \cdot 3   \\
 \hline
 13 &   2 \cdot 7   &   3 \cdot 5   &   2 \cdot 2 \cdot 2 \cdot 2   & 17 &   2 \cdot 3 \cdot 3   \\
 \hline
 19 &   2 \cdot 2 \cdot 5   &   3 \cdot 7   &   2 \cdot 11   & 23 & \cellcolor{green!25}   2 \cdot 2 \cdot 2 \cdot 3   \\
 \hline
 25 &   2 \cdot 13   &   3 \cdot 9   &   2 \cdot 2 \cdot 7   & 29 &   2 \cdot 3 \cdot 5   \\
 \hline
 31 &   2 \cdot 2 \cdot 2 \cdot 4   &   3 \cdot 11   &   2 \cdot 17   & 35 &   2 \cdot 2 \cdot 2 \cdot 3 \cdot 3  \\
 \hline
\end{array}$ 

\caption{Example of factoring using sieving by $p = 2$ three times, then by $p = 3$.\label{Table:FactoringBySieving}} 
\end{table}
\end{document}
Mico
  • 506,678
  • Thank you. This certainly came as a solution to part of the problem which seems not to have a single-step solution. Also, it introduced me to the potential advantage of 'array' over 'tabular' environments. The document is still overwhelmed with 30 'bad boxes', however, I think a lot of manual work has to be done (including the introduction of artificial paragraphs!) – Abdullah Heyari Dec 13 '13 at 21:15