I am encountering a weird issue where when I knit my markdown document to a pdf, some of the headers/figures are having a bunch of line breaks/spaces buffered above and below them (see image below for both code and knit document). I cannot figure out why this is occurring. I have checked the spaces above and below the headers and nearby chunks to make sure they are consistent, as I know this can sometimes cause similar issues, to no avail. There are some headers that are seemingly unaffected, and I tried to copy/paste those over the ones that are, and yet when doing so they also get the breaks added in that space.
When removing the code chunks for my plots, however, these mysterious spacings disappear.
Any suggestions would be greatly appreciated.
EDIT:
I believe I've solved the issue, and will leave this here in case anyone has similar issues in the future. I believe the buffers are being added around the headers under which the code chunks are placed because the image would otherwise be cutoff or not fit on the page in that location. Since markdown does not want the image to be cut off, it adds a space buffer to make sure it will fit on the page. You can work around this by either changing the size of the image or the location to make sure that it will fully fit on one page without being cut off.
Related
This is a two-part question, both parts are probably simple:
Why do my comments appear between the code and the output? I'd rather it display as I type it. For instance:
Gives the output:
But I would prefer the "We have 7 classes of data..." line to go above the code in the PDF.
Using the second picture from above, why does the gray box containing the code in have a larger border above the code than below? I'd rather the top have the same size border as the bottom.
I'm assuming this is an easy setting to change but I can't figure it out.
My plots are showing up with the titles way too zoomed it. They are printing like my available space is much smaller than it really is. It was working fine before. I've tried to reset it with dev.off() and par(mfrow=c(2,2)).
plot(mtcars$mpg)
Do you see how the dimensions are weird? I've also tried to clear the preivous plots.
This is the same plot printed on another computer with the viewerport set to about the same size.
I'm trying to create a flexdashboard with several tabs. One of them needs to include multiple graphs (~50). I produce the graphs under one single chunk within a loop (because numbers of graphs varies each time). What I get in the output is showing only some graphs without being able to scroll to see the rest of them. Scroll is totally deactivated but graphs are printed.
So far I've tried and didn't work to:
change the vertical_layout = scroll
adjust the row-height but graphs got shrunk (not readable)
download latest version of flexdashboard
include some CSS style (overflow-x: scrollbar;)
run the same in simple rmakrdown and works fine
when you put each graph in different chunk, scroll works properly but it doesn't solve my problem
Any ideas?
Thank you
I'm trying to use the knit2wp() function of knitr in order to blog to Wordpress as discussed here: http://yihui.name/knitr/demo/wordpress/
My problem is that, despite trying various options to control chunk width, including setting tidy.opts in the chunk options, and adjusting global width settings as seen here, my R code chunks won't wrap around, resulting in overly wide code chunks that require scrolling sideways to view them, like this.
Is there a setting that I'm missing that will cause R code chunks to wrap around? Also, is there a setting that will widen the grey boxes that appear in Wordpress for the code chunks? None of the width options seem to have any effect.
This is what my setup chunk currently looks like:
```{r setup, echo=FALSE}
library(knitr)
opts_knit$set(upload.fun = function(file) imgur_upload(file, key = "xxxx"))
opts_chunk$set(fig.width=5, fig.height=5, fig.align = 'center', cache=TRUE, tidy = FALSE)
````
I have also tried adding the line options(width = 80) to that chunk, as well as setting tidy.opts within each chunk, and none of these has had any effect.
As a dirty fix, you may add word-wrap: break-word; in css file to your pre element. Or embed it to a html file.
EDIT1:
Final advise is on the bottom. I am not an expert in WP, so you will have to work out the solution yourself.
As for how it will look, you may try it in a browser. There is an example with this page. You choose the element and may see a style on left. You may fix it in your browser (Right click, then "Inspect element" in Chrome) to see how it will look. However, this is not a permanent change: you change your local version. Refresh the page to get back to original.
Now I turn word wrapping off (better change it to break-word):
If you satisfied with result of in-browser if, there are to options to make change it in server:
If we play dirty anyway, you may embed the style tag into your template somewhere. Wrap it in a style tag (Editor removes them, so i am not able to post it):
pre {word-wrap: break-word}
Edit you css and either create a new class or fix the ones that you have. I ma not sure how to do it with wordpress, but there is some information here: https://wordpress.org/support/topic/how-to-edit-css-style-sheet
I believe that the right approach is the second, but if you want result ASAP, you may try the first one as it looks easier.
I have a template in which I'm attempting to change the source of a picture from Image 1, to Image 2 - yet I want Image 2 to keep the original size it was uploaded to the server in. (I want it in the position of Image 1, but its own dimensions.)
To do this, I figured I needed to use the adjust parameter - which I have attempted. The description for adjust=100% is "The picture is adjusted to be proportional to the original size." - which sounded like what I needed to do.
However, in my docx output, this seems to set the image size to be 100% of page width, rather than related to image size. (In the word image properties, it shows my image to be 208%, so I don't think it's related to my file!)
Is this a bug in opentbs, or have I misunderstood the docs? If so, how should I be doing it, or otherwise, can anyone thing of a work around? I attempted not using adjust at all, however that seems to have the same behaviour as adjust=inside - which I presume is the default.
With the normal thanks for a great tool!
Edit: The Error causing tag is below. I've found the problem reproducible when starting from nothing, and with just an image in the word doc. Word 2010, OpenTBS 1.8.
[onshow.logo;ope=changepic;tagpos=after;adjust=100%]
The problems was caused by the TbsPicAdjust() function expecting the image's dimensions to be provided in points, rather than pixels, as php's getimagesize() function was returning.
It was solved by replacing the two fixed coefficients in the TbsPicGetDim_OpenXML_dml() function with 9,525, rather 12,700 as they were originally coded. (Which would be an appropriate value, if the dimensions were in points, rather than pixels.)
After some research, from what I can see, getimagesize() always returns a size in pixels rather than points, so it looks to me like this could be a potential bug?
Additional Source for coefficient, combined with personal calculations: http://openxmldeveloper.org/discussions/formats/f/15/p/396/933.aspx
Workaround:
It depends if you are using the new (.docx) or old (.doc) style of document. If you have the newer style, I don't know for sure that you can change the image size without putting the tag directly into the XML. The older (VML, I believe) style uses <v:shape> to describe a picture rather than <pic:pic>. With v:shape, you can just put together a CSS-style string that describes the size, etc. of your image. Something like:
$imgStyle = "position:absolute;left:0;top:0;width:800;height:600"
Then you just have a tag next to your changepic tag; something like:
[imgStyle;att=v:shape#style]
The newer style does not use a style string like this to size and position images, the pic:pic element is full of nested tags describing the image so it is harder to get to the details (though you could certainly try). I ended up creating a subtemplate for my image switching because my template is in the new format with compatibility for the old format (so I have to maintain two image blocks). This allows me to maintain the XML directly for the image dimensions, but still be able to edit my main template in Word. I just use a tag in my main template that includes the subtemplate like:
[LineItem.template;block=w:r;file='img.xml']
Separating the manually controlled XML out allows me to edit the main template in Word without damaging the really custom parts. Using this technique though, you may have some trouble with onload/onshow tags in the subtemplate - everything I change in the subtemplate is controlled by a block.