Motivation: I have developed a template to do engineering homework problems (See this question), and am now trying to encapsulate the table formating code for problems and their subsections into a \newenvironment.
The Error: When I run the appended M(N)WE, I get an error message:
! Extra }, or forgotten \endgroup.
<template> \unskip \hfil }
\hskip \tabcolsep \endtemplate
l.24 \begin{given}
The weights of the various components of the truck are ...
Question:
- Am I using this
\newenvironmentcommand the wrong way? - Is it not possible to include the
&and\\table formating commands in a\newenvironment? - What is the right way to accomplish the essence of what I am trying to do?
Attempts: So far, I have tried the following:
- Placing the formating commands outside the
\newenvironment, where I would want the macro to place them. - Using the
environpackage. - Using
tabuinstead oftabular - Using
\tabularand\endtabularinstead of\begin{tabular}and\end{tabular}
All to no avail.
Appended M(N)WE: This is the style I am trying to get to; however, it produces the error I referenced above.
\documentclass[10pt]{article}
\usepackage{units}
\newenvironment{problem}{
\begin{tabular}{l p{5.5in}}
}{
\end{tabular}
\pagebreak
}
\newenvironment{given} { \textbf{Given:} \vspace{0.125in} & }{\\}
\newenvironment{asked} { \textbf{Asked:} \vspace{0.125in } &} {\\}
\newenvironment{sketch} { \textbf{Sketch:} \vspace{0.125in} &} {\\}
\newenvironment{equations} { \textbf{Equations:} \vspace{0.125in} &} {\\}
\newenvironment{solution} { \textbf{Solution:} \vspace{0.125in} &} {\\}
\begin{document}
\pagestyle{empty}
\begin{problem}
\begin{given} The weights of the various components of the truck are show in the sketch below. \end{given}
\begin{asked} Replace this system of forces by an equialent resultant force and specify its location measured from $B$. \end{asked}
\begin{sketch} \begin{center} PUT PICTURE HERE \end{center} \end{sketch}
\begin{equations}
$$\sum F_{x_I} = \sum F_{x_{II}}$$
$$\sum F_{y_I} = \sum F_{y_{II}}$$
$$\sum M_{o_I} = \sum M_{o_{II}}$$
\vspace{.0625 in}
$$M_o = F\times d_\perp$$
\end{equations}
\begin{solution}
$$\sum F_x = F_{x_1} + F_{x_2} + F_{x_3} = 0$$
$$\sum F_y = F_{y_1} + F_{y_2} + F_{y_3} = \unit[3500]{lb} + \unit[5500] {lb} + \unit[1750]{lb} = \unit[10\;750]{lb}$$
\vspace{.0625 in}
$$\sum M_B = M_1 + M_2 + M_3$$
$$\begin{aligned}
M_1 &= F\times d_\perp = \unit[3500]{lb}(\unit[3]{ft}) &= \unit[10\;500]{ft\cdot lb} \\
M_2 &= F\times d_\perp = \unit[5500]{lb}(\unit[3]{ft}+\unit[14]{ft}) &= \unit[93\;500]{ft\cdot lb} \\
M_3 &= F\times d_\perp = \unit[1750]{lb}(\unit[3]{ft}+\unit[14]{ft}+\unit[6]{ft}+\unit[2]{ft}) &= \unit[43\;750]{ft\cdot lb} \vspace{.0625in} \\
M_B &= \unit[10\;500]{ft\cdot lb} + \unit[93\;500]{ft\cdot lb} + \unit[43\;750]{ft\cdot lb} &= \unit[147\;750]{ft\cdot lb}
\end{aligned}$$
\end{solution}
\end{problem}
\end{document}
MWE: Here is a version that does not use \newenvironment, but works, and represents the document I am trying to produce.
\documentclass[10pt]{article}
\usepackage{units}
\begin{document}
\begin{tabular}{l p{5.5in}}
\textbf{Given:} \vspace{.125in} &
The weights of the various components of the truck are show in the sketch below. \\
\textbf{Asked:} \vspace{.125in} &
Replace this system of forces by an equialent resultant force and specify its location measured from $B$. \\
\textbf{Sketch:} \vspace{.125in} &
\begin{center}PUT PICTURE HERE\end{center} \\
\textbf{Equations:} \vspace{.125in} &
$$\sum F_{x_I} = \sum F_{x_{II}}$$
$$\sum F_{y_I} = \sum F_{y_{II}}$$
$$\sum M_{o_I} = \sum M_{o_{II}}$$
\vspace{.0625 in}
$$M_o = F\times d_\perp$$ \\
\textbf{Solution:} \vspace{.125in} &
$$\sum F_x = F_{x_1} + F_{x_2} + F_{x_3} = 0$$
$$\sum F_y = F_{y_1} + F_{y_2} + F_{y_3} = \unit[3500]{lb} + \unit[5500] {lb} + \unit[1750]{lb} = \unit[10\;750]{lb}$$
\vspace{.0625 in}
$$\sum M_B = M_1 + M_2 + M_3$$
$$\begin{aligned}
M_1 &= F\times d_\perp = \unit[3500]{lb}(\unit[3]{ft}) &= \unit[10\;500]{ft\cdot lb} \\
M_2 &= F\times d_\perp = \unit[5500]{lb}(\unit[3]{ft}+\unit[14]{ft}) &= \unit[93\;500]{ft\cdot lb} \\
M_3 &= F\times d_\perp = \unit[1750]{lb}(\unit[3]{ft}+\unit[14]{ft}+\unit[6]{ft}+\unit[2]{ft}) &= \unit[43\;750]{ft\cdot lb} \vspace{.0625in} \\
M_B &= \unit[10\;500]{ft\cdot lb} + \unit[93\;500]{ft\cdot lb} + \unit[43\;750]{ft\cdot lb} &= \unit[147\;750]{ft\cdot lb}
\end{aligned}$$
\end{tabular}
\end{document}



\newenvironment{given} { \textbf{Given:} \vspace{0.125in} & }{\\}as it is like doing{\textbf{Given:}&\\}as environments form a group, you would get similar errors. (If you really want that syntax, anything is possible but it's perhaps confusing to use environment syntax for something that is not a group. – David Carlisle Feb 05 '17 at 16:05\vspace{0.125in}vspace does nothing very useful in anlcell which is horizontal mode – David Carlisle Feb 05 '17 at 16:24\[…\]preferable to$$? – Werner Feb 05 '17 at 17:50