2

I have this table in my MWE. In the 2nd table, the cell colors seem to bleed over into the margin. I have tried to set various parameters with the tabularx and in the multicol to reduce this but it isn't exact. Is there a reason both linewidth and textwidth offer different widths on the same page. In other words, both tables are identical, except with the multicol which I image is the issue.

\documentclass[letterpaper]{memoir}
\usepackage{color, colortbl, longtable}
\usepackage{booktabs}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{multicol}
\usepackage{tabularx}
\usepackage{lipsum}

\begin{document}

\lipsum[1]

\begin{center}
{\rowcolors{2}{black!10}{white}
\begin{tabularx}{\linewidth}{lX<{\raggedright}X<{\raggedright}}
\toprule
\textbf{Property}   &       \textbf{Addition}       &       \textbf{Multiplication} \\
\midrule
Associative     &   $\mathbf{A + (B + C) = (A + B) + C}$
                    $2 + (3 + 4) = (2 + 3) + 4$     
                                                    &       $\mathbf{A \times (B \times C) = 
                                                            (A \times B) \times C}$         
                                                            $2 \times (3 \times 4) = (2 \times 
                                                            3) \times 4$ \\
                &   Basically, if you only see addition 
                    signs around, it's okay, group the 
                    numbers however you want        &       Same deal here. If there's nothing 
                                                            but multiplication, it doesn't matter 
                                                            where the parentheses are. \\
\midrule
Commutative     &   $\mathbf{A + B = B + A}$ \newline
                    $5 + 7 = 7 + 5$                 &       $\mathbf{A \times B = B \times A}$ \newline
                                                            $5 \times 7 = 7 \times 5$ \\
                &   No big deal. Addition works in 
                    any order.                      &       Same! Multiplication doesn't care about 
                                                            order. \\
\midrule
Identity            &   $\mathbf{A + 0 = A}$ \newline
                    $3 + 0 = 3$                     &       $\mathbf{A \times 1 = A}$ \newline
                                                            $3 \times 1 = 3$ \\
                &   It's good to remember this one.
                    Anything plus zero is just 
                    itself.                         &       For multiplication, anything times one 
                                                            is itself. \\
\bottomrule
\end{tabularx} }

\bigskip
{\rowcolors{2}{black!10}{white}
\begin{tabularx}{\textwidth}{XX}
\toprule
        \multicolumn{2}{c}{\textbf{Distributive:}} \\       
\midrule
        $\mathbf{A(B + C) = A 
        \times B + A \times C}$         &   
                                            $7(3 + 1) = 7 \times 3 + 7 \times 1$    \\
        \multicolumn{2}{p{\textwidth}}{
        This will help you a lot. If there's
        more than one number inside 
        parentheses, then you can do 
        the operation (in this case, 
        multiplying by $7$) to each 
        number in the parentheses
        to simplify things.} \\
\bottomrule
\end{tabularx}}
\end{center}

\end{document}

1 Answer 1

3

You have two \tabcolsep too many. With

\multicolumn{2}{p{\textwidth-2\tabcolsep}}

you get the required width. Load the calc package. Note that multicol is not required, it is used for different purposes (text in two or more columns). I left draft to show that the overfull box message you get is not due to the background color, but to something in the first table.

\documentclass[letterpaper,draft]{memoir}
\usepackage{color, colortbl, longtable,calc}
\usepackage{booktabs}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{tabularx}
\usepackage{lipsum}

\begin{document}

\lipsum[1]

\begin{center}
{\rowcolors{2}{black!10}{white}
\begin{tabularx}{\linewidth}{lX<{\raggedright}X<{\raggedright}}
\toprule
\textbf{Property}   &       \textbf{Addition}       &       \textbf{Multiplication} \\
\midrule
Associative     &   $\mathbf{A + (B + C) = (A + B) + C}$
                    $2 + (3 + 4) = (2 + 3) + 4$     
                                                    &       $\mathbf{A \times (B \times C) = 
                                                            (A \times B) \times C}$         
                                                            $2 \times (3 \times 4) = (2 \times 
                                                            3) \times 4$ \\
                &   Basically, if you only see addition 
                    signs around, it's okay, group the 
                    numbers however you want        &       Same deal here. If there's nothing 
                                                            but multiplication, it doesn't matter 
                                                            where the parentheses are. \\
\midrule
Commutative     &   $\mathbf{A + B = B + A}$ \newline
                    $5 + 7 = 7 + 5$                 &       $\mathbf{A \times B = B \times A}$ \newline
                                                            $5 \times 7 = 7 \times 5$ \\
                &   No big deal. Addition works in 
                    any order.                      &       Same! Multiplication doesn't care about 
                                                            order. \\
\midrule
Identity            &   $\mathbf{A + 0 = A}$ \newline
                    $3 + 0 = 3$                     &       $\mathbf{A \times 1 = A}$ \newline
                                                            $3 \times 1 = 3$ \\
                &   It's good to remember this one.
                    Anything plus zero is just 
                    itself.                         &       For multiplication, anything times one 
                                                            is itself. \\
\bottomrule
\end{tabularx} }

\bigskip
{\rowcolors{2}{black!10}{white}
\begin{tabularx}{\textwidth}{XX}
\toprule
        \multicolumn{2}{c}{\textbf{Distributive:}} \\       
\midrule
        $\mathbf{A(B + C) = A 
        \times B + A \times C}$         &   
                                            $7(3 + 1) = 7 \times 3 + 7 \times 1$    \\
        \multicolumn{2}{p{\textwidth-2\tabcolsep}}{
        This will help you a lot. If there's
        more than one number inside 
        parentheses, then you can do 
        the operation (in this case, 
        multiplying by $7$) to each 
        number in the parentheses
        to simplify things.} \\
\bottomrule
\end{tabularx}}
\end{center}

\end{document}

enter image description here

You must log in to answer this question.

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