In latex when I force a newline in a caption with \\ it gives an error saying \Hy@tempa has an extra } runaway argument?
In latex when I force a newline in a caption with \\ it gives an error saying \Hy@tempa has an extra } runaway argument?
The error occurs because the `\\` command is fragile in moving arguments like captions, especially when using the `hyperref` package. Here's how to fix it: **Solution:** Use `\protect\\` to safely insert a line break in the caption. **Example:**
1 2 3 4 5 6 7 | \documentclass{article} \usepackage{hyperref} % For hyperlinks \begin{document} \begin{figure} \caption{First line \protect\\ Second line} \end{figure} \end{document} |
1 | \caption{Line 1 \protect\\ Line 2 \protect\\ Line 3} |
Testing if the previous output contains the string \protect
: True