# Remove unwanted vertical space before and after environment in footnote

I am trying to make my own environment for (left-)indented blocks inside hanging footnotes, in which the normal quote environment doesn't work, it's left indent being the same as that of the indent of the footnote, so that one doesn't see it. I am now trying to do to this with the adjustwidth environment, which does the indentation as I want it, but it inserts horizontal spaces before and after the environment if there's nothing before or after it in the footnote, a behaviour which the quote environment also seems to have.

I tried to adapt the solution suggested here, but the \compress didn't seem to do anything, and the negative \vspace after the environment would pull the next line, if there was one, into last line of the environment.

\documentclass{memoir}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\setlength{\footmarkwidth}{\leftmargin}
\setlength{\footmarksep}{0em}
\footmarkstyle{#1\hfill}
\begin{document}
Some text\footnote{Enough text to be two lines in the footnote. Enough text to be two lines in the footnote. Enough text to be two lines in the footnote.
And here we have a quote inside the footnote. With some text before or after it it looks fine, but ...
Some text after the quote.
}
\footnote{
If I have a footnote starting or ending with a quotation I get an empty line, before or after, which I don't want.
}
\footnote{
\begin{fnquote}
If I have a footnote starting or ending with a quotation I get an empty line, before or after, which I don't want.
\end{fnquote}
And some more text here.
}
\footnote{Just another footnote.}
\end{document}


Is there maybe another switch I could use to trick the environment into thinking there was some text before and after it in the footnote?

• My question is: wouldn't it be better to typeset the quotation in a different font rather than with narrower text width in the footnote? Without any text before it, the quote would look strange even if the empty line problem gets fixed. – egreg Apr 7 '15 at 21:52
• Before and after the footnote text, LaTeX inserts a strut, that's used for making the distance between consecutive footnotes right. The fnquote environment (or adjustwidth) starts and ends with \par, so the two struts get eventually in lines by themselves. – egreg Apr 7 '15 at 22:01

I'm not sure this is really what you want: the result is just wrong, nobody will understand why the text in the second and third footnote is shifted right.

\documentclass{memoir}

\setlength{\footmarkwidth}{\leftmargin}
\setlength{\footmarksep}{0em}
\footmarkstyle{#1\hfill}

\newenvironment{fnquote}
{\par
\setbox0=\lastbox \setbox2=\hbox{\unhcopy0}%
\ifdim\wd2>\leftmargin \nointerlineskip\else\prevdepth=\dp\strutbox\fi\box0
\vspace{-2.83337pt plus -1.41669pt minus -0.94446pt}%
\ifdim\wd2>\leftmargin \else\vspace{-\baselineskip}\fi
{\end{adjustwidth}\vspace{-2.83337pt plus -1.41669pt minus -0.94446pt}}
\newenvironment{fnquote*}
{\fnquote}{\endfnquote\vspace{-\baselineskip}}

\begin{document}
Some text\footnote{%
Enough text to be two lines in the footnote. Enough text to be two
lines in the footnote. Enough text to be two lines in the footnote.
\begin{fnquote}
And here we have a quote inside the footnote. With some text before or after
it it looks fine, but ...
\end{fnquote}
Some text after the quote.}
\footnote{%
\begin{fnquote*}
If I have a footnote starting or ending with a quotation I get an empty line,
before or after, which I don't want.
\end{fnquote*}
}
\footnote{%
\begin{fnquote}
If I have a footnote starting or ending with a quotation I get an empty line,
before or after, which I don't want.
\end{fnquote}
And some more text here.
}
\footnote{Just another footnote.}
\end{document}


The problem is that any footnote has two implicit struts at the beginning and end; when fnquote appears at the beginning, it does a \par and so the strut forms a paragraph by itself. Similarly, if no text follows fnquote, the final strut makes a paragraph by itself.

I measure the last typeset line and if it is longer than \leftmargin, it means it has text; otherwise I back up what's necessary.

For quotes ending the footnote, it's necessary to use a different environment fnquote* that backs up by a baselineskip.

• Interesting to see the use of \lastbox. I agree with your comment about reader confusion regarding the indentation. Nevertheless, is there a handy way to clean up the interline spacing between footnote 2 and 3? It looks a bit tight. And perhaps the same can be said about the end of the quote in footnote 3 and its following text. – A.Ellett Apr 7 '15 at 22:58
• @A.Ellett It's not meant to be a full solution (there are some strange effects indeed. Fixed now. – egreg Apr 7 '15 at 22:59
• I only asked because I'd been playing with this for a bit. Never would have come up with your solution (not entirely sure I'd ever have thought about shifting around the boxes at the beginning). I'd been thinking of doing a \par\xdef\tpd{\the\prevdepth} sort of thing, but didn't see how to apply it to what you'd done. – A.Ellett Apr 7 '15 at 23:19
• @A.Ellett I didn't try with \footnote{\begin{fnquote}...\end{fnquote} as the first on a page. But it seems to work well. ;-) – egreg Apr 7 '15 at 23:23