Search code examples
rmarkdownright-to-left

Change text direction to become right-to-left in R Markdown


I have a fully functioning RMD template which generates nice reports in English.

(The RMD stands for R Markdown file. Basically its an interactive template r file, which can receive input from another r file many times. as any given input is passed, the template calculates some functions on the input and saves an HTML report corresponding to the outputs you specify.)

In addition, I need to make another version which look beautiful in Hebrew instead. simply replacing the text works fine. However, The main a issue with it is that the text is aligned Left-to-right (compatible with English) while I need to turn it to Right-to-left.

I am sure there is some simple way to do it, but I haven't found it.

Any help would be appreciated.


Solution

  • You can add css options to your Rmd template file. For example:

    ---
    title: חוכמה
    output: html_document
    ---
    <style>
    h1 {
      direction: rtl;
    }
    p {
      direction: rtl;
    }
    </style>
    
    הספר הוא ידידו הטוב של האדם
    

    Render this document with rmarkdown::render("Template.Rmd") for a result like this:

    enter image description here

    Option direction: rtl; specifies text direction right to left.

    p in :

    p {
      direction: rtl;
    }
    

    Specifies direction for text in "paragraphs".
    h1 in:

    h1 {
      direction: rtl;
    }
    

    Specifies direction for level 1 header (it's your title and header that starts with 1 #). For direction to work with all headers (eg, #, ##, ###) you should use:

    h1, h2, h3, h4, h5, h6 {
      direction: rtl;
    }