2015-04-06 4 views
2

Действительно оцените вашу помощь!xtable: изменить цвет и толщину (table.attributes)

Я генерация LaTeX таблицы с R и xtable пакета, как это:

df <- cbind(c("SUNE", "WST"), c("Apr 01", NA), c("EXL", "VG"), c("Mar 18", NA)) 
out_table <- xtable(df) 
align(out_table) <- "lll|ll" 
print(out_table, floating = FALSE, hline.after = NULL, ...) #omitted some formatting arguments 

Извинения для ограниченного образца кода, но пример вывода выглядит следующим образом:

enter image description here

На этом этапе я хотел бы изменить цвет и толщину вертикальной линии на «#bdbdbd» (серый) и 0,25 пт. Я пробовал выполнить шаги в этом сообщении (How to put a spacing of colors in a table of xtable?), но без каких-либо успехов. Можете ли вы мне помочь?

Edit 1: Желаемая Вывод производится в Illustrator

enter image description here

ответ

2

Это кажется предпочтительным способом, чтобы получить нужный формат, благодаря @ user20650

\documentclass{article} 
\usepackage{colortbl} 
\usepackage[usenames,dvipsnames]{xcolor} 
\begin{document} 

<<results='asis'>>= 
library('xtable') 
options(xtable.comment = FALSE) 

df <- cbind(c("SUNE", "WST"), c("Apr 01", NA), 
      c("EXL", "VG"), c("Mar 18", NA)) 
out_table <- xtable(df) 
align(out_table) <- "lll|ll" 
print(out_table, floating = FALSE, hline.after = NULL, 
     include.rownames=FALSE, include.colnames=FALSE) 

# \begin{tabular}{lll|ll} 
# & 1 & 2 & 3 & 4 \\ 
# 1 & SUNE & Apr 01 & EXL & Mar 18 \\ 
# 2 & WST & & VG & \\ 
# \end{tabular} 

attr(out_table, "align") <- 
    c("l", "l","l","!{\\color[HTML]{BDBDBD}\\vrule width .25pt}","l","l") 
print(out_table, floating = FALSE, hline.after = NULL, 
     include.rownames=FALSE, include.colnames=FALSE) 

# \begin{tabular}{lll!{\color[HTML]{BDBDBD}\vrule width .25pt}ll} 
# & 1 & 2 & 3 & 4 \\ 
# 1 & SUNE & Apr 01 & EXL & Mar 18 \\ 
# 2 & WST & & VG & \\ 
# \end{tabular} 
@ 

\end{document} 

Результаты с

enter image description here

И некоторые другие варианты дилетантский:

Все это составляет заменял из {lll|ll} для {lll!{\color[HTML]{BDBDBD}\vrule width .25pt}ll}

И вам нужен пакет Xcolor использовать шестнадцатеричный цвет, #BDBDBD и colortbl для цветной VRule

\documentclass{article} 
\usepackage{colortbl} 
\usepackage[usenames,dvipsnames]{xcolor} 
\begin{document} 

<<results='asis'>>= 
library('xtable') 
options(xtable.comment = FALSE) 

df <- cbind(c("SUNE", "WST"), c("Apr 01", NA), 
      c("EXL", "VG"), c("Mar 18", NA)) 
out_table <- xtable(df) 
align(out_table) <- "lll|ll" 
print(out_table, floating = FALSE, hline.after = NULL) 

# \begin{tabular}{lll|ll} 
# & 1 & 2 & 3 & 4 \\ 
# 1 & SUNE & Apr 01 & EXL & Mar 18 \\ 
# 2 & WST & & VG & \\ 
# \end{tabular} 

cat(gsub(paste0(attr(out_table, 'align'), collapse = ''), 
     'lll!{\\color[HTML]{BDBDBD}\\vrule width .25pt}ll', 
     print(out_table, floating = FALSE, hline.after = NULL, 
       print.results = FALSE), fixed = TRUE)) 

# \begin{tabular}{lll!{\color[HTML]{BDBDBD}\vrule width .25pt}ll} 
# & 1 & 2 & 3 & 4 \\ 
# 1 & SUNE & Apr 01 & EXL & Mar 18 \\ 
# 2 & WST & & VG & \\ 
# \end{tabular} 
@ 


\end{document} 

дает мне этот

enter image description here

В качестве альтернативы, если что-то подобное работает, это было бы намного проще, чем указано пользователем @ user20650 (хотя сначала я попытался что-то похожее, и мне было очень сложно о выравниваниях, но я, вероятно, просто что-то не так)

\documentclass{article} 
\usepackage{colortbl} 
\usepackage[usenames,dvipsnames]{xcolor} 
\begin{document} 

<<results='asis'>>= 
library('xtable') 
options(xtable.comment = FALSE) 

df <- cbind(c("SUNE", "WST"), c("Apr 01", NA), 
      c("EXL", "VG"), c("Mar 18", NA)) 
out_table <- xtable(df) 
align(out_table) <- "lll|ll" 
print(out_table, floating = FALSE, hline.after = NULL) 

# \begin{tabular}{lll|ll} 
# & 1 & 2 & 3 & 4 \\ 
# 1 & SUNE & Apr 01 & EXL & Mar 18 \\ 
# 2 & WST & & VG & \\ 
# \end{tabular} 

attr(out_table, 'align') <- 
    'lll!{\\color[HTML]{BDBDBD}\\vrule width .25pt}ll' 
print(out_table, floating = FALSE, hline.after = NULL) 

# \begin{tabular}{lll!{\color[HTML]{BDBDBD}\vrule width .25pt}ll} 
# & 1 & 2 & 3 & 4 \\ 
# 1 & SUNE & Apr 01 & EXL & Mar 18 \\ 
# 2 & WST & & VG & \\ 
# \end{tabular} 
@ 


\end{document} 

И вы все еще получаете те же самые результаты:

enter image description here

+0

(+1). Я думаю, что это хороший способ: возможно, установка выравнивания через атрибуты упрощает бит 'attr (out_table,« align ») <- 'lll! {\\ color {red} \\ vrule width 2.25pt } ll'' – user20650

+0

@ user20605 это первое, что я пробовал, я сделал что-то неправильно, видимо, и получил ошибки, и пошел по этому более сложному пути – rawr

+0

ах да, я вижу ... похоже, что он сталкивается с ошибками при исключении row.names – user20650

 Смежные вопросы

  • Нет связанных вопросов^_^