kableExtra functions in R return latex errors when compiling rmarkdown file to PDF document in Rstudio











up vote
0
down vote

favorite












I'm trying to knit a rmarkdown file to PDF file which contains kableExtra functions like:




  • kable_styling

  • column_spec

  • add_header_above


However I am always getting the following error:



! Extra alignment tab has been changed to cr.
<template> endtemplate

l.184 end{tabular}}


pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43
Ejecución interrumpida


One easy example that I am executing is:



```
---
output:
pdf_document:
keep_tex: yes
classoption: table
header-includes:
- usepackage{array}
- usepackage{float}
- usepackage{xcolor}
---

```{r results='asis'}
options(kableExtra.latex.load_packages = FALSE)
require(kableExtra)
print(kable(head(cars),"latex")%>%kable_styling(latex_options = c("striped",
"bordered"))
%>%column_spec(column=1:2,width = "0.5in") %>%
kable_styling(c("striped", "bordered"),latex_options =
"scale_down")%>% add_header_above(c(" "=7,
"Absolute"=1,"Relative"=1,"Absolute"=1,"Relative"=1,
"Absolute"=1,"Relative"=1,"Absolute"=1,"Relative"=1,"Absolute"=1,
"Relative"=1))%>%
add_header_above(c(" "= 1,"Non-weighted"=1,"Weighted"=1,"Non-
weighted"=1,"Weighted"=1,"Non-weighted"=1,
"Weighted"=1,"Weighted"=2,"Non-weighted"=2,"Weighted"=2,"Non-
weighted"=2,"Weighted"=2))%>%
add_header_above(c("Theoretical Values"= 1,"First-Order Predicted
Value"=2,"Second-Order Predicted Value"=2,
"Third-Order Predicted Value"=2,
"Non-linearity 1st Order"=2,"Non-linearity 2nd Order"=4,"Non-linearity 3rd
Order"=4)))


```



Can anyone help me with this issue?



I would appreciate whatever clue!










share|improve this question




























    up vote
    0
    down vote

    favorite












    I'm trying to knit a rmarkdown file to PDF file which contains kableExtra functions like:




    • kable_styling

    • column_spec

    • add_header_above


    However I am always getting the following error:



    ! Extra alignment tab has been changed to cr.
    <template> endtemplate

    l.184 end{tabular}}


    pandoc.exe: Error producing PDF
    Error: pandoc document conversion failed with error 43
    Ejecución interrumpida


    One easy example that I am executing is:



    ```
    ---
    output:
    pdf_document:
    keep_tex: yes
    classoption: table
    header-includes:
    - usepackage{array}
    - usepackage{float}
    - usepackage{xcolor}
    ---

    ```{r results='asis'}
    options(kableExtra.latex.load_packages = FALSE)
    require(kableExtra)
    print(kable(head(cars),"latex")%>%kable_styling(latex_options = c("striped",
    "bordered"))
    %>%column_spec(column=1:2,width = "0.5in") %>%
    kable_styling(c("striped", "bordered"),latex_options =
    "scale_down")%>% add_header_above(c(" "=7,
    "Absolute"=1,"Relative"=1,"Absolute"=1,"Relative"=1,
    "Absolute"=1,"Relative"=1,"Absolute"=1,"Relative"=1,"Absolute"=1,
    "Relative"=1))%>%
    add_header_above(c(" "= 1,"Non-weighted"=1,"Weighted"=1,"Non-
    weighted"=1,"Weighted"=1,"Non-weighted"=1,
    "Weighted"=1,"Weighted"=2,"Non-weighted"=2,"Weighted"=2,"Non-
    weighted"=2,"Weighted"=2))%>%
    add_header_above(c("Theoretical Values"= 1,"First-Order Predicted
    Value"=2,"Second-Order Predicted Value"=2,
    "Third-Order Predicted Value"=2,
    "Non-linearity 1st Order"=2,"Non-linearity 2nd Order"=4,"Non-linearity 3rd
    Order"=4)))


    ```



    Can anyone help me with this issue?



    I would appreciate whatever clue!










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm trying to knit a rmarkdown file to PDF file which contains kableExtra functions like:




      • kable_styling

      • column_spec

      • add_header_above


      However I am always getting the following error:



      ! Extra alignment tab has been changed to cr.
      <template> endtemplate

      l.184 end{tabular}}


      pandoc.exe: Error producing PDF
      Error: pandoc document conversion failed with error 43
      Ejecución interrumpida


      One easy example that I am executing is:



      ```
      ---
      output:
      pdf_document:
      keep_tex: yes
      classoption: table
      header-includes:
      - usepackage{array}
      - usepackage{float}
      - usepackage{xcolor}
      ---

      ```{r results='asis'}
      options(kableExtra.latex.load_packages = FALSE)
      require(kableExtra)
      print(kable(head(cars),"latex")%>%kable_styling(latex_options = c("striped",
      "bordered"))
      %>%column_spec(column=1:2,width = "0.5in") %>%
      kable_styling(c("striped", "bordered"),latex_options =
      "scale_down")%>% add_header_above(c(" "=7,
      "Absolute"=1,"Relative"=1,"Absolute"=1,"Relative"=1,
      "Absolute"=1,"Relative"=1,"Absolute"=1,"Relative"=1,"Absolute"=1,
      "Relative"=1))%>%
      add_header_above(c(" "= 1,"Non-weighted"=1,"Weighted"=1,"Non-
      weighted"=1,"Weighted"=1,"Non-weighted"=1,
      "Weighted"=1,"Weighted"=2,"Non-weighted"=2,"Weighted"=2,"Non-
      weighted"=2,"Weighted"=2))%>%
      add_header_above(c("Theoretical Values"= 1,"First-Order Predicted
      Value"=2,"Second-Order Predicted Value"=2,
      "Third-Order Predicted Value"=2,
      "Non-linearity 1st Order"=2,"Non-linearity 2nd Order"=4,"Non-linearity 3rd
      Order"=4)))


      ```



      Can anyone help me with this issue?



      I would appreciate whatever clue!










      share|improve this question















      I'm trying to knit a rmarkdown file to PDF file which contains kableExtra functions like:




      • kable_styling

      • column_spec

      • add_header_above


      However I am always getting the following error:



      ! Extra alignment tab has been changed to cr.
      <template> endtemplate

      l.184 end{tabular}}


      pandoc.exe: Error producing PDF
      Error: pandoc document conversion failed with error 43
      Ejecución interrumpida


      One easy example that I am executing is:



      ```
      ---
      output:
      pdf_document:
      keep_tex: yes
      classoption: table
      header-includes:
      - usepackage{array}
      - usepackage{float}
      - usepackage{xcolor}
      ---

      ```{r results='asis'}
      options(kableExtra.latex.load_packages = FALSE)
      require(kableExtra)
      print(kable(head(cars),"latex")%>%kable_styling(latex_options = c("striped",
      "bordered"))
      %>%column_spec(column=1:2,width = "0.5in") %>%
      kable_styling(c("striped", "bordered"),latex_options =
      "scale_down")%>% add_header_above(c(" "=7,
      "Absolute"=1,"Relative"=1,"Absolute"=1,"Relative"=1,
      "Absolute"=1,"Relative"=1,"Absolute"=1,"Relative"=1,"Absolute"=1,
      "Relative"=1))%>%
      add_header_above(c(" "= 1,"Non-weighted"=1,"Weighted"=1,"Non-
      weighted"=1,"Weighted"=1,"Non-weighted"=1,
      "Weighted"=1,"Weighted"=2,"Non-weighted"=2,"Weighted"=2,"Non-
      weighted"=2,"Weighted"=2))%>%
      add_header_above(c("Theoretical Values"= 1,"First-Order Predicted
      Value"=2,"Second-Order Predicted Value"=2,
      "Third-Order Predicted Value"=2,
      "Non-linearity 1st Order"=2,"Non-linearity 2nd Order"=4,"Non-linearity 3rd
      Order"=4)))


      ```



      Can anyone help me with this issue?



      I would appreciate whatever clue!







      r r-markdown kableextra






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 at 10:37

























      asked Nov 22 at 15:46









      Laura Santulario Verdú

      13




      13
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          You are telling kableExtra not to load the LaTeX packages (why?), so you have to do this yourself. The features you are using require array, float and xcolor with the table option. One difficulty is that fancyvrb v3.0 already loads xcolor with other options. You can circumvent this by supplying table as a class option:



          ---
          output:
          pdf_document:
          keep_tex: yes
          classoption: table
          header-includes:
          - usepackage{array}
          - usepackage{float}
          ---


          ```{r results='asis'}
          options(kableExtra.latex.load_packages = FALSE)
          require(kableExtra)
          print(kable(head(cars),"latex") %>%column_spec(column=1:2,width = "0.5in"))
          ```

          ```{r results='asis'}
          print(kable(head(cars),"latex")%>%kable_styling(latex_options = c("striped", "bordered")))
          ```





          share|improve this answer























          • @LauraSantularioVerdú Please edit your question to include such information.
            – Ralf Stubner
            Nov 23 at 6:53










          • Thank you very much for your help. It is true that I 'd forgotten the YALM so I 've added now. The thing is that it is that now it works for function column_spec() but not for kable_styling(). I write you the code I have problems with: --- output: pdf_document header-includes: - usepackage{array} --- {r results='asis'} options(kableExtra.latex.load_packages = FALSE) require(kableExtra) print(kable(cars,"latex")%>%kable_styling(latex_options = c("striped", "bordered")))
            – Laura Santulario Verdú
            Nov 23 at 8:56










          • What error(s) do you get? Please add code to your question, since it is unreadable in a comment. Also please build a Minimal, Complete, and Verifiable example instead of including code and the full YAML header separately.
            – Ralf Stubner
            Nov 23 at 9:27










          • Sorry, I have updated right now
            – Laura Santulario Verdú
            Nov 23 at 10:04










          • @LauraSantularioVerdú Thanks, please see my updated answer.
            – Ralf Stubner
            Nov 23 at 10:06











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434402%2fkableextra-functions-in-r-return-latex-errors-when-compiling-rmarkdown-file-to-p%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          You are telling kableExtra not to load the LaTeX packages (why?), so you have to do this yourself. The features you are using require array, float and xcolor with the table option. One difficulty is that fancyvrb v3.0 already loads xcolor with other options. You can circumvent this by supplying table as a class option:



          ---
          output:
          pdf_document:
          keep_tex: yes
          classoption: table
          header-includes:
          - usepackage{array}
          - usepackage{float}
          ---


          ```{r results='asis'}
          options(kableExtra.latex.load_packages = FALSE)
          require(kableExtra)
          print(kable(head(cars),"latex") %>%column_spec(column=1:2,width = "0.5in"))
          ```

          ```{r results='asis'}
          print(kable(head(cars),"latex")%>%kable_styling(latex_options = c("striped", "bordered")))
          ```





          share|improve this answer























          • @LauraSantularioVerdú Please edit your question to include such information.
            – Ralf Stubner
            Nov 23 at 6:53










          • Thank you very much for your help. It is true that I 'd forgotten the YALM so I 've added now. The thing is that it is that now it works for function column_spec() but not for kable_styling(). I write you the code I have problems with: --- output: pdf_document header-includes: - usepackage{array} --- {r results='asis'} options(kableExtra.latex.load_packages = FALSE) require(kableExtra) print(kable(cars,"latex")%>%kable_styling(latex_options = c("striped", "bordered")))
            – Laura Santulario Verdú
            Nov 23 at 8:56










          • What error(s) do you get? Please add code to your question, since it is unreadable in a comment. Also please build a Minimal, Complete, and Verifiable example instead of including code and the full YAML header separately.
            – Ralf Stubner
            Nov 23 at 9:27










          • Sorry, I have updated right now
            – Laura Santulario Verdú
            Nov 23 at 10:04










          • @LauraSantularioVerdú Thanks, please see my updated answer.
            – Ralf Stubner
            Nov 23 at 10:06















          up vote
          1
          down vote













          You are telling kableExtra not to load the LaTeX packages (why?), so you have to do this yourself. The features you are using require array, float and xcolor with the table option. One difficulty is that fancyvrb v3.0 already loads xcolor with other options. You can circumvent this by supplying table as a class option:



          ---
          output:
          pdf_document:
          keep_tex: yes
          classoption: table
          header-includes:
          - usepackage{array}
          - usepackage{float}
          ---


          ```{r results='asis'}
          options(kableExtra.latex.load_packages = FALSE)
          require(kableExtra)
          print(kable(head(cars),"latex") %>%column_spec(column=1:2,width = "0.5in"))
          ```

          ```{r results='asis'}
          print(kable(head(cars),"latex")%>%kable_styling(latex_options = c("striped", "bordered")))
          ```





          share|improve this answer























          • @LauraSantularioVerdú Please edit your question to include such information.
            – Ralf Stubner
            Nov 23 at 6:53










          • Thank you very much for your help. It is true that I 'd forgotten the YALM so I 've added now. The thing is that it is that now it works for function column_spec() but not for kable_styling(). I write you the code I have problems with: --- output: pdf_document header-includes: - usepackage{array} --- {r results='asis'} options(kableExtra.latex.load_packages = FALSE) require(kableExtra) print(kable(cars,"latex")%>%kable_styling(latex_options = c("striped", "bordered")))
            – Laura Santulario Verdú
            Nov 23 at 8:56










          • What error(s) do you get? Please add code to your question, since it is unreadable in a comment. Also please build a Minimal, Complete, and Verifiable example instead of including code and the full YAML header separately.
            – Ralf Stubner
            Nov 23 at 9:27










          • Sorry, I have updated right now
            – Laura Santulario Verdú
            Nov 23 at 10:04










          • @LauraSantularioVerdú Thanks, please see my updated answer.
            – Ralf Stubner
            Nov 23 at 10:06













          up vote
          1
          down vote










          up vote
          1
          down vote









          You are telling kableExtra not to load the LaTeX packages (why?), so you have to do this yourself. The features you are using require array, float and xcolor with the table option. One difficulty is that fancyvrb v3.0 already loads xcolor with other options. You can circumvent this by supplying table as a class option:



          ---
          output:
          pdf_document:
          keep_tex: yes
          classoption: table
          header-includes:
          - usepackage{array}
          - usepackage{float}
          ---


          ```{r results='asis'}
          options(kableExtra.latex.load_packages = FALSE)
          require(kableExtra)
          print(kable(head(cars),"latex") %>%column_spec(column=1:2,width = "0.5in"))
          ```

          ```{r results='asis'}
          print(kable(head(cars),"latex")%>%kable_styling(latex_options = c("striped", "bordered")))
          ```





          share|improve this answer














          You are telling kableExtra not to load the LaTeX packages (why?), so you have to do this yourself. The features you are using require array, float and xcolor with the table option. One difficulty is that fancyvrb v3.0 already loads xcolor with other options. You can circumvent this by supplying table as a class option:



          ---
          output:
          pdf_document:
          keep_tex: yes
          classoption: table
          header-includes:
          - usepackage{array}
          - usepackage{float}
          ---


          ```{r results='asis'}
          options(kableExtra.latex.load_packages = FALSE)
          require(kableExtra)
          print(kable(head(cars),"latex") %>%column_spec(column=1:2,width = "0.5in"))
          ```

          ```{r results='asis'}
          print(kable(head(cars),"latex")%>%kable_styling(latex_options = c("striped", "bordered")))
          ```






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 23 at 9:43

























          answered Nov 22 at 16:15









          Ralf Stubner

          13.6k21437




          13.6k21437












          • @LauraSantularioVerdú Please edit your question to include such information.
            – Ralf Stubner
            Nov 23 at 6:53










          • Thank you very much for your help. It is true that I 'd forgotten the YALM so I 've added now. The thing is that it is that now it works for function column_spec() but not for kable_styling(). I write you the code I have problems with: --- output: pdf_document header-includes: - usepackage{array} --- {r results='asis'} options(kableExtra.latex.load_packages = FALSE) require(kableExtra) print(kable(cars,"latex")%>%kable_styling(latex_options = c("striped", "bordered")))
            – Laura Santulario Verdú
            Nov 23 at 8:56










          • What error(s) do you get? Please add code to your question, since it is unreadable in a comment. Also please build a Minimal, Complete, and Verifiable example instead of including code and the full YAML header separately.
            – Ralf Stubner
            Nov 23 at 9:27










          • Sorry, I have updated right now
            – Laura Santulario Verdú
            Nov 23 at 10:04










          • @LauraSantularioVerdú Thanks, please see my updated answer.
            – Ralf Stubner
            Nov 23 at 10:06


















          • @LauraSantularioVerdú Please edit your question to include such information.
            – Ralf Stubner
            Nov 23 at 6:53










          • Thank you very much for your help. It is true that I 'd forgotten the YALM so I 've added now. The thing is that it is that now it works for function column_spec() but not for kable_styling(). I write you the code I have problems with: --- output: pdf_document header-includes: - usepackage{array} --- {r results='asis'} options(kableExtra.latex.load_packages = FALSE) require(kableExtra) print(kable(cars,"latex")%>%kable_styling(latex_options = c("striped", "bordered")))
            – Laura Santulario Verdú
            Nov 23 at 8:56










          • What error(s) do you get? Please add code to your question, since it is unreadable in a comment. Also please build a Minimal, Complete, and Verifiable example instead of including code and the full YAML header separately.
            – Ralf Stubner
            Nov 23 at 9:27










          • Sorry, I have updated right now
            – Laura Santulario Verdú
            Nov 23 at 10:04










          • @LauraSantularioVerdú Thanks, please see my updated answer.
            – Ralf Stubner
            Nov 23 at 10:06
















          @LauraSantularioVerdú Please edit your question to include such information.
          – Ralf Stubner
          Nov 23 at 6:53




          @LauraSantularioVerdú Please edit your question to include such information.
          – Ralf Stubner
          Nov 23 at 6:53












          Thank you very much for your help. It is true that I 'd forgotten the YALM so I 've added now. The thing is that it is that now it works for function column_spec() but not for kable_styling(). I write you the code I have problems with: --- output: pdf_document header-includes: - usepackage{array} --- {r results='asis'} options(kableExtra.latex.load_packages = FALSE) require(kableExtra) print(kable(cars,"latex")%>%kable_styling(latex_options = c("striped", "bordered")))
          – Laura Santulario Verdú
          Nov 23 at 8:56




          Thank you very much for your help. It is true that I 'd forgotten the YALM so I 've added now. The thing is that it is that now it works for function column_spec() but not for kable_styling(). I write you the code I have problems with: --- output: pdf_document header-includes: - usepackage{array} --- {r results='asis'} options(kableExtra.latex.load_packages = FALSE) require(kableExtra) print(kable(cars,"latex")%>%kable_styling(latex_options = c("striped", "bordered")))
          – Laura Santulario Verdú
          Nov 23 at 8:56












          What error(s) do you get? Please add code to your question, since it is unreadable in a comment. Also please build a Minimal, Complete, and Verifiable example instead of including code and the full YAML header separately.
          – Ralf Stubner
          Nov 23 at 9:27




          What error(s) do you get? Please add code to your question, since it is unreadable in a comment. Also please build a Minimal, Complete, and Verifiable example instead of including code and the full YAML header separately.
          – Ralf Stubner
          Nov 23 at 9:27












          Sorry, I have updated right now
          – Laura Santulario Verdú
          Nov 23 at 10:04




          Sorry, I have updated right now
          – Laura Santulario Verdú
          Nov 23 at 10:04












          @LauraSantularioVerdú Thanks, please see my updated answer.
          – Ralf Stubner
          Nov 23 at 10:06




          @LauraSantularioVerdú Thanks, please see my updated answer.
          – Ralf Stubner
          Nov 23 at 10:06


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434402%2fkableextra-functions-in-r-return-latex-errors-when-compiling-rmarkdown-file-to-p%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          Alexandru Averescu

          Trompette piccolo