Open michielvandijk opened 2 years ago
you are right, that approach does not work here.
The layout of the letter is defined in a letter class option file (lco). The default lco is just a layout that I like. You could use one of the standard layouts of the underlying latex class scrlttr2
(cf. vignette letter_example_2 web version). Some of those lco's are listed in vignette 'introduction to komaletter' web. Or define your own lco for instance based on the packages' default lco see vignette letter_example_1 web. You wouldn't need to do the 'system.file()'-thing just put your lco in the same directory and merely specify the filename of the lco.
Having said the above, I gotta say I'm still undecided on adding an option to replace the author name with an image file/logo in the upper right hand corner.
A few remarks and corrections:
You can pass LaTeX code to be included in the document header (as well as before or after its body) via the specified Rmd output format's includes
argument. komaletter::komaletter()
passes this on to the underlying rmarkdown::pdf_document()
. This has the same effect as specifying the header-includes
variable for the Pandoc template.
Example YAML header:
---
output:
komaletter::komaletter:
includes:
in_header: header.tex
---
You should use the LaTeX command \input
instead of \include
to source your header.tex
file.
The LaTeX package textpos
appears to be a good choice to place the logo image, especially in its absolute positioning mode and using a textblock with absolute sizes. See the manual for all the details.
To load textpos
in absolute mode, include the following line in your header.tex
:
\usepackage[absolute]{textpos}
To create a textblock with absolute sizes (using the starred textblock environment variant), LaTeX code similar to the following one has to be included in the (Rmd) document body:
\begin{textblock*}{5cm}(12cm,1cm)
\includegraphics[width=5cm]{logo.png}
\end{textblock*}
The first argument in curly braces ({5cm}
) defines the width of the textblock (its height automatically adapts to its content, so does not have to be explicitly specified). The second argument in parentheses ((12cm, 1cm)
) defines the horizontal and vertical offset from the reference point (the top left corner of the page in absolute positioning mode).
Note that you also need to either specify graphics: true
in the YAML header or add the line \usepackage{graphicx}
to header.tex
in order for the LaTeX package graphicx
to be loaded.
Hope that helps.
Hi @salim-b
thank you for your input. I am not quite sure which part of your writing addresses me. Are you suggesting any changes in the package?
As you write, the inclusion of additional Tex is possible via the YAML tags provided by rmarkdown, on top of which komaletter is built. The inclusion of header-includes in the komaletter template is identical to pandoc's default-latex template. Does this part need to be changed?
Hi @rnuske
I am not quite sure which part of your writing addresses me.
I wasn't really addressing you but rather the OP and future readers of this issue in general (while I was looking for a solution to include a logo in a letter created with komaletter I stumpled upon this issue and thought it would be nice to share my findings).
The inclusion of header-includes in the komaletter template is identical to pandoc's default-latex template. Does this part need to be changed?
You're right. I somehow assumed komaletter's template would ignore the header-includes
variable since one of my early experiments relying on it failed. But it's clearly there (and works). I've update my post above accordingly. Sorry for the confusion.
Are you suggesting any changes in the package?
Not really. I think the KOMA-Script LaTeX letter class scrlttr2
already contains configuration variables in excess. Adding even more config options (for logo inclusion or whatever) beyond what scrlttr2
supports seems overkill to me.
One thing though that bothers me about komaletter's template is that the LaTeX package graphicx
is only loaded when one of the template variables graphics
or signature
is set:
This means that a simple \includegraphics{}
call will by default produce an error message during build. This is consistent with Pandoc's default template. But while Pandoc targets a wide range of input/output formats, komaletter is intended to be used for LaTeX/PDF output only. So maybe we could change the template to load graphicx
unconditionally?
Furthermore, in an ideal world, komaletter's documentation would be extended to include
scrlttr2
supports together with their official description and default value.Anyways, thanks a lot for developing and maintaining this package!
I would like to add the university logo to the top of the letter so it more-or-less replicates the standard template. I followed the approach as described here:
https://stackoverflow.com/questions/27982052/insert-a-logo-in-upper-right-corner-of-r-markdown-pdf-document
And added this in the yaml: header-includes:
plus a header.tex with the following information in the same folder
\usepackage{fancyhdr} \pagestyle{fancy} \rhead{\includegraphics[width = .05\textwidth]{logo.png}}
Nothing, however, seems to happen. I suppose the header-includes is not supported (yet) by the package. Not sure if this is easy to implement but this seems to be a general feature that users would like to use.