Hmisc icon indicating copy to clipboard operation
Hmisc copied to clipboard

insert.bottom text in latex function does not appear below table

Open iiijohan opened this issue 8 years ago • 2 comments

A minimum working knitr example is inserted below and the resulting pdf file is attached here.

When I try to insert a text below a table using the latex function and setting table.env=FALSE the text does not appear below the table but on the side (Example 1).

When table.env=TRUE and center='center' the text is below the table but not centered (Example 2) while when center='centering' the text is again on the side and the table is not centered (Example 3). The third example might be as expected (sometimes you don't want the text centered) but the fourth is not.

\documentclass{article}
\begin{document}

<<"setup", results="hide", echo=FALSE, message=FALSE>>=
library("Hmisc")
foo <- data.frame(x = 1:2, y = 2:1)
@

Example 1:
<<results="asis">>=
latex(foo, file = "", insert.bottom = "Some text", where = "h",
      table.env = FALSE)
@

Example 2:
<<results="asis">>=
latex(foo, file = "", insert.bottom = "Some text", where = "h",
      table.env = TRUE, caption = "A caption", center = "center")
@

Example 3:
<<results="asis">>=
latex(foo, file = "", insert.bottom = "Some text", where = "h",
      table.env = TRUE, caption = "A caption", center = "centering")
@

\end{document}

Installing Hmisc after different commits suggest that the "bug" was introduced in the September 14 commit (ref = 59559fd) as it did work as expected after the previous commit on September 13 (ref = 4fc43af).

sessionInfo()
R version 3.3.2 Patched (2016-11-14 r71659)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=Swedish_Sweden.1252  LC_CTYPE=Swedish_Sweden.1252   
[3] LC_MONETARY=Swedish_Sweden.1252 LC_NUMERIC=C                   
[5] LC_TIME=Swedish_Sweden.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Hmisc_4.0-0     ggplot2_2.2.0   Formula_1.2-1   survival_2.40-1
[5] lattice_0.20-34 knitr_1.15     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.7         cluster_2.0.5       magrittr_1.5       
 [4] splines_3.3.2       munsell_0.4.3       colorspace_1.3-0   
 [7] highr_0.6           stringr_1.1.0       plyr_1.8.4         
[10] tools_3.3.2         nnet_7.3-12         grid_3.3.2         
[13] data.table_1.9.6    htmlTable_1.7       gtable_0.2.0       
[16] latticeExtra_0.6-28 htmltools_0.3.5     digest_0.6.10      
[19] lazyeval_0.2.0      assertthat_0.1      tibble_1.2         
[22] Matrix_1.2-7.1      gridExtra_2.2.1     RColorBrewer_1.1-2 
[25] acepack_1.4.1       rpart_4.1-10        evaluate_0.10      
[28] stringi_1.1.2       compiler_3.3.2      scales_0.4.1       
[31] chron_2.3-47        foreign_0.8-67     

iiijohan avatar Nov 17 '16 12:11 iiijohan

I fixed the code for the next CRAN release (also here on git) to put \par in front of the text if not in a table environment. As for the centering there is no way to control that.
For linux a new package tarball is at http://data.vanderbilt.edu/fh/attach/Hmisc_4.0-1.tar.gz Thanks for the excellent examples.

harrelfe avatar Nov 17 '16 14:11 harrelfe

Thanks for the quick reply and fix! Interested Windows (and Linux) users can also install the tarball with

install.packages("http://data.vanderbilt.edu/fh/attach/Hmisc_4.0-1.tar.gz", type = "source")

/Johan

iiijohan avatar Nov 18 '16 14:11 iiijohan