1

The following code defines a header with a logo, a course title, an quiz title, and boxes for the student to enter in their name, id and section.

I will comment out the image since it works and does not affect the answer. How does "quiz title" end up below the horizontal line?

\documentclass{article} \usepackage[margin=0.5in]{geometry} \usepackage{calc} \usepackage{amsmath} \usepackage{multirow} \usepackage{graphicx} \NewDocumentCommand{\ans}{O{} O{36}}{% \fbox{\makebox(#2 pt,18pt){}} } % Define the quiz environment \newenvironment{quiz}[2][]{% \begin{flushleft} \begin{tabular}{cccccc} \multirow{2}{*}{ %\includegraphics[width=40pt]{rulogo.png} } & & & \small{Name} & \small{NetID} & \small{Section} \\ & #1 & #2 & \ans[][162] & \ans[][50] & \ans \\ \end{tabular} \end{flushleft} \hrule }{% } \begin{document} \begin{quiz}{mycourse}{quiz title} \end{quiz} \end{document} 

The same thing happens if I just create a single line of output. I could understand if the line overflowed and the last item spilled onto the next line, but how does #2 jump out of the middle?

\begin{flushleft} \includegraphics[width=1cm]{logo.png} #1 #2 \ans[][144] \ans[][50] \ans \\ \end{flushleft} 
2
  • 2
    unrelated, but size commands do not take an argument, use \small Name not \small{Name} Commented May 13, 2024 at 14:32
  • why is \ans defined with an optional argument that is never used? Commented May 13, 2024 at 14:44

1 Answer 1

1

You use two mandatory arguments in \begin{quiz}{mycourse}{quiz title}. So you want to define it as \newenvironment{quiz}[2]{...} instead of \newenvironment{quiz}[2][]{...}. Otherwise latex will look for an optional argument and treat the second {...} as part of the environment body.

MWE:

\documentclass{article} \usepackage[margin=0.5in]{geometry} \usepackage{calc} \usepackage{amsmath} \usepackage{multirow} \usepackage{graphicx} \NewDocumentCommand{\ans}{O{} O{36}}{% \fbox{\makebox(#2 pt,18pt){}} } % Define the quiz environment \newenvironment{quiz}[2]{% \begin{flushleft} \begin{tabular}{cccccc} \multirow{2}{*}{ \includegraphics[width=40pt]{example-image-duck} } & & & \small Name & \small NetID & \small Section \\ & #1 & #2 & \ans[][162] & \ans[][50] & \ans \\ \end{tabular} \end{flushleft} \hrule }{% } \begin{document} \begin{quiz}{mycourse}{quiz title} \end{quiz} \end{document} 

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.