# Having formatting problems I can't seem to figure out

As you should be able to see from the image, my enumerate environment seems to work fine up until I typeset the table, and then things shift to the left margin. I'd like the (a) and (b) to line up, and have the table sit to the right as well.

Any tips?

Here's the code I have...

\documentclass{article}
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\thesection.\Roman{subsection}}

\usepackage{setspace}
\usepackage{amsmath}
\usepackage{caption}
\usepackage{amsfonts}

\RequirePackage[left=1.5in,right=1.5in,top=1.5in,bottom=1.5in]{geometry}

\newcommand\state[1]{\ensuremath{q_{#1}}}
\newcommand\blank{\ensuremath{\sqcup}}
\newcommand\lang{\ensuremath{\mathcal{L}}}

\begin{document}

\begin{enumerate}
\item \textbf{Programming Turing Machines}
\begin{enumerate}
\item  Give a full description of a Turing machine $M = (Q, \Sigma, \Gamma. \state{0}, \state{accept}, \state{reject}, \delta)$ accepting a language $\lang = \{x \in \{0,1\}^{*}\ |\ x\ is\ divisible\ by\ 4 \}$, ignoring trailing 0s; treat blank string as a 0.
\begin{align*}
M = (Q, \Sigma, \Gamma, \state{0}, \state{accept}, \state{reject}, \delta)\\
Q=\{q_{0},q_{1},q_{2},q_{accept},q_{reject}\}\\
\Gamma=\{0,1,\blank\}\\
\Sigma=\Gamma\setminus\{\blank\}
\end{align*}

\captionof{table}{$\delta: Q\times \Gamma \to Q\times \Gamma\times \{L,R\}$}
\begin{tabular}{c|c|c|c|c}
Current State&Current Character&New State&New Character&Move\\
\hline
\state{0}&1&\state{0}&1&R\\
\state{0}&0&\state{0}&0&R\\
\state{0}&\blank&\state{1}&\blank&L\\
\state{1}&1&\state{reject}&-&-\\
\state{1}&0&\state{2}&0&L\\
\state{2}&1&\state{reject}&-&-\\
\state{2}&0&\state{accept}&-&-\\
\hline
\end{tabular}

\bigskip

\item  Give a full description of a Turing machine $M = (Q, \Sigma, \Gamma, \state{0}, \state{accept}, \state{reject}, \delta)$ accepting a language $\lang = \{x \in \{0,1\}^{*}\ |\ x\ does\ not\ have\ repeating\ 1s \}$. ( e.g., x = 110 is rejected and x = 1001 is accepted. )

\begin{align*}
M = (Q, \Sigma, \Gamma, \state{0}, \state{accept}, \state{reject}, \delta)\\
Q=\{q_{0},q_{1},q_{2},q_{accept},q_{reject}\}\\
\Gamma=\{0,1,\blank\}\\
\Sigma=\Gamma\setminus\{\blank\}
\end{align*}

\captionof{table}{$\delta: Q\times \Gamma \to Q\times \Gamma\times \{L,R\}$}
\begin{tabular}{c|c|c|c|c}
Current State&Current Character&New State&New Character&Move\\
\hline
\state{0}&1&\state{0}&1&R\\
\state{0}&0&\state{0}&0&R\\
\state{0}&\blank&\state{1}&\blank&L\\
\state{1}&1&\state{2}&1&L\\
\state{1}&0&\state{1}&0&L\\
\state{1}&\blank&\state{accept}&-&-\\
\state{2}&1&\state{reject}&-&-\\
\state{2}&0&\state{1}&0&L\\
\hline
\end{tabular}

\bigskip

\item  Give a full description of a Turing machine $M = (Q, \Sigma, \Gamma, \state{0}, \state{accept}, \state{reject}, \delta)$ accepting a language $\lang = \{x \in \{0,1\}^{*}\ |\ x\ does\ not\ have\ repeating\ 1s \}$. ( e.g., x = 110 is rejected and x = 1001 is accepted. )
\end{enumerate}
\end{enumerate}

\end{document}

-
Hi agent154, would you be able to complete your snippet to a full compilable document. The \state command, for example, is defined either in your preamble or by a package. You are also missing a closing \end{enumerate} I believe. –  Scott H. Jan 21 '13 at 3:31
@ScottH. I've updated the code. I originally didn't want to include some parts as it had personal info, and some of the custom commands were in a custom package. I copied over all the relevant stuff. –  agent154 Jan 21 '13 at 3:42
thanks! The problem has to do with the caption package although I'm not sure why. Removing the package and the \captionof commands fixes the spacing. Someone, I'm sure, will be able to tell you why. –  Scott H. Jan 21 '13 at 3:48
Check the answer here and see whether that solves the problem: enclose the captionof command in a group. Let us know if that fixes the problem for you (it did for me). –  Scott H. Jan 21 '13 at 3:52
@ScottH. That does help a bit, but the captions are not centered on the tabular anymore. I wonder if there's a better way to do this. Using \begin{table} \end{table} makes it float and my table doesn't even appear where I want it to be on the page. –  agent154 Jan 21 '13 at 3:57
show 1 more comment

The problem seems to be that \captionof resets the left and right margins for the enumerate environment.

Embed the \captionof inside a \parbox like so:

\parbox{\linewidth}{\captionof{table}{$\delta: Q\times \Gamma \to Q\times \Gamma\times \{L,R\}$}}


Using \linewidth should get the correct centering for within you enumerated list. This is because \linewidth is the parameter LaTeX uses to determine how long a line should be at that moment. Note \textwidth will not give you the correct width.

This solution creates a bit of extra vertical space you may not want. But you can easily fix that by adding a \vspace{<dim>} with an appropriately set negative dimension.

Here's a full copy of my MWE:

\documentclass{article}
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\thesection.\Roman{subsection}}

\usepackage{setspace}
\usepackage{amsmath}
\usepackage{caption}
\usepackage{amsfonts}

\RequirePackage[left=1.5in,right=1.5in,top=1.5in,bottom=1.5in]{geometry}

\newcommand\state[1]{\ensuremath{q_{#1}}}
\newcommand\blank{\ensuremath{\sqcup}}
\newcommand\lang{\ensuremath{\mathcal{L}}}

\begin{document}

\begin{enumerate}
\item \textbf{Programming Turing Machines}
\begin{enumerate}
\item  Give a full description of a Turing machine $M = (Q, \Sigma, \Gamma. \state{0}, \state{accept}, \state{reject}, \delta)$ accepting a language $\lang = \{x \in \{0,1\}^{*}\ |\ x\ is\ divisible\ by\ 4 \}$, ignoring trailing 0s; treat blank string as a 0.
\begin{align*}
M = (Q, \Sigma, \Gamma, \state{0}, \state{accept}, \state{reject}, \delta)\\
Q=\{q_{0},q_{1},q_{2},q_{accept},q_{reject}\}\\
\Gamma=\{0,1,\blank\}\\
\Sigma=\Gamma\setminus\{\blank\}
\end{align*}

\parbox{\linewidth}{\captionof{table}{$\delta: Q\times \Gamma \to Q\times \Gamma\times \{L,R\}$}}\vspace{-1ex}
\begin{tabular}{c|c|c|c|c}
Current State&Current Character&New State&New Character&Move\\
\hline
\state{0}&1&\state{0}&1&R\\
\state{0}&0&\state{0}&0&R\\
\state{0}&\blank&\state{1}&\blank&L\\
\state{1}&1&\state{reject}&-&-\\
\state{1}&0&\state{2}&0&L\\
\state{2}&1&\state{reject}&-&-\\
\state{2}&0&\state{accept}&-&-\\
\hline
\end{tabular}

\bigskip

\item  Give a full description of a Turing machine $M = (Q, \Sigma, \Gamma, \state{0}, \state{accept}, \state{reject}, \delta)$ accepting a language $\lang = \{x \in \{0,1\}^{*}\ |\ x\ does\ not\ have\ repeating\ 1s \}$. ( e.g., x = 110 is rejected and x = 1001 is accepted. )

\begin{align*}
M = (Q, \Sigma, \Gamma, \state{0}, \state{accept}, \state{reject}, \delta)\\
Q=\{q_{0},q_{1},q_{2},q_{accept},q_{reject}\}\\
\Gamma=\{0,1,\blank\}\\
\Sigma=\Gamma\setminus\{\blank\}
\end{align*}

\parbox{\linewidth}{\captionof{table}{$\delta: Q\times \Gamma \to Q\times \Gamma\times \{L,R\}$}}\vspace{-1ex}
\begin{tabular}{c|c|c|c|c}
Current State&Current Character&New State&New Character&Move\\
\hline
\state{0}&1&\state{0}&1&R\\
\state{0}&0&\state{0}&0&R\\
\state{0}&\blank&\state{1}&\blank&L\\
\state{1}&1&\state{2}&1&L\\
\state{1}&0&\state{1}&0&L\\
\state{1}&\blank&\state{accept}&-&-\\
\state{2}&1&\state{reject}&-&-\\
\state{2}&0&\state{1}&0&L\\
\hline
\end{tabular}

\bigskip

\item  Give a full description of a Turing machine $M = (Q, \Sigma, \Gamma, \state{0}, \state{accept}, \state{reject}, \delta)$ accepting a language $\lang = \{x \in \{0,1\}^{*}\ |\ x\ does\ not\ have\ repeating\ 1s \}$. ( e.g., x = 110 is rejected and x = 1001 is accepted. )
\end{enumerate}
\end{enumerate}

\end{document}


-
Copying and pasting your solution directly in place of my current \captionof{} line generates many errors... –  agent154 Jan 21 '13 at 4:21
TexMaker isn't being very helpful in copying errors. I try to copy the log and what I paste isn't what I'm seeing in the error window. –  agent154 Jan 21 '13 at 4:26
! LaTeX Error: \begin{document} ended by \end{enumerate}. ! Extra \endgroup –  agent154 Jan 21 '13 at 4:27
Sounds to me like you've got unbalanced parentheses in there somehow. If you copy and paste my entire MWE into its own document, what happens? –  A.Ellett Jan 21 '13 at 4:28
OK. I must have had something missing. It works when I paste your code. Thanks. –  agent154 Jan 21 '13 at 4:30