pander control column width - r

table output
I am trying to create a table to hold some basic information using Kable in RMarkdown that will be generated in HTML, PDF, and Word.
I have used pander function to do that and adjust some options such as split.table, split.cells, but it did not work out.
I also tried changing font size of the whole file by setting
classoption: a1paper
fontsize: 3pt
Then the table becomes pretty small but 5 columns are still not in the same line. Besides, fontsizeļ¼š3pt only changes the text size but the font size in the table does not change.
I just want the 5 columns of the data frame to be on the same line, any methods workable are welcome.

Related

R markdown to MS Word: keep paragraphs together

I am creating a report in MS Word and am using a RMarkdown document. I have managed to use a reference.docx file where I adjusted the styles of titles, headers, text, and figure captions to my need. Now I would like to make sure some lines, paragraphs and pictures are kept together on the same page. Is there a way to do this?
Here's my sample code
---
title: "Test"
output:
word_document:
reference_docx: reference.docx
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
Here is some text.
### I Use This as Figure Caption Above the Figure
(Index, 2015=100, seasonally adjusted series)
![Source: World Bank](https://previews.123rf.com/images/lovjane/lovjane1610/lovjane161000009/64921112-hand-drawn-sun-with-face-and-eyes-alchemy-medieval-occult-mystic-symbol-of-sun-vector-illustration-.jpg){ width=10cm }
The last 3 lines are the ones I would like to be kept together in my MS-Word output file, i.e. Caption+(Comment)+Figure.
You can include certain properties in your style definitions - that's the best way. You'll want to test this in the Word environment to get a feel for how these work as they can be confusing.
For all paragraphs that should stay together on the same page (as long as the total length does not exceed the space available on the page):
Paragraph dialog box (P-dlg)/Line and Page Breaks tab (LPB-tab)/Keep with Next
In the Word object model corresponds to: Paragraph.KeepWithNext = true/false
For the last paragraph in this group, make sure to remove this property. This means a separate style for the last paragraph!
To force lines to stay together:
P-dlg/LPB-tab/Keep lines together
In the Word object model corresponds to: Paragraph.KeepTogether = true/false
The same commands will apply to any pictures formatted in-line with the text. You may want to define separate styles for pictures if they need special alignment or spacing.
For pictures with text-wrap formatting the trick to keeping them together with specific text is to lock the anchor to the Range of that text. This cannot be part of a style, however.

Controlling space between lines or rows in tables using papaja with r markdown for pdf

I'm working on APA tables with the package papaja and r markdown together with Latex and I want to adjust the vertical space between rows in a relatively big table so it will fit on one page. Additionally, if needed, i also want to reduce font size and column width. Is this possible with papaja's apa_table() function? Just using the small argument to TRUE did not do the trick.
As mentioned in the papaja manual you can adjust line spacing in tables by adding some lines to the document preamble. The following will result in single-spaced tables with double-spaced caption and table note:
header-includes:
- \usepackage{setspace}
- \AtBeginEnvironment{tabular}{\singlespacing}
- \AtBeginEnvironment{lltable}{\singlespacing}
- \AtBeginEnvironment{tablenotes}{\doublespacing}
- \captionsetup[table]{font={stretch=1.5}}
- \captionsetup[figure]{font={stretch=1.5}}
The column width is currently not controllable with apa_table() but you can use landscape = TRUE if the table doesn't fit in portrait mode. Font size can currently only be adjusted with small = TRUE.

Table numbering in texreg output

Texreg is the only package I found that produces nicely formatted Latex tables for multi-level regression (e.g., lmer).
The generated table caption is "Table N: caption", where N is the number of texreg tables in the document up to that point, including the current table. The caption text can be set using the caption parameter, but I can't find a way to change the "Table N:"
This is an issue if other types of tables (e.g., xtable) are also used in the same RMarkdown/knitr document.
Is there a way to modify this part of the caption without manually changing the compiled .tex file?
texreg creates a tabular environment that contains the actual table. By default, texreg additionally wraps this tabular environment in a table float, which positions the table on the page and creates the caption. If you choose to do this manually, you can use texreg's argument table = FALSE. In that case, you may want to write the code for the table float manually in your LaTeX file and possibly adjust the caption in custom ways:
\begin{table}
<insert texreg output with table = FALSE here>
\caption{My table}
\end{table}
You can edit the caption manually or redefine the caption command to do whatever you want. This source contains some useful suggestions on how to redefine the appearance of the caption.

How to Shrink Column Width and Table Size In Kable(type = rmarkdown)

I am making slides in rmarkdown, and when I use
kable(tablename)
the columns adjust so the table fits the whole slide.
I want the columns to be a smaller fixed size somehow. Either by wrapping columns around the width of the text/numbers, or declaring a fixed width.
Also, I wouldn't mind shrinking the whole table to be a much smaller size.
I'd like to avoid using other packages and just want to know how to do this with kable.
I do this when kniting to .pdf by using latex commands and minipage package. I don't think you will have to install this.
\centering
\begin{minipage}{0.4\textwidth}
```{r}
Use your kable command here to create your first table
knitr::kable(data[c(rownum),],format = "latex")
```
\end{minipage}
\begin{minipage}{0.4\textwidth}
```{r}
Use your kable command here to create your second table
knitr::kable(data[c(rownum),],format = "latex")
```
\end{minipage}
\flushleft
the \centering and \flushleft commands are your preference and do what you would expect. The two minipage commands will put the tables side by side. you can place more than two byt will have to play around with the {0.4\textwidth} part, which means allow table to occupy 0.4 of the text width.
Hope this helps!

rmarkdown - Increasing html width to fit entire table

I was looking for a way to change the setting in my Rmd file so that the html output contains all the columns and the table does not break. I tried to change the css properties as in this solution (Output table width in Rmarkdown) but this does not affect my output.
I have currently 17 columns and using a pandoc.table, but only 5 coloumns are shown before the table is broken and the next 5 columns are displayed below.
What changes do I need to make so that the entire table can be shown in my html output?
Thanks for your help.
I can't use the pandoc package because is not currently available for R version 3.2.0. Instead, I used knitr with the kable() function. This code works fine:
{r, echo=FALSE, results='asis'}
library(knitr)
examp <- data.frame(matrix(rep("Unicorn"), nrow=5, ncol=100))
kable(examp)
I think, because you don't provide an example, that you need to specify the results='asis' chunk option.
Try ?kable for further information.
Anyway ?pandoc.table shows that there is an option split.table that may help.

Resources