I want to place a logo in the header of the first page of an article(documentclass: scrartcl
), but I want the header to change from the second page onward. I have tried the following solution:
---
title: "Logo in Header"
format:
pdf:
include-in-header:
text: |
\usepackage{scrlayer-scrpage}
\clearpairofpagestyles
\cohead[\includegraphics[width=5cm]{my_logo.png}]{Header from page 2 onward}
---
Page 1
\newpage
Page 2
Unfortunately, I am receiving the following error message:
compilation failed- error
LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.80 ...cludegraphics[width=5cm]{visana_logo.png}]
{Header from page 2 onward}
When I replace the image with text, it works:
---
title: "Logo in Header"
format:
pdf:
include-in-header:
text: |
\usepackage{scrlayer-scrpage}
\clearpairofpagestyles
\cohead[Header page 1]{Header from page 2 onward}
---
Page 1
\newpage
Page 2
It also works when I remove the width argument for the image:
---
title: "Logo in Header"
format:
pdf:
include-in-header:
text: |
\usepackage{scrlayer-scrpage}
\clearpairofpagestyles
\cohead[\includegraphics{my_logo.png}]{Header from page 2 onward}
---
Page 1
\newpage
Page 2
You are getting errors because the closing square bracket ]
from width[..]
is being parsed as optional argument terminator for \cohead
.
So,
\includegraphics[width=5cm
is being passed as the optional argument to \cohead
. So to avoid this, enclose the whole optional argument content within a curly braces. See this excellent Q/A thread from TexStackExchange for details.
Therefore, just put the includegraphics[width=5cm]{test.png}
within a extra pair of curly braces {}
and it will work!
---
title: "Logo in Header"
format:
pdf:
include-in-header:
text: |
\usepackage{scrlayer-scrpage}
\clearpairofpagestyles
\cohead[{\includegraphics[width=5cm]{test.png}}]{Header from page 2 onward}
---
Page 1
\newpage
Page 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With