Skip to content

Add options for specialized environments before and after LaTeX table code #157

Closed

Description

@rich-iannone

This new issue is based on a comment from @kuriwaki from the closed issue #114.

xtable::print.xtable has an argument floating that either generates .tex with a float environment with captions \begin{table}... (the default), or without the floating environment and starts directly with \begin{tabular} (if set to FALSE). Both options would be great to have with the file export argument.

library(xtable)
library(ggplot2)

tab <- xtabs(~ cyl + drv, data = mpg)
xtbl <- xtable(tab)

print.xtable(xtbl, floating = TRUE)
#> % latex table generated in R 3.5.1 by xtable 1.8-3 package
#> % Sun Jan 13 15:28:24 2019
#> \begin{table}[ht]
#> \centering
#> \begin{tabular}{rrrr}
#>   \hline
#>  & 4 & f & r \\ 
#>   \hline
#> 4 &  23 &  58 &   0 \\ 
#>   5 &   0 &   4 &   0 \\ 
#>   6 &  32 &  43 &   4 \\ 
#>   8 &  48 &   1 &  21 \\ 
#>    \hline
#> \end{tabular}
#> \end{table}
print.xtable(xtbl, floating = FALSE)
#> % latex table generated in R 3.5.1 by xtable 1.8-3 package
#> % Sun Jan 13 15:28:24 2019
#> \begin{tabular}{rrrr}
#>   \hline
#>  & 4 & f & r \\ 
#>   \hline
#> 4 &  23 &  58 &   0 \\ 
#>   5 &   0 &   4 &   0 \\ 
#>   6 &  32 &  43 &   4 \\ 
#>   8 &  48 &   1 &  21 \\ 
#>    \hline
#> \end{tabular}

Created on 2019-01-13 by the reprex package (v0.2.1)

Activity

  1. self-assigned this
    on Jan 31, 2019
  2. benediktschfr commented on Jun 17, 2020

    @benediktschfr

    It would be great to control the floating of a table (as in LaTeX like \begin{table}[htbp]) and not just automatically break it. Or at least control the floating environment (table instead of lontable).

  3. added this to the FUTURE milestone on Aug 22, 2022
  4. AaronGullickson commented on Mar 11, 2023

    @AaronGullickson
    Contributor

    I want to second this suggestion. I am in the process of switching over to gt from kableExtra and this is the one thing making that transition difficult. IMO, a floating environment should be the default for any latex output.

  5. andrewheiss commented on Nov 1, 2023

    @andrewheiss

    Hi! Just checking in on this, given advancements in Quarto. With Quarto it's possible to control figure position in PDF/LaTeX documents (see https://quarto.org/docs/authoring/figures.html#figure-position), with options like b, h, t, etc.

    With {gt} tables, though, it isn't possible yet, leading to tables that span multiple pages and the general inability to position tables as floats, like this issue/discussion here: quarto-dev/quarto-cli#7171

  6. modified the milestones: FUTURE, v0.12.0 on Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions