2

When using both hyperref and fleqn, I am getting some extra vertical space above numbered equations. This issue is I believe a known bug in hyperref and has already been discussed at

but I have not been able to successfully apply the workarounds given there to my specific problem, and that is what I could use some help with. Here's a MnWE:

\documentclass[fleqn]{report}
\usepackage{hyperref}
\usepackage{amsmath}

\newcommand{\question}[4]{
    \par \noindent \textbf{\ignorespaces#2}
    \nopagebreak[2]
    \vspace{10pt}
    \par \noindent \ignorespaces#3 \textit{\ignorespaces#4}
    \vspace{20pt}
}

\begin{document}

\question{default}{
  A question whose answer is an equation*.
}{
  \begin{equation*} \frac{x}{(1-x)^2} \end{equation*}
}{}

\question{default}{
  A question whose answer is an equation.
}{
  \begin{equation} \frac{x}{(1-x)^2} \end{equation}
}{}


\question{default}{
  A question whose answer is plain old text.
}{
  The answer.
}{}

\end{document}

MWE output

Some Background

I have a collection of notes in question-answer format. I like to review them by covering the (printed) notes with a sheet of paper and moving that paper down until I can see only the question. At this point I try to remember the answer, and I once I think I've got it, I move the sheet down further to reveal the answer.

Until recently the tex file containing this was something of a mess, so I decided to try writing the macro you see above. If my macro is completely wrong, let me know and I'll open a separate question on how to do that properly.

  • If you intend to always include some sort of display environment in #3, you can set \aboveskipayskip and \belowdisplayskip (temporarily) to the desired values. If not, you should set them to 0pt. – John Kormylo Jul 11 '16 at 13:10
2

You should never have a paragraph break before a displayed equation, TeX always does the wrong thing in such a situation. Here I removed the spurious par, also added some missing % I left in the \noindent although in almost all cases that shouldn't be used in latex,

enter image description here

\documentclass[fleqn]{report}
\usepackage{hyperref}
\usepackage{amsmath}

\newcommand{\question}[4]{%
    \par \noindent\nopagebreak[2]\textbf{\ignorespaces#2}%
    \ignorespaces#3 \textit{\ignorespaces#4}%
    \vspace{20pt}%
}

\begin{document}

\question{default}{
  My question
}{
  \begin{equation*} \frac{x}{(1-x)^2} \end{equation*}
}{}

\question{default}{
  My question
}{
  \begin{equation} \frac{x}{(1-x)^2} \end{equation}
}{}

\end{document}
  • Thank you. Unfortunately the third argument is sometimes an equation but usually not, and I want the third argument to always go on its own line. I'll go back and describe the bigger picture in my question. – user471651 Jul 11 '16 at 17:16
  • What is the purpose of the %'s? I know that double newlines will start a new paragraph, but I thought a single newline is basically the same as a space. – user471651 Jul 11 '16 at 17:41
  • @user471651 exactly and you don't want spaces there tex.stackexchange.com/questions/7453/… – David Carlisle Jul 12 '16 at 8:57

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.