hughjonesd / huxtable

An R package to create styled tables in multiple output formats, with a friendly, modern interface.
http://hughjonesd.github.io/huxtable
Other
322 stars 28 forks source link

Custom table environment like {table*} in latex #187

Closed mingsu closed 4 years ago

mingsu commented 4 years ago

custom table environment can be very important for some cases, such as, the fullwidth table has to be set to table* in twocolumn layout.

Although there is a function set_tabular_environment, but it seems not working with table* environment. Can it be easily implemented? Thanks.

expect

set_tabular_environment(ht, "table*")

gives

\begin{table*}
....

\end{table*}
hughjonesd commented 4 years ago

That function gives the environment used for the "tabular", not the "table" environment that surrounds it. Could you explain what the advantage of table* is, or point me to a helpful resource? If so I might accept this as an enhancement.

mingsu commented 4 years ago

@hughjonesd Thanks for your quick response!

table* with [t] or [b] option in latex can make floating fullwidth table in twocolumn layout.

Here is a resource might help to understand.

https://tex.stackexchange.com/questions/89462/page-wide-table-in-two-column-mode

I am giving MWE here:

> cat MWE.Rmd
---
title: "fullwidth table using huxtable in twocolumn layout within latex"
classoption: 
    - twocolumn
output:
  pdf_document:
    keep_tex: yes
---

# I want a fullwidth table 

```{r echo = F}
require(magrittr)
require(huxtable)
head(mtcars) %>%
    as_hux() # %>%
    # set_table_environment(env = "table*", option = "tb")

test

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.

this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo. this is minimal demo.


The MWE above gives:

<img width="635" alt="image" src="https://user-images.githubusercontent.com/3145794/98467547-e2832a00-2210-11eb-955b-b157d491588d.png">

The key latex code for the table is:

cat MWE.tex

\begin{table}[ht] \begin{centerbox} \begin{threeparttable} \label{tab:unnamed-chunk-1} \setlength{\tabcolsep}{0pt} \begin{tabular}{l l l l l l l l l l l}

...... ......

\end{tabular} \end{threeparttable}\par\end{centerbox}

\end{table}


if we change the `table` environment to `table*`, as shown below:

cat MWE_expected.tex

\begin{table*}[ht] \begin{centerbox} \begin{threeparttable} \label{tab:unnamed-chunk-1} \setlength{\tabcolsep}{0pt} \begin{tabular}{l l l l l l l l l l l}

...... ......

\end{tabular} \end{threeparttable}\par\end{centerbox}

\end{table*}



It will give this:

<img width="1171" alt="image" src="https://user-images.githubusercontent.com/3145794/98467523-c2536b00-2210-11eb-80a8-74d4ab4ecf35.png">
hughjonesd commented 4 years ago

Could you try the current code in the "table_environment" branch?

remotes::install_github("hughjonesd/huxtable", ref = "table_environment")
library(huxtable)

This should give you a new table_environment property which you can set to e.g. "table*".

Tell me how you get on.

mingsu commented 4 years ago

@hughjonesd Great thanks! It works as expected.

hughjonesd commented 4 years ago

OK, I'll merge to master.

mingsu commented 4 years ago

Great!