Text FormattingAlignment over two lists

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: Alignment over two lists

Post by svend_tveskaeg »

I cannot figure out the problem, but I have accepted your answer anyway.

Thank you for your help.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: Alignment over two lists

Post by svend_tveskaeg »

Hmmm! Something was wrong with the file. When I deleted it (again!) and startet with a new one, it complies just fine.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Alignment over two lists

Post by svend_tveskaeg »

The code worked just as I wanted; thank you!

Now I have another request: Is it possible to `restart' the counter for the question or answer from (1) every time I begin a new enviroment?

Thank you in advance, again.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Alignment over two lists

Post by cgnieder »

Oh, I forgot that \stepcounter acts globally! It's easy: add

Code: Select all

\setcounter{question}{0}%
at the beginning of the definition of the question environment (completely analogous for the answer environment).

Regards
site moderator & package author
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Alignment over two lists

Post by svend_tveskaeg »

This is getting a bit embarrassing for me.

The following code will not compile, even though I think that I have inserted \setcounter at the beginning of the question and answer enviroments. :?

Code: Select all

\documentclass[danish]{article}
\usepackage{babel,enumitem}
\usepackage{lipsum}% for dummy text


\newlength\mylabelwidth
\setlength\mylabelwidth{6em}

\makeatletter
\newlength\my@labelindent
\setlength\my@labelindent{0pt}
\newcommand*\mylabelindent{\noindent\hspace*{\my@labelindent}}
\makeatother

\newcounter{question}
\newenvironment{questions}
\setcounter{question}{0}%
  {%
    \def\Item{%
      \stepcounter{question}%
      \par\mylabelindent
      \parbox{\mylabelwidth}{Q~(\arabic{question}):}}%
    \vskip0pt\relax\addvspace{\baselineskip}% skip before the env
  }%
  {\par\noindent\vskip0pt\relax\addvspace{\baselineskip}}% skip after the env

\newcounter{answer}
\newenvironment{answers}
\setcounter{answer}{0}%
  {%
    \def\Item{%
      \stepcounter{answer}%
      \par\mylabelindent
      \parbox{\mylabelwidth}{Answer~(\arabic{answer}):}}%
    \vskip0pt\relax\addvspace{\baselineskip}%
  }%
  {\par\noindent\vskip0pt\relax\addvspace{\baselineskip}}

\begin{document}

Wierd animal features:
\begin{questions}
  \Item Why is a horse not blue? \lipsum[4]
  \Item Why can a goat not fly?
\end{questions}
Explanations:
\begin{answers}
  \Item It would look stupid.
  \Item I actually have seen a flying goat.
\end{answers}

\end{document}
What is wrong?
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Alignment over two lists

Post by cgnieder »

You need to insert it after the opening brace of \newenvironment's second argument.
site moderator & package author
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: Alignment over two lists

Post by svend_tveskaeg »

Spot on. Thank you very much.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply