3

(This is, in a sense, a follow-up to Insert text between title and author).

When using \raggedright in the preamble, LaTeX throws an error when I use a linebreak command \\ in \maketitle. How can I circumvent this?

\documentclass{article}
\raggedright % turn off right-edge text justification and hyphenation
\usepackage{titling}
    \pretitle{\begin{flushleft}\LARGE\textbf} % left aligned title with LARGE bold type
    \posttitle{\vskip .25ex\hrule\par\end{flushleft}} % add hrule under title
    \preauthor{\begin{flushleft}\large} % left align author
    \postauthor{\par\end{flushleft}}
    \predate{\begin{flushleft}} % left align date
    \postdate{\par\end{flushleft}\vspace{-3ex}} % reduce space after \maketitle

\begin{document}
\title{Review}
\author{\textbf{Paul McCartney}\\ University of Liverpool}
\date{\today}
\maketitle
\noindent Here my review begins
\end{document}

! Argument of \reserved@a has an extra }.

\par

l.14 ...Paul McCartney}\ University of Liverpool}

4
  • 1
    You can substitute \\ by \hfil\break. This will probably break other parts of the document (running heads, maybe).
    – Koji
    Oct 3, 2013 at 18:46
  • I can't figure what is the exact cause in this case, but never use commands like \raggedright in the preamble (see this thread: tex.stackexchange.com/q/132062/27635). Can't you anyway issue \raggedright after \maketitle? Oct 3, 2013 at 19:49
  • @karlkoeller I'm puzzled by the principle "NEVER use any command related to typesetting text in the preamble." I would like to hear more about that.
    – Sverre
    Oct 3, 2013 at 20:10
  • @Sverre I can't remember now where I read something about it, but (probably I'm wrong) I can remember to have read that it is a good practice (at least one should issue such commands after having loaded all packages, although in your case it seems to be not enough). Oct 3, 2013 at 20:19

2 Answers 2

7

Usually (not always, but here)

! Argument of \reserved@a has an extra }. 

should be read as Use of fragile command in a moving argument.

So

\author{\textbf{Paul McCartney}\protect\\ University of Liverpool}

Works as intended without error.

2
0

I encountered the same error while using the titling package in combination with the tabular environment:

\documentclass[]{article}

\usepackage[margin=0.9in]{geometry}
\usepackage{titling} 
\usepackage{graphicx}
\usepackage{lipsum}

\pretitle{\vspace{-35pt}\begin{flushleft}}

\title{
\begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}r}
\Huge{Title} & \includegraphics[width = 0.2\textwidth]{example-image}
\end{tabular*}
}

\posttitle{\end{flushleft}\hrule\vspace{-50pt}}
\date{}

\begin{document}

\maketitle
\lipsum[1-2]

\end{document}

When I ignored this error and simply pressed enter a few times, I did get the pdf output, but it bothered me that I get this error every time I compile the document. I tried adding \protect at various locations in the code, but that did not help. I did find a solution in the titling package documentation, that uses \DeclareRobustCommand:

\documentclass[]{article}

\usepackage[margin=0.9in]{geometry}
\usepackage{titling} 
\usepackage{graphicx}
\usepackage{lipsum}

\pretitle{\vspace{-35pt}\begin{flushleft}}

\DeclareRobustCommand{\desiredTitle}{
\begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}r}
\Huge{Title} & \includegraphics[width = 0.2\textwidth]{example-image}
\end{tabular*}
}

\title{\desiredTitle}

\posttitle{\end{flushleft}\hrule\vspace{-50pt}}
\date{}

\begin{document}

\maketitle
\lipsum[1-2]

\end{document}

I was asking a question about the problem when I found this solution. I figured I'd place my findings here in case anyone else encounters this error in a similar situation.

You must log in to answer this question.

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