Import LateX for R Markdown

4

Hello! Probably this question was already covered here but I did not find it ... Well I use Markdonw R to generate manuals on certain R commands, but I did a diagram in LateX and wanted to know if there is any way to import the same for R Markdown. Thanks!

I would like to insert this.

% arara: pdflatex

\documentclass[10pt,a4paper]{article} 
\usepackage[utf8]{inputenc}
\usepackage[hmargin=2cm,vmargin=1cm]{geometry}
\renewcommand{\rmdefault}{bch} % change default font
\usepackage{tikz} 
\usetikzlibrary{positioning}

\begin{document}    
    \begin{figure}[h]       
        \centering
        \begin{tikzpicture}
        [% style definitions
        ,every node/.style={node distance=3, font=\footnotesize}
        ,comment/.style={font=\scriptsize\sffamily}
        ,force/.style={rectangle, draw, fill=black!10, inner sep=5pt, text width=3cm, text badly centered, minimum height=1.2cm, font=\bfseries\footnotesize\sffamily}
        ,on grid
        ] 
        % Draw forces
        \node [force] (z) {Dados Arvore};
        \node [force, above = of z] (y) {Dados Originais};
        \node [force, right = 5 of z] (x) {Secção};
        \node [force, below = of z] (v) {Dados Arvore II};
        \node [force, right = 5 of v] (b) {Cubagem};
        \node [force, below = 4 of v] (w) {Arquivo Final};
        \node [force, below left = 2 and 2.5 of v] (c) {Modelos de Relaçao Hisométrica};
        \node [force, below right = 2 and 2.5 of v] (e) {Modelos de Volume};        
        % Draw the links between forces
        \path[->,thick,every node/.append style={comment,anchor=base, fill=white}] 
        (y) edge node {Avaliação} (z) edge node {Avaliação} (x)
        (z) edge node {Inconsistências e Manipulação} (v)
        (v) edge (w) edge node {Ajuste} (c) edge node {Ajuste} (e)
        (c) edge node {Predição} (w)
        (e) edge node {Predição} (w)
        (x) edge node {Inconsistências e Manipulação} (b)
        (b) edge node {Manipulação} (e);        
        \end{tikzpicture} 
        \caption[Diagrama do Script de ajuste de relação hipsométrica]{Diagrama do Script de ajuste de relação hipsométrica, volume cubado e equações de volumetria da empresa FLORESTECA.}
        \label{fig:6forces}
    \end{figure}    
\end{document}
    
asked by anonymous 27.04.2015 / 07:24

1 answer

2

I assume you're using pandoc doc.rmd -o doc.pdf or similar.

The Rmarkdown file needs a metadata block (I suggest it placed at the beginning of the document, in which case I'll use YAML ) where you include the headear of LateX/tikz

---
title: "Manual de ...."
date: \today
header-includes:
    - \renewcommand{\rmdefault}{bch}
    - \usepackage{tikz}
    - \usetikzlibrary{positioning}
---

Diagrama em TiKZ
================

\begin{figure}[h]
        \centering
        \begin{tikzpicture}
        [% style definitions
        ,every node/.style={node distance=3, font=\footnotesize}
        ,comment/.style={font=\scriptsize\sffamily}
        ....
        ....
\end{figure}

Is this what you needed? (Cut what does not matter)

This works fine for building pdf, and some other formats. For others cases (Ex. HTML) it takes more work - See also pandocfilters .

    
28.04.2015 / 10:25