Reputation: 61
I am trying to export tables from R to Word using R-markdown via huxtable package but it looks unformatted. After knitr, RStudio launchs Word on Read only mode or Compatibility mode and tables looks pretty:
but when I re-open MS Word in normal mode, the tables looks unformatted:
---
title: "Prueba"
output:
word_document: default
html_document:
df_print: paged
---
knitr::opts_chunk$set(echo = FALSE)
require(dplyr)
library(tidyverse)
require(RODBC)
require(data.table)
library(huxtable)
library(flextable)
Loren ipsum...
tabla1 <- data.frame(mes = seq(1:4),
estado = 'observación',
valoracionesPorMes = seq(1:4))
tabla1 %>%
bind_rows(., tibble(valoracionesPorMes = sum(.[["valoracionesPorMes"]]))) %>%
as_hux(add_colnames = TRUE) %>%
set_bold(nrow(tabla1)+2,1:ncol(tabla1),T) %>%
set_bold(1,1:ncol(tabla1),T) %>%
set_bottom_border(1,1:ncol(tabla1),1) %>%
set_align(0:nrow(tabla1)+2, 1:ncol(tabla1), 'center') %>%
set_width(100) %>%
set_col_width(0.25) #%>%
# huxtable::as_flextable()
I am using huxtable because I need to knitr to Word and looks suitable option to add format to tables, and total sums rows. I know I could reformat in Ms Word but this is a flow with multiple tables, it is not suitable because it is a task that will be repeated many times.
Upvotes: 2
Views: 570
Reputation: 2262
Remove the set_width()
and set_col_width()
lines. You'll then get a reasonable width by default.
Upvotes: 1