7

I tried to combine this answer: https://tex.stackexchange.com/a/73983/4011 with minipage but got an error: ERROR: LaTeX Error: Float(s) lost.

\documentclass{article}
\usepackage{showframe}% http://ctan.org/pkg/showframe
\newcommand{\points}[1]{% Print points in margin
  \leavevmode\marginpar{\makebox[\marginparwidth][r]{[#1]}}\ignorespaces}
\reversemarginpar% Points in left margin by default
\begin{document}
\begin{enumerate}
  \begin{minipage}[t]{0.5\linewidth}

  \item \points{5} This is what a simple open ended question, with no other parts could look like.
    \par\vfill
  \item This would be where you could put a question with two parts.
    \begin{enumerate}
    \item \points{2} This would be part~(a).
      \par\vfill
    \item \points{2} This would be part~(b).
      \par\vfill
    \end{enumerate}
  \item \points{10} This is what a multiple-choice question would look
    like.
    \par\vfill
  \end{minipage}
  \begin{minipage}[t]{0.5\linewidth}
    Some other text or a picture.
  \end{minipage}
\end{enumerate}
\end{document}

Without minipage it works.

Any idea, how to fix this?

2
  • I'm guessing that because a minipage doesn't have a margin, a \marginpar inside a minipage will not work. But what do I know? Commented Oct 23, 2014 at 17:02
  • 1
    \marginpar uses the \insert mechanism; an \insert does something only if it is at the outer level, not inside a box. You may want to look at the marginnote package.
    – egreg
    Commented Oct 23, 2014 at 17:20

1 Answer 1

5

This is similar to \marginpar and \begin{align}, but that question hides the main point.

Floats cannot be placed inside boxes, because they use the \insert primitive; the same holds for footnotes and marginpars. This is an inherent limitation of TeX.

The problem with floats is not really relevant: a float inside a minipage doesn't make any sense; for \footnotes one can remedy to some extent with \footnotemark and \footnotetext. For \marginpar there's no remedy, because the position should be remembered.

The marginnote package offers a workaround; change your definition into

\usepackage{marginnote}
\newcommand{\points}[1]{% Print points in margin
  \leavevmode\marginnote{\makebox[\marginparwidth][r]{[#1]}}\ignorespaces}

and you should be OK.

enter image description here

2
  • I can't seem to be able to break lines inside the argument of \points. Could you kindly suggest a workaround? E.g. I would like to have \points{XXX\\ YYY}.
    – Matsmath
    Commented Jul 1, 2017 at 17:38
  • 1
    @Matsmath Change \makebox[\marginparwidth][r]{[#1]} into \smash{\parbox[t]{\marginparwidth}{\raggedleft#1}} (but of course you need at least two lines in the exercise if you have a line break in the points)
    – egreg
    Commented Jul 1, 2017 at 17:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .