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 you're encountering is due to the fact that LaTeX's `\caption` command is not designed to handle line breaks (`\\`) directly. When you use `\\` in a caption, it can cause issues with the hyperref package, which is often used for creating hyperlinks in documents. To resolve this issue, you can use the `\protect` command before the `\\` to prevent it from being interpreted incorrectly. Here’s how you can do it:
1 | \caption{This is the first line of the caption.\protect\\ This is the second line.} |
1 | \caption{This is the first line of the caption.\newline This is the second line.} |
1 | \captionof{figure}{This is the first line of the caption.\\ This is the second line.} |
Testing if the previous output contains the string \protect
: True