# Table inside table going past margin

How can I have the tabularx inside question 6 to evenly split into 2 and not go past the margins?
(I am currently using p{0.25cm}p{7cm} which is not optimal as I need to manually specify the width)

Sub-questions (not as important):
How can I line up the (a) and (b) from question 5 to the (a) in question 6?
How can I indent the i., ii. and iii. from question 6 so that it does not line up with the (a) and (b)?

Note that the example below works, but the style and formatting isn't optimal (I'm also getting 2 Underfull \hbox and 7 Overfull \hbox messages).
Also note that I'm very new to LaTeX typesetting (only installed it yesterday!) and will appreciate any feedback on the overall style of the code

\documentclass[12pt]{article}

% Set page margin to 1 inch on all sides
\usepackage[margin=1in]{geometry}

% Required for custom enumeration styles
\usepackage{enumerate}

\usepackage{multicol}

\usepackage{tabularx}

% Increase line height for table
\setlength{\extrarowheight}{10pt}

\begin{document}

\begin{center}
\begin{Large}My Title\end{Large}\\
\end{center}

\begin{enumerate}
\setcounter{enumi}{4}

\item
The cumulative frequency graph below represents the height (in meters) of 100 people living in London. (Graph omitted)

\begin{enumerate}[(a)]
\item
Estimate

\begin{multicols}{2}
\begin{enumerate}[i.]
\item the median height
\item the 75\textsuperscript{th} percentile of the height
\end{enumerate}
\end{multicols}

\item \ldots
\end{enumerate}

\item
Sketch the solid whose region is given by the integral:

\begin{tabularx}{\textwidth}{X|X}
(a) $\int_0^2 \int_0^3 \int_0^4 dz\ dx\ dy$ & (b) $\int_0^3 \int_{x^2}^{9} \int_0^{e^{5^2}} dz\ dy\ dx$\\
Rewrite the above integral using the orders: & Rewrite the above integral using the orders:\\
{
\begin{tabularx}{\textwidth}{p{0.25cm}p{7cm}}
i. & $dx\,dy\,dz$\\
ii. & $dy\,dx\,dz$\\
iii. & Evaluate each of the above 3 integrals using your calculator
\end{tabularx}
}
&
{
\begin{tabularx}{\textwidth}{p{0.25cm}p{7cm}}
i. & $dy\,dz\,dx$\\
ii. & $dx\,dy\,dz$\\
iii. & Evaluate each of the above 3 integrals using your calculator
\end{tabularx}
}\\
\end{tabularx}

\end{enumerate}
\end{document}


For those who don't want to compile the document, this is what it looks like right now (click for larger version):

• You have hard-coded p{7cm} in your tables. If you replace them by p{6cm} the table does no longer overshoot. – user121799 Dec 17 '17 at 19:48
• tabularx has to have an X column so \begin{tabularx}{\textwidth}{p{0.25cm}p{7cm}} is wrong, – David Carlisle Dec 17 '17 at 19:50

Two kinds of solution:

1) all automatic without tables, if the two sides of the multicols are of different height, you could use \columnbreak, as in points 7. and 8. of my MWE:

\documentclass[12pt]{article}
% Set page margin to 1 inch on all sides
\usepackage[margin=1in]{geometry}

% Required for custom enumeration styles
\usepackage{enumerate}

\usepackage{multicol}

\usepackage{tabularx}

% Increase line height for table
\setlength{\extrarowheight}{10pt}

\begin{document}
\begin{center}
\begin{Large}My Title\end{Large}\\
\end{center}

\begin{enumerate}
\setcounter{enumi}{4}
\item
The cumulative frequency graph below represents the height (in meters) of 100 people living in London. (Graph omitted)

\begin{enumerate}[(a)]
\item
Estimate

\begin{multicols}{2}
\begin{enumerate}[i.]
\item the median height
\item the 75\textsuperscript{th} percentile of the height
\end{enumerate}
\end{multicols}

\item \ldots
\end{enumerate}

\item
Sketch the solid whose region is given by the integral:
\begin{multicols}{2}\setlength{\columnseprule}{0.4pt}
\begin{enumerate}[(a)]
\item $\int_0^2 \int_0^3 \int_0^4 dz\ dx\ dy$

Rewrite the above integral using the orders:

\begin{enumerate}[i.]
\item $dx\,dy\,dz$
\item $dy\,dx\,dz$
\item Evaluate each of the above 3 integrals using your calculator
\end{enumerate}
\item $\int_0^3 \int_{x^2}^{9} \int_0^{e^{5^2}} dz\ dy\ dx$

Rewrite the above integral using the orders:

\begin{enumerate}[i.]
\item $dy\,dz\,dx$
\item $dx\,dy\,dz$
\item Evaluate each of the above 3 integrals using your calculator
\end{enumerate}
\end{enumerate}

\end{multicols}
\item
In case the first column is longer than the second one:
\begin{multicols}{2}\setlength{\columnseprule}{0.4pt}
\begin{enumerate}[(a)]
\item in this case the first column has a text longer than the second one
\columnbreak
\item blah
\end{enumerate}
\end{multicols}
\item
In case the second column is longer than the first one:
\begin{multicols}{2}\setlength{\columnseprule}{0.4pt}
\begin{enumerate}[(a)]
\item blah blah blah
\columnbreak
\item in this case the second column has a text longer than the first one
\end{enumerate}
\end{multicols}
\end{enumerate}
\end{document}


2) with customize counters, and tables:

\documentclass[12pt]{article}
% Set page margin to 1 inch on all sides
\usepackage[margin=1in]{geometry}

% Required for custom enumeration styles
\usepackage{enumerate}

\usepackage{multicol}

\usepackage{tabularx}
% Increase line height for table
\setlength{\extrarowheight}{10pt}

\newcounter{itemalpha}
\newcounter{itemroman}
\newcommand*{\itemalpha}{\stepcounter{itemalpha}(\alph{itemalpha})}
\newcommand*{\resetitemalpha}{\setcounter{itemalpha}{0}}
\newcommand*{\itemroman}{\stepcounter{itemroman}\roman{itemroman}.}
\newcommand*{\resetitemroman}{\setcounter{itemroman}{0}}

\begin{document}

\begin{center}
\begin{Large}My Title\end{Large}\\
\end{center}

\begin{enumerate}
\setcounter{enumi}{4}

\item
The cumulative frequency graph below represents the height (in meters) of 100 people living in London. (Graph omitted)

\begin{enumerate}[(a)]
\item
Estimate

\begin{multicols}{2}
\begin{enumerate}[i.]
\item the median height
\item the 75\textsuperscript{th} percentile of the height
\end{enumerate}
\end{multicols}

\item \ldots
\end{enumerate}

\item
Sketch the solid whose region is given by the integral:

\begin{tabular}{@{}r@{\hspace{\labelsep}}p{.41\textwidth}|r@{\hspace{\labelsep}}p{.41\textwidth}@{}}
\itemalpha &$\int_0^2 \int_0^3 \int_0^4 dz\ dx\ dy$ & \itemalpha &$\int_0^3 \int_{x^2}^{9} \int_0^{e^{5^2}} dz\ dy\ dx$\\
&Rewrite the above integral using the orders: & & Rewrite the above integral using the orders:\\
&
{
\begin{tabular}{@{}r@{\hspace{\labelsep}}p{.37\textwidth}@{}}
\itemroman & $dx\,dy\,dz$\\
\itemroman & $dy\,dx\,dz$\\
\itemroman & Evaluate each of the above 3 integrals using your calculator
\end{tabular}
}
& &
{
\begin{tabular}{@{}r@{\hspace{\labelsep}}p{.37\textwidth}@{}}
\resetitemroman\itemroman & $dy\,dz\,dx$\\
\itemroman & $dx\,dy\,dz$\\
\itemroman & Evaluate each of the above 3 integrals using your calculator
\end{tabular}
}\\
\end{tabular}

\end{enumerate}
\end{document}


A similar solution, with some improvements brought by the medium-size commands from nccmath, playing with some lengths. The main difference is that I don't nest tabularxs inside another tabularx, but an enumerate (customised with enumitem), so as to obtain a (referable) automatic numbering:

    \documentclass[12pt]{article}

% Set page margin to 1 inch on all sides
\usepackage[margin=1in, showframe]{geometry}

% Required for custom enumeration styles
\usepackage[shortlabels]{enumitem}

\usepackage{multicol}
\usepackage{ragged2e}
\usepackage{tabularx}
\usepackage{nccmath}
\newcommand{\mint}{\medint\int}
% Increase line height for table
\setlength{\extrarowheight}{10pt}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother

\begin{document}

\begin{center}
\begin{Large}My Title\end{Large}\\
\end{center}

\begin{enumerate}
\setcounter{enumi}{4}

\item
The cumulative frequency graph below represents the height (in meters) of 100 people living in London. (Graph omitted)

\begin{enumerate}[(a)]
\item
Estimate
\begin{multicols}{2}
\begin{enumerate}[i., wide = 0pt]
\item the median height
\item the 75\textsuperscript{th} percentile of the height
\end{enumerate}
\end{multicols}
\item \ldots
\end{enumerate}

\item
Sketch the solid whose region is given by the integral:

\begin{tabularx}{\linewidth}{>{\compress}X|>{\compress}X}
(a) $\mint_0^2 \mint_0^3 \mint_0^4 dz\, dx\, dy$ & (b) $\mint_0^3 \mint_{x^2}^{9} \mint_0^{e^{5^2}} dz\, dy\, dx$\\
Rewrite the above integral using the orders: & Rewrite the above integral using the orders:\\[-1.5ex]
\begin{enumerate}[i., leftmargin = *, nosep]
\item $dx\,dy\,dz$
\item $dx\,dy\,dz$
\item Evaluate each of the above 3 integrals using your calculator
\end{enumerate}
&
\begin{enumerate}[i., leftmargin = *, nosep]
\item $dx\,dy\,dz$
\item $dx\,dy\,dz$
\item Evaluate each of the above 3 integrals using your calculator
\end{enumerate}
\\
\end{tabularx}
\end{enumerate}

\end{document}


You could use the following code, in which I have replaced the p{7cm} by X columns as well as all occurences of \textwidth by \linewidth.

\documentclass[12pt]{article}

% Set page margin to 1 inch on all sides
\usepackage[margin=1in]{geometry}

% Required for custom enumeration styles
\usepackage{enumerate}

\usepackage{multicol}

\usepackage{tabularx}

% Increase line height for table
\setlength{\extrarowheight}{10pt}

\begin{document}

\begin{center}
\begin{Large}My Title\end{Large}\\
\end{center}

\begin{enumerate}
\setcounter{enumi}{4}

\item
The cumulative frequency graph below represents the height (in meters) of 100 people living in London. (Graph omitted)

\begin{enumerate}[(a)]
\item
Estimate

\begin{multicols}{2}
\begin{enumerate}[i.]
\item the median height
\item the 75\textsuperscript{th} percentile of the height
\end{enumerate}
\end{multicols}

\item \ldots
\end{enumerate}

\item
Sketch the solid whose region is given by the integral:

\begin{tabularx}{\linewidth}{X|X}
(a) $\int_0^2 \int_0^3 \int_0^4 dz\ dx\ dy$ & (b) $\int_0^3 \int_{x^2}^{9} \int_0^{e^{5^2}} dz\ dy\ dx$\\
Rewrite the above integral using the orders: & Rewrite the above integral using the orders:\\
{
\begin{tabularx}{\linewidth}{p{0.25cm}X}
i. & $dx\,dy\,dz$\\
ii. & $dy\,dx\,dz$\\
iii. & Evaluate each of the above 3 integrals using your calculator
\end{tabularx}
}
&
{
\begin{tabularx}{\linewidth}{p{0.25cm}X}
i. & $dy\,dz\,dx$\\
ii. & $dx\,dy\,dz$\\
iii. & Evaluate each of the above 3 integrals using your calculator
\end{tabularx}
}\\

\end{tabularx}

\end{enumerate}

\end{document}


Alternatively, you could use a solution like the following. I have replaced the inner tabularx environment by an enumerate environment. To set it up correctly, I have additionally replaced the enumerate package by the more powerful enumitem package.

\documentclass[12pt]{article}

% Set page margin to 1 inch on all sides
\usepackage[margin=1in]{geometry}

% Required for custom enumeration styles
\usepackage{enumitem}

\usepackage{multicol}

\usepackage{tabularx}

% Increase line height for table
\setlength{\extrarowheight}{10pt}

\begin{document}

\begin{center}
\begin{Large}My Title\end{Large}\\
\end{center}

\begin{enumerate}
\setcounter{enumi}{4}

\item
The cumulative frequency graph below represents the height (in meters) of 100 people living in London. (Graph omitted)

\begin{enumerate}[label=({\alph*})]
\item  Estimate

\begin{multicols}{2}
\begin{enumerate}[label={\roman*}.]
\item the median height
\item the 75\textsuperscript{th} percentile of the height
\end{enumerate}
\end{multicols}

\item \ldots
\end{enumerate}

\item
Sketch the solid whose region is given by the integral:

\begin{tabularx}{\linewidth}{X|X}
(a) $\int_0^2 \int_0^3 \int_0^4 dz\ dx\ dy$ & (b) $\int_0^3 \int_{x^2}^{9} \int_0^{e^{5^2}} dz\ dy\ dx$\\
Rewrite the above integral using the orders: & Rewrite the above integral using the orders:\\
\begin{minipage}[t]{\linewidth}
\begin{enumerate}[label={\roman*}.,align=left]
\item  $dx\,dy\,dz$
\item $dy\,dx\,dz$
\item Evaluate each of the above 3 integrals using your calculator
\end{enumerate}
\end{minipage}&
\begin{minipage}[t]{\linewidth}
\begin{enumerate}[label={\roman*}.,align=left]
\item  $dx\,dy\,dz$
\item $dy\,dx\,dz$
\item Evaluate each of the above 3 integrals using your calculator
\end{enumerate}
\end{minipage}
\end{tabularx}

\end{enumerate}

\end{document}


To indent i., ii. ... you can add the option leftmargin=1.75cm to the corresponding \begin{enumerate}[label={\roman*}.,align=left] lines.

The following image compares the output of the two above MWEs. On the left: enumerate approac, on the right: nested tables, black lines are caused by the package showframe, that I have included to visualize the margins)