2

I have been trying to get the author of a quote to show in a different font size and font style than the rest of the quotation.

MWE:

\documentclass[11pt]{memoir} % draft

\renewcommand*{\sourceatright}[2][2em]{{%
  \unskip\nobreak\hfil\penalty50
  \hskip#1\hbox{}\nobreak\hfil\tiny\sffamily{#2}
  \parfillskip\z@\finalhyphendemerits=0\par}}

\begin{document}
\begin{quotation}
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ante sapien, feugiat sed elit id, tempus dictum erat. Maecenas bibendum eget lectus eu mollis.\sourceatright{Lipsum 2016}
\end{quotation}

\end{document}

From what I can tell it doesn't like the placing of \tiny\sffamily but I just can't work out how to do it.

The error I get is this:

 ! Undefined control sequence.
 \\sourceatright ...\sffamily {#2} \parfillskip \z
                                                  @\finalhyphendemerits =0\p...
 l.11 ...ctus eu mollis.\sourceatright{Lipsum 2016}

Any help is appreciated.

4

You need \makeatletter and \makeatother, see What do \makeatletter and \makeatother do?. But also another adjustment.

\documentclass[11pt]{memoir} % draft

\makeatletter
\renewcommand*{\sourceatright}[2][2em]{{%
  \unskip\nobreak\hfil\penalty50
  \hskip#1\hbox{}\nobreak\hfil{\tiny\sffamily#2}%
  \parfillskip\z@\finalhyphendemerits=\z@\par}}
\makeatother

\begin{document}

\begin{quotation}
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aliquam ante sapien, feugiat sed elit id, tempus dictum erat.
Maecenas bibendum eget lectus eu mollis.\sourceatright{Lipsum 2016}
\end{quotation}

\end{document}

The difference is that \tiny\sffamily{#2} should be {\tiny\sffamily#2}, otherwise \tiny would be in force when the paragraph is split into lines, with nefarious consequences.

enter image description here

Shorter code with xpatch.

\documentclass[11pt]{memoir} % draft

\usepackage{xpatch}

\xpatchcmd{\sourceatright}{#2}{\tiny\sffamily#2}{}{}

\begin{document}

\begin{quotation}
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aliquam ante sapien, feugiat sed elit id, tempus dictum erat.
Maecenas bibendum eget lectus eu mollis.\sourceatright{Lipsum 2016}
\end{quotation}

\end{document}

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.