pandoc-latex-template icon indicating copy to clipboard operation
pandoc-latex-template copied to clipboard

I tried to add a logo to the left of the header, but failed

Open zhanenkui opened this issue 3 years ago • 6 comments

This is what I defined in the YAML block, maybe I'm wrong, does anyone know how to add a logo to the header?

---
title: "Document Template (English)"
logo: image/logo.png
author: AN
version: Ver1.2.0
date: 2020.12
header-left: image/test.jpg
---

zhanenkui avatar Dec 24 '20 08:12 zhanenkui

YAML is hipster cancer, so it can't do proper escapes of very uncommon symbols like [ and ]. You have to workaround this by a new command without those symbols.

header-right: "\\headerlogo"
header-includes:
- |
  ```{=latex}
  \newcommand{\headerlogo}{\includegraphics[width=1.5cm]{images/title-logo.png}}
  ```

rokk4 avatar Jan 19 '21 17:01 rokk4

You can look at my pull request #222 and try to modify it for your needs. You can also comment there and I try to include this option.

Fabioni avatar Jan 25 '21 21:01 Fabioni

Thank you for your reply to this question
Add a logo to the left of the header. I tried it and it worked.You need to make some adjustments to the image size

  \lhead[$if(header-right)$$header-right$$else$$title$$endif$]{$if(header-left)$$header-left$$else$\includegraphics{image/primarylg110.png}$endif$}
  \chead[$if(header-center)$$header-center$$else$$endif$]{$if(header-center)$$header-center$$else$$endif$}
  \rhead[$if(header-left)$$header-left$$else$\includegraphics{image/primarylg110.png}$endif$]{$if(header-right)$$header-right$$else$$title$$endif$}

zhanenkui avatar Jan 26 '21 02:01 zhanenkui

@rokk4 Thanks a lot. This works great. My first copy-and-paste somehow broke my yaml so I thought at first, it wouldn’t work but a second attempt lead to success. If you can spare the time, could you point me to a resource where I could read more about how you came up with this solution? I used this code to insert an image in the header-left while using a text in header-right. The text and the image where centered vertically but I rather wanted the text to align with the bottom of the image. Following the suggestion in https://texwelt.de/fragen/1375/wie-kann-ich-kopfzeilenfelder-vertikal-ausrichten I extended your command as follows:

\newcommand{\headerlogo}{\raisebox{0pt}[0pt]{\includegraphics[width=2.5cm]{media/image1.png}}}

screenshot

hmbgbw avatar Apr 08 '21 07:04 hmbgbw

@hmbgbw https://yaml.org/spec/history/2001-05-26.html Actually I just read the yml spec after the error and than thought of a way around it. lol :D

rokk4 avatar Apr 13 '21 19:04 rokk4

@rokk4 Thanks for responding. So, I dove into the yaml specs again and additionally read the pandoc user guide – which I thought I had done before but apparently not thorough enough. It will probably be of minor interest for anyone besides me but here are my insights: The command is a combination of YAML and Pandoc: The Pipe Sign starts a Literal Block Scalar( https://yaml.org/spec/1.2/spec.html#id2760844 https://yaml.org/spec/1.2/spec.html#id2793652) which contains a fenced code block (three backticks) following the syntax described in https://pandoc.org/MANUAL.html#extension-raw_attribute A very similar example can be found in https://pandoc.org/MANUAL.html#metadata-blocks Using the given information for raw code (pandoc) and escaping single lines (YAML, Single-Quoted Styles, https://yaml.org/spec/1.2/spec.html#id2788097) following code is an equivalent to rok44s code from above:

header-left: '\headerlogo'
header-includes:
- '`\newcommand{\headerlogo}{\raisebox{0pt}[0pt]{\includegraphics[width=1cm]{logo.png}}}`{=latex}'

Since using single quotes, the backslash in the first line doesn’t have to be escaped. The LaTeX command is written as a raw LaTeX inline element (https://pandoc.org/MANUAL.html#extension-raw_attribute) and therefore included in single backticks. The whole command (including the {=latex}) has to be in single quotes due to YAML specs.

hmbgbw avatar Apr 14 '21 20:04 hmbgbw