Hmisc :: latex does not print a signature with a table object

First I will tell you that I am trying to make a big picture if I am wrong. I have a nested table that I would like to put as a LaTeX table in RStudio using knitr. I'm fine until I try to add a signature. I tried the example on page 9 in tables vignette (LINK) .

It works without a title, but when I add a signature, it is not. It also works with non-table object. The funny thing is that latex.default works, but causes an error in the RStudio / knitr Compile PDF, and from what I read, latex is called anyway; plus the table is no longer rounded. I tried latexTabular , but this is not rounded either.

 library(Hmisc); library(tables) latex(head(mtcars), file="", caption="de") #works x <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) latex(x, file="", caption="de") #no caption :( 

Ideally, I would like to have \caption{de} in the output, but I can't figure out where I am going wrong.

If useful, here is the entry and exit:

 > latex(x, file="", caption="de", label="tab1") \begin{tabular}{lccccc} \hline & & \multicolumn{2}{c}{Sepal.Length} & \multicolumn{2}{c}{Sepal.Width} \\ Species & n & mean & sd & mean & sd \\ \hline setosa & $\phantom{0}50$ & $5.01$ & $0.35$ & $3.43$ & $0.38$ \\ versicolor & $\phantom{0}50$ & $5.94$ & $0.52$ & $2.77$ & $0.31$ \\ virginica & $\phantom{0}50$ & $6.59$ & $0.64$ & $2.97$ & $0.32$ \\ All & $150$ & $5.84$ & $0.83$ & $3.06$ & $0.44$ \\ \hline \end{tabular} 
+6
source share
3 answers

The x object from tabular () has the class "tabular" and is dispatched to latex.tabular, which has no caption argument. I assume that it is intended for use by Sweave, who would be tasked with providing a signature.

However, page 22 gives an example of the argument "\\caption{.}" For the parameters in the table vignette. This seems to give success:

  x <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) latex(x, file="", options = list( tabular="longtable", toprule="\\caption{This is a sample caption.}\\\\ \\toprule", midrule="\\midrule\\\\[-2\\normalbaselineskip]\\endhead\\hline\\endfoot")) \begin{longtable}{lccccc} \caption{This is a sample caption.}\\ \toprule & & \multicolumn{2}{c}{Sepal.Length} & \multicolumn{2}{c}{Sepal.Width} \\ Species & n & mean & sd & mean & sd \\ \midrule\\[-2\normalbaselineskip]\endhead\hline\endfoot setosa & $\phantom{0}50$ & $5.01$ & $0.35$ & $3.43$ & $0.38$ \\ versicolor & $\phantom{0}50$ & $5.94$ & $0.52$ & $2.77$ & $0.31$ \\ virginica & $\phantom{0}50$ & $6.59$ & $0.64$ & $2.97$ & $0.32$ \\ All & $150$ & $5.84$ & $0.83$ & $3.06$ & $0.44$ \\ \hline \end{longtable} 
+6
source

I am ashamed to admit it, but the whole problem was that I was trying to force something inside a piece of code that did not belong. I gasp with pride to help future seekers. Latex material comes out. Therefore, if you are trying to build the table above as a beautifully formatted table, this is what you are looking for:

 \begin{table}[ht] \caption{This is a sample caption. \label{guy}} <<desc, echo = FALSE, results = 'asis'>>= x <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) latex(x) @ \end{table} 
+9
source

That should work.

 cat('\\begin{table}[ht] \\centering') latex(tabularTable) cat('\\caption{some caption}') cat('\\label{tab:table1}') cat('\\end{table}') 
0
source

Source: https://habr.com/ru/post/925262/


All Articles