I am atempting to switch from RMarkdown to Quarto, but I have several difficulties.
Can´t find tabset options (fade, pills)
CSS style does not seem to work properly on Quarto tabset - the element is always grey when active and only colored properly when inactive, despite the css style working properly in rmarkdown:
.nav>li>a{
color: Grey;
}
.nav>li>a:hover, .nav>li>a:focus, .nav>li.active>a,
.nav>li.active>a:hover, .nav>li.active>a:focus{
color: #BD3632;
}
Can´t find a way for quarto to render in current environment (using RStudio), thus already loaded objects are loaded again and again for each rendering. It adds time for large objects, if you need multiple renders to polish your report.
Date specified in yaml header is rendered in the wrong format:
date: "`r format(Sys.time(), '%d.%m.%Y')`"
results in
PUBLISHED
February 2, 2023
Related
I've been having a problem where my css style sheet isn't effecting my HTML page. After trying numerous attempts at getting it to work, I deleted the style sheet and rewrote it. To test I changed my background of my site to red. This worked.
However when I went to change other things (like font) nothing else would change. This includes the red background which won't go back to the original white. I deleted that style sheet again, put in a new style sheet with this code for background:
body {
background: #fafafa;
color: #333333;
margin-top: 5rem;
}
But the background still won't change back. I restarted the server and Visual Studio Code but it just won't go back. This is the source on the html page which shows the color as not white:
body { background: #bb3636; color: #333333; margin-top: 5rem; }
In summary, CSS/HTML wasn't allowing any changes, after deleting, CSS was working for about a minute but now has gone back to not allowing any changes. I'm using Firefox as browser and Visual Studio Code. I'm also importing from bootstrap with a custom style sheet with additional style info.
Caching issue, as stated in the comments. Opened page through incognito mode to see changes had taken place there. Thanks for all the answers everyone.
When I create an R Markdown notebook in RStudio, the code chunks do all the usual text coloring of RStudio -- for example, comment lines and text constants in green, numerical constants in blue, etc. All the coloring still shows up nicely when I open RStudio's HTML preview window, and equally well when I view the HTML document in a browser.
Colors embedded in ggplot2 graphics objects in the same document are appearing equally successfully, up to this point (on-screen viewing of HTML).
However, when I send the HTML document to a printer from my Mac's browser, or when I use the Print dialog to export the HTML doc to PDF, all the text coloring disappears and everything is rendered in black text, even as the ggplot2 graphics colors are still completely successful in the printed output.
How can I recover the text coloring in printed output? Thanks.
(This is happening on a Mac laptop, just the same in Firefox and Safari.)
Editing 1 day later to add:
there's a symptom I hadn't noticed until after I applied #user2554330's initial solution. Hyperlinks in the markdown text (i.e., outside code chunks) get transformed into black text as well, and both the link text and the underlying URL get printed, unlike in the HTML output which is in color and shows only the text of the link.
I tried .hljs-link based on what I found at https://highlightjs.readthedocs.io/en/latest/css-classes-reference.html, but it didn't seem to have any effect.
This is hard to fix.
The problem is that rmarkdown uses the bootstrap framework to set styles. That framework tries to standardize the display on different browsers; since browsers are really variable in how they handle printing, it chooses a very simple black on white style for printing text.
You can create a CSS file that overrides these choices, or you can edit the source to the bootstrap CSS file so that it doesn't do that. Both are hard.
The problem with creating your own CSS file is that you need to re-specify the colors for each different type of text, marking all of the choices as !important. rmarkdown has several different color schemes for highlighting code. The default one looks like this after editing:
.hljs-literal {
color: #990073!important;
}
.hljs-number {
color: #099!important;
}
.hljs-comment {
color: #998!important;
font-style: italic;
}
.hljs-keyword {
color: #900!important;
font-weight: bold;
}
.hljs-string {
color: #d14!important;
}
If you're using a different highlight style, you'll need to edit that one instead.
Save this in a file, e.g. style.css, then put this in your YAML header:
output:
html_document:
css: style.css
The alternative to this is to edit the bootstrap source so that it no longer forces the color to black. Look for the #media print sections, and edit those. The file to edit is
<rmarkdown dir>/rmd/h/bootstrap/css/bootstrap.min.css
(which is a minimized version of bootstrap.css, so it's hard to edit).
If you really know what you're doing, you can recompile the file with different options; I haven't tried that.
EDITED TO ADD:
If you also want URLs to appear in color, you'll need to do something similar for them: override the override. A simple version is
a {
color: #23527c!important;
}
which forces all links to be blueish. This isn't ideal; it doesn't let links change color when selected, so the original on-screen version of your document will be changed, not just the print version. I'm too lazy right now to figure out how to handle the color change.
To stop the URL from being appended, you want this text:
a[href]::after {
content: "";
}
This says that anchors with HREF elements should get an empty string appended. The standard bootstrap spec appends the extra text that you saw. This doesn't appear to need !important, since the standard one didn't use that.
Put both of these entries into your style.css file, and you should get your links in color when printing, without appending the URL.
I just stumbled across this question, while also checking out other relevant answers, so I think this SO answer fixes your hyperlink problem. TLDR: Add urlcolor: blue and possibly linkcolor:red to the documents yaml section at the top :)
This this the current design of my report:
When I run it on different browser except for Chrome, it's looks almost ok (I have no idea why the HTML render is different from the expected result):
But in Chrome, it's a different story. Tiny boxes appear out of nowhere. How do I get rid of it?:
It seems that the boxes are generated upon loading the page. It creates a gif image named "Blank.gif" here is the complete code when I entered 'Inspect Element':
<img src="/Reserved.ReportViewerWebControl.axd?Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=712a96453ecc4eb89b71439a5477d6c6&Mode=true&OpType=ReportImage&ResourceStreamID=Blank.gif"/>
I solved it by just creating a CSS style that finds img elements in the body that matches the source of that image element with "Blank.gif" and then hides it.
Here is my solution:
<style>
body:nth-of-type(1) img[src*="Blank.gif"]
{
display: none;
}
</style>
I had the same problem. I'd used lines in the report to create custom-shaped tables. Those lines were the problem.
I created my own table using rectangles instead of lines. And there are no more empty images.
If I include the css style 'writing-mode: tb-rl', which is used for writing vertical text, in the html stream that is to be converted to pdf, I get a repeat of the first 30 pages, up to the number of pages that should have rendered, which is always counted correctly.
SO for example in a 70 page pdf, it will show 70 pages but will repeat the first 30, between 30 and 59, and then show the first 10 again for 60 onwards.
If I remove the vertical text, i.e the style writing-mode: tb-rl, everything returns to normal. The vertical text when displayed is rendered correctly on page 21.
This happens in our code that uses the pdf library, and also in the example provided by Winnovative.
Has anyone dealt with this before? I would love a fix or work around as Winnovative are slow to respond to anything. Thanks
I never did find a direct work around to this issue.
Winnovative HTML2PDF is inconsistent in all version (tried up to 7) when the output includes vertical text in a multi-page document.
I would guess that this is something to do with page flowing/measuring calculations.
One alternative which we tested to work (but we did not use for other reasons) was to switch to evo pdf - a Winnovative sister product and their recommended solution to several internet explorer based issues apparent in the Winnovative HTML2PDF solution.
Our solution in the end was to use the existing Winnovative library to convert the pages with vertical text into non paged images (full height), and then embed the image in the PDF.
Winnovative HTML to PDF converter rendering is compatible with WebKit rendering. The supported way to rotate text is using CSS -webkit-transform property. For example, you can rotate a whole div 5 degrees clockwise using the following code:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 200px;
height: 100px;
background-color: yellow;
/* Rotate div */
-webkit-transform: rotate(5deg);
}
</style>
</head>
<body>
<div>Hello</div>
</body>
</html>
Based on my research, it seems that what I want to do is not possible, but in case something has changed, I wanted to check to see if anyone had come up with a way to do this.
I have a web app that generates reports for print based on user selections in the browser window. I have a custom header and footer that, when the report is printed from the browser, should be repeated on every printed page. It is not the browser header and footer I need, but rather the custom ones that I generate. Also, I don't think this is an issue of CSS and media types, but I am not a CSS expert. I have no issues getting the header and footer to print once, but I can't get them to print on each page. I have read that perhaps if I recreated my report pages using tables, and then used table head tags and CSS, that may work at least to get the header on each page. I have not had success with this yet, but I will try it again if it is the only option. A coworker suggested that I count lines in my php and manually put out the header and footer as required. I guess that is an option, but it just seems like there should be a way to do this that isn't so "brute force"!
The other caveat is that I have to support IE 6, so I suspect some of the CSS things I have tried are just not supported.
If anyone knows any way to do this, that would be great! If there isn't, I will have to rethink my approach.
Thanks in advance!
UPDATE (14 Dec 2011)
I made considerable progress with this issue, and using some of the info from the answers, I did produce reports that were usable, but never as nice or as professional as I wanted. Footers would tend to be not close enough to the bottom of the page, I had to do a lot of guess work and "brittle" calculations about how big text was going to be to decide on inserting page breaks, I could only support a restricted set of page formats, and any changes to the reports resulted in a cascade of code changes and yet more brittle calculations. There was always a scenario that broke some part of some report. We revisted the requirements, and are now generating reports as PDFs using TCPDF. The documentation is a bit opaque, and it takes some experimentation, but the results are far superior and now the reports appear as they should. I would say to anyone trying to do HTML reports from the browser, unless they are very simple, save yourself the frustration (as others told me here) and go with PDFs or something similar.
It can be done with tables -- and I know I'm going to risk a downvote by suggesting using tables for layout - but we are talking IE6 here which isn't known for its fantastic CSS support :-)
If you set a CSS style as follows:
thead { display: table-header-group; }
tfoot { display: table-footer-group; }
Then when you create your HTML, render your body as:
<body>
<table>
<thead><tr><td>Your header goes here</td></tr></thead>
<tfoot><tr><td>Your footer goes here</td></tr></tfoot>
<tbody>
<tr><td>
Page body in here -- as long as it needs to be
</td></tr>
</tbody>
</table>
</body>
Yes it's not good (tables vs CSS), it's not ideal, but (importantly for you) it does work on IE6. I can't comment on Firefox as I've not tested it there, but it should do the job. This will also handle differnt sized pages, differing font sizes, etc. so it should "just work".
If you want the header and footer to appear on printed media only, then use the #media parameters to do the right thing:
#media print {
thead { display: table-header-group; }
tfoot { display: table-footer-group; }
}
#media screen {
thead { display: none; }
tfoot { display: none; }
}
Note
As of July 2015, this will still only work in Firefox and IE. Webkit-based browsers (cf. Chrome, Safari) have long standing bugs in their issue trackers about this if anyone feels strongly enough to vote on them:
The comments below this question tell me this is now resolved in Chrome. I haven't checked myself :-)
The original bugs against Chrome (for reference) are:
https://bugs.webkit.org/show_bug.cgi?id=17205
https://code.google.com/p/chromium/issues/detail?id=24826
https://code.google.com/p/chromium/issues/detail?id=99124
This will work in some browsers, not not all. I don't think there is an elegant cross-browser solution
Include the print footer/header you want in divs on the page (in this example div id='printableFooter')
In the screen css file put:
#printableFooter {display: none;}
In the print css file:
#printableFooter {display: block; position: fixed; bottom: 0;}
I would suggest to divide the page in table, and add the header part to first row and the footer part to the last row. The contents of the rows between the first and last rows can be changed dynamically so you will get the constant header and footer at desired pages.
----------
ROW1 HEADER
----------
ROW2
Insert dynamic contents here
ROW N-1
----------
ROW N Footer
try to generate a (rtf | pdf) document for printing