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}

Sverre
  • 20,729
  • 1
    You can substitute \\ by \hfil\break. This will probably break other parts of the document (running heads, maybe). – Koji Oct 03 '13 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: http://tex.stackexchange.com/q/132062/27635). Can't you anyway issue \raggedright after \maketitle? – karlkoeller Oct 03 '13 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 03 '13 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). – karlkoeller Oct 03 '13 at 20:19

2 Answers2

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.

David Carlisle
  • 757,742
  • 2
    I have no idea how to interpret "Use of fragile command in a moving argument", but \protect does indeed work. – Sverre Oct 17 '13 at 12:46
  • @Sverre you interpret it as "you need \protect :-) see any of http://tex.stackexchange.com/search?q=fragile+protect+user%3A1090 – David Carlisle Oct 17 '13 at 13:01
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.

mbercx
  • 1