Hemken / Statamarkdown

Functions to write Stata documentation with knitr
Other
59 stars 11 forks source link

output font size change, or width change? #34

Closed xiangao closed 1 year ago

xiangao commented 1 year ago

How to change the font size in output? Currently the output always folds because it exceeds the width. See the example:

reg mpg price

  Source |       SS           df       MS      Number of obs 

= 74 -------------+---------------------------------- F(1, 72)
= 20.26 Model | 536.541807 1 536.541807 Prob > F
= 0.0000 Residual | 1906.91765 72 26.4849674 R-squared
= 0.2196 -------------+---------------------------------- Adj R-squared = 0.2087 Total | 2443.45946 73 33.4720474 Root MSE
= 5.1464



mpg | Coefficient Std. err. t P>|t| [95% co n
f. interval] -------------+---------------------------------------------------

price | -.0009192 .0002042 -4.50 0.000 -.001326 3
-.0005121 _cons | 26.96417 1.393952 19.34 0.000 24.1853 8
29.74297


remlapmot commented 1 year ago

Which output format are you rendering to: html_document, or pdf_document or word_document or something else?

The easiest way to achieve this for pdf_document is to set the fontsize option in the YAML header to say 10pt, e.g.

---
title: "Make pdf font smaller"
author: "Name"
date: "2023-03-14"
output: pdf_document
fontsize: 10pt
---

```{r message=FALSE}
library(Statamarkdown)
sysuse auto, clear
regress mpg price
remlapmot commented 1 year ago

For HTML output you can change the font size using CSS, e.g. here the body font is the normal text in the document and the pre font is for the code chunks.

---
title: "Some HTML settings"
output: html_document
---

```{css echo=FALSE}
body {
  font-size: 10px;
}

pre {
  font-size: 10px;
}
library(Statamarkdown)

Some normal/body text.

* Some pre text
sysuse auto, clear
reg mpg price
Hemken commented 1 year ago

Thanks, Tom! I continue to learn from you!

-- Doug Hemken SSCC statistical consultant

From: Tom Palmer @.> Sent: Tuesday, March 14, 2023 5:22 AM To: Hemken/Statamarkdown @.> Cc: Subscribed @.***> Subject: Re: [Hemken/Statamarkdown] output font size change, or width change? (Issue #34)

For HTML output you can change the font size using CSS, e.g. here the body font is the normal text in the document and the pre font is for the code chunks.


title: "Some HTML settings"

output: html_document



body {

  font-size: 10px;

}

pre {

  font-size: 10px;

}

library(Statamarkdown)

Some normal/body text.


* Some pre text

sysuse auto, clear

reg mpg price

— Reply to this email directly, view it on GitHubhttps://github.com/Hemken/Statamarkdown/issues/34#issuecomment-1467814103, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACYBMEZDSVJVEFGW24JOK63W4BBCZANCNFSM6AAAAAAVZZJLXI. You are receiving this because you are subscribed to this thread.Message ID: @.***>

remlapmot commented 1 year ago

My pleasure Doug.

There are many other ways as well.

For example, for pdf_document you could reduce the margin around the document (here setting to 1 inch on all sides).

---
title: "PDF with small margins"
geometry: margin=1in
output: pdf_document
---

For html_document you could make the body wider - there seem to be many ways to achieve this in CSS, one way is (I find Stackoverflow examples using max-width and don't really know which is preferable).

```{css echo=FALSE}
body {
  min-width: 100% !important;
}

And for `word_document`, you can make a template document with the margins and heading and paragraph styles (with those styles having the desired font sizes) of your choosing and then specify that as your `reference_docx`.

````rmarkdown
---
title: "Fancy Word doc"
output:
  word_document:
    reference_docx: my-nice-word-template.docx
---

And there are the equivalents of these in Quarto too (just sometimes an option name changes slightly).

Hemken commented 1 year ago

Xiangoa,

You might also need to think about your linesize setting in Stata. You can type

display c(linesize)

In Stata. I think you want to set a wider margin in Stata.

Doug Hemken

Statistical consultant Social Science Computing Cooperative Univ. of Wisc. – Madison

@.**@.> 608-262-4327

From: xiangao @.> Sent: Monday, March 13, 2023 8:08 PM To: Hemken/Statamarkdown @.> Cc: Subscribed @.***> Subject: [Hemken/Statamarkdown] output font size change, or width change? (Issue #34)

How to change the font size in output? Currently the output always folds because it exceeds the width. See the example:

reg mpg price

Source | SS df MS Number of obs

= 74 -------------+---------------------------------- F(1, 72) = 20.26 Model | 536.541807 1 536.541807 Prob > F = 0.0000 Residual | 1906.91765 72 26.4849674 R-squared = 0.2196 -------------+---------------------------------- Adj R-squared = 0.2087 Total | 2443.45946 73 33.4720474 Root MSE = 5.1464



 mpg | Coefficient  Std. err.      t    P>|t|     [95% co

n f. interval] -------------+---------------------------------------------------

price | -.0009192 .0002042 -4.50 0.000 -.001326

3 -.0005121 _cons | 26.96417 1.393952 19.34 0.000 24.1853 8 29.74297



— Reply to this email directly, view it on GitHubhttps://github.com/Hemken/Statamarkdown/issues/34, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACYBME63655D7BIUML3KNZ3W37AHDANCNFSM6AAAAAAVZZJLXI. You are receiving this because you are subscribed to this thread.Message ID: @.***>

xiangao commented 1 year ago

Thank you, Tom and Doug! "set linesize 96" works for me. Good to know these tricks!