0

In my document I have a number of questions, some with enumerable items and others with no items. I would like the body of each question to have similar margins regardless of contents.

My current workaround is to place the text of questions without enumerable items into descriptions without items. Latex will compile this, but produces an error. How can I easily achieve the same formatting without causing an error?

\documentclass[12pt]{article}

\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb,xfrac}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}

\newenvironment{theorem}[2][Theorem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{lemma}[2][Lemma]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{exercise}[2][Exercise]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{problem}[2][Problem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{question}[2][Question]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{corollary}[2][Corollary]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}

\linespread{1.5}

\begin{document}

\begin{question}{1}\hfill
  \begin{enumerate}
  \item
    $\text{average traffic per user} = 100kbps \times 0.1 = 10kbps$ \\
    $\text{peak traffic per user} = 100kbps$
\end{question}

\begin{question}{2}\hfill
  \begin{description}
  $P_n=(1-\rho)\rho^n$ \\
  $\rho = \sfrac{5.4}{6.0} = 0.9$ \\
  $B = 50, N > B \longrightarrow N >= B + 1$ \\
  $P_N = 1 - \sum_{b}^{B+1}P_{b} = 0.004638397686588025 \approx 0.464\%$ \\
  The packet loss probability due to buffer overflow is $0.464\%$. \\
  \end{description}
\end{question}

\end{document}

error

ERROR: LaTeX Error: \begin{enumerate} on input line 32 ended by \end{trivlist}.

--- TeX said ---

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.36 \end{question}

--- HELP ---
No help available
  • 4
    Please add a minimal working example which reproduces your error – CarLaTeX Jan 29 at 4:11
  • 2
    your code is not compileable – AndréC Jan 29 at 5:03
  • It compiles for me, I'll add the error I get. – Paul Jan 29 at 5:30
  • 2
    It only compiles for you because you have embedded it in a complete document, which starts with \documentclass, loads some packages, has \begin{document} and so on. We do not have any information about the document class you are using, nor on the packages, nor on the output you want to reproduce, so it is hard if not impossible to answer your question. – user121799 Jan 29 at 6:01
  • 2
    The PDF won't be produced if there's an error... A description environment is a list, and a list needs an \item. Yours doesn't, hence the error. Also, what indentation are you referring to with a description that doesn't have any \items? – Werner Jan 29 at 6:03
3

You provided no usable example so I can't show the output, but in all list environments that use \item you can use the optional argument to specify a different label and so \item[] to specify no label at all. In fact this is how most latex displays environment such as center, quote etc are defined, as a one-item list with no no label.

  • Thank you for the suggestion. I'm not sure what I could post besides the entire document itself, as I don't know what it is necessary. – Paul Jan 29 at 8:23
  • 1
    @Paul you should post a complete but small document. between begin document and end document it just needs the question environment you posted, but you should add \documentclass{article} and any packages and definitions required to run it, for example question has no definition by default. A code block that no one can run to see the problem or test answers really does not help clarify the question at all. – David Carlisle Jan 29 at 8:50
  • I have updated my post with a minimal document showing what is going on. – Paul Jan 29 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.