# サンプル引用文献リストを取得する dir.create("img") file.copy(system.file("resources/bibliography/rmdja.bib", package = "rmdja"), to = "./") # 上記は日本語引用文献リストのために必要 # サンプル画像等を参照するパス file_loc <- system.file("resources", package = "rmdja") knitr::opts_chunk$set(cache = T)
\textrm{Нужны новые формы. Новые формы нужны, а если их нет, то лучше ничего не нужно.}
{=latex}
\textmc{新しいフォーマットが必要なんですよ. 新しいフォーマットが. それがないというなら, いっそ何もないほうがいい.}
{=latex}r tufte::quote_footer('--- A. チェーホフ『かもめ』')
\tableofcontents[hideallsubsections]
beamer
で日本語を含むスライドを作るためのテンプレート兼用例集reveal.js
などHTML媒体は他の資料を参照reveal.js
じゃダメなの?reprex
でコピペremotes::install_github( "Gedevan-Aleksizde/my_latex_templates", subdir = "rmdja")
apt
より公式ダウンローダの方が良いかもexample/
のテンプレートを参考にoutput: rmdja::beamer_presentation_ja
knitr::include_graphics(file.path(file_loc, "img/render.png"))
knitr::include_graphics(file.path(file_loc, "img/readme-selection.png"))
output: rmdja::beamer_presentation_ja: latex_engine: lualatex mainfont: "`r if(Sys.info()['sysname'] == 'Linux'){'DejaVu Serif'} else {'Times New Roman'}`" mainfontoptions: sansfont: "`r if(Sys.info()['sysname'] == 'Linux'){'DejaVu Sans'} else {'Arial'}`" monofont: 'Courier New' jfontpreset: "`r switch(Sys.info()['sysname'], 'Linux' = 'noto', 'Darwin' = 'hiragino-pro', 'Windows' = 'ms')`"
##
タイトル" でスライドの開始# 節見出し ## タイトル1 - **太字** **bold** - _強調_ _emph_ - `タイプライタ体` `mono` - ~~取り消し線~~
タイプライタ体
mono
\
...`{=latex}``で囲むpxrubrica
の構文を参考にnames(knitr::knit_engines$get())
require(conflicted) # パッケージの競合防止用 require(tidyverse) # 全般 require(ggthemes) # ggplot2のデザイン変更 require(ggdag) # ネットワーク図の用例に require(DiagrammeR) # DOT言語でのネットワーク図例 require(kableExtra) # 表の出力オプション require(stargazer) # 複雑なLaTeXの表を扱う例
citr
: 引用文献の挿入をGUIでbookdown
: 数式をGUIでecho=T
でチャンク内コードを表示tidy=F
して手動改行class.source = "numberLines, LineAnchors"
で行番号表示(参考)text <- '```r require(conflicted) require(tidyverse) require(ggthemes) ```' cat(text)
```{R load-packages2, echo=T, class.source = "numberLines LineAnchors", eval=F} require(conflicted) require(tidyverse) require(ggthemes)
## カラー絵文字 * [`BXcoloremoji`](https://github.com/zr-tex8r/BXcoloremoji)をインストール + `\coloremoji{}` で絵文字表示: \ifdefined\coloremoji \coloremoji{🍣} \else (ここに絵文字) \fi + 実際には**画像に置き換えている** * グラフ描画には特に設定必要なし + ソースコード上のものは文字化けする ```r plot(1:10, pch = "🍣")
$
で挟むらんま$\frac{1}{2}$
$$
で挟んだ範囲に\LaTeX 構文$$\begin{aligned} & \sin^2(x) + \cos^2(x) = 1\\ & f(x) = \frac{1}{(2\pi)^2}\int_{\mathbb{R}^n} \hat{f}(\omega)\exp(i\omega x)d\omega \end{aligned}$$
$$\begin{aligned} & \sin^2(x) + \cos^2(x) = 1\ & f(x) = \frac{1}{(2\pi)^2}\int_{\mathbb{R}^n}\hat{f}(\omega)\exp(i\omega x)d\omega \end{aligned}$$
bookdown
パッケージのアドインで補完knitr::include_graphics(file.path(file_loc, "img/math-input.png"))
\mathbb{}
とか\hat{}
とか\aligned
等環境の入力は不可out.width=
/out.height=
でサイズ調整fig.show="hold"
knitr::include_graphics(file.path(file_loc, c("img/tiger.eps", "img/tiger.pdf", "img/tiger.png")))
out.width=
/out.height=
が適用されない{ height=30% }
{ height=30% }
ggplot2
のグラフfig.cap=
でキャプションを設定可能. labs(title = )
と違い自動相互参照ありtheme_set( theme_classic(base_size = 11) + theme(legend.position = "top", axis.title.y = element_text(angle = 90, vjust = .5), legend.title = element_blank()))
data(iris) g <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) + geom_point() + labs(x = "萼長", y = "萼幅") g
ggplot2
は aanotate()
のみmm単位cairo_pdf()
のpointsize
はビルトインデバイスにのみ影響fig.width
/fig.height
は保存時のサイズout.width
/out.height
は表示するサイズggsave()
は 9.11 x 5.77 in で保存out.width="100%"
はスライドサイズではなく本文領域の相対サイズ
````r
g + labs(title = "Iris") + theme_classic(base_size =11) + theme(axis.text = element_text(size = 11))## 図の挿入: beamerサイズで保存, 幅100%で出力 * 相対的に文字が大きくなった ````r g + labs(title = "Iris") + theme_classic(base_size =11) + theme(axis.text = element_text(size = 11))
theme_*()
でbase_size
をbeamerの文字サイズと同じにするfig.width=
を調整するtheme_*()
の文字サイズのみ手動で書くtheme_set(base_size = )
で統一すると楽ggplot2
の本来の使い方ではないggdag
はネットワーク図に使えるggforce
はベン図の描画に応用可能diag_yjseir <- dagify( Y ~ E, J ~ E, S ~ Y, E ~ S, I ~ E + Y, R ~ J + I, labels = c("Y" = "懐疑", "J" = "間接接触", "S" = "感受性", "E" = "潜伏", "I" = "感染", "R" = "回復"), coords = list(x = c(Y = 1.5, J = 2, S = 0, E = 1, I = 2, R =3), y = c(Y = .5, J = -.5, S = 0, E = 0, I = 0, R = 0) ) ) %>% tidy_dagitty() %>% mutate(label_edge = c("beta", NA, NA, "gamma", NA, "lambda", NA, NA, NA)) diag_yjseir %>% ggplot(aes(x = x, y = y, xend = xend, yend = yend)) + geom_dag_node(size = 9 * .pt) + geom_dag_edges(edge_width = 2, arrow_directed = grid::arrow(length = grid::unit(.05, "npc"), type = "closed")) + geom_dag_text(aes(label = label)) + geom_label(aes(x = (x + xend)/2, y = (y + yend)/2, label = label_edge), parse = T, size = 10) + theme_dag_blank() + coord_cartesian(ylim=c(-1, 1))
ggforce::geom_circle()
を利用require(ggforce) df.venn <- data.frame( x = c(-.5, 0, .5), y = c(0, .8, 0), r = c(1, 1, 1), labels = c('コーディング', 'デザイン', 'タイポグラフィ')) ggplot(df.venn, aes(x0 = x, y0 = y, r = r, fill = labels)) + geom_circle(alpha = .3, size = 1, colour = 'grey') + geom_label(aes(x = x, y = y, label = labels)) + annotate("text", x = 0, y = .2, label = "LaTeX", size = 11 / .pt) + coord_fixed() + scale_fill_pander() + theme_void(base_size = 11) + theme(legend.position = "none")
DiagrammeR
でDOT言語で書くDiagrammeR::grViz()
でDOT言語によるグラフィカルモデル描画fig.show="hold"
にすると正しく出力できないgrViz(" digraph boxes_and_circles { # a 'graph' statement graph [overlap = true, fontsize = 15] # several 'node' statements node [shape = box] A; B; C; D; E; F node [shape = circle, fixedsize = true, width = 0.9] // sets as circles 1; 2; 3; 4; 5; 6; 7; 8 # several 'edge' statements A->1 B->2 B->3 B->4 C->A 1->D E->A 2->4 1->5 1->F E->6 4->6 5->7 6->7 3->8 } ")
data(iris) print(head(iris))
kable()
で表示knitr::kable()
やkableExtra
のマニュアルdata(iris) kable(head(iris[, 1:3]), caption="kable()による表示")
\input{tab.tex}
でコピペなしで貼り付け可.tex
ファイルで出力してから読み込むfile.copy(file.path(file_loc, "latex/tab.tex"), "./")
\input{tab.tex}
stargazer
の表示fit1 <- lm(Sepal.Length ~ Petal.Width, data = iris) fit2 <- lm(Sepal.Length ~ Petal.Width + Petal.Length, data = iris) stargazer(fit1, fit2, header = F, type = "latex", digits = 2, digits.extra = 0, align = T, ...
stargazer
の出力結果\scriptsize
fit1 <- lm(Sepal.Length ~ Petal.Width, data = iris) fit2 <- lm(Sepal.Length ~ Petal.Width + Petal.Length, data = iris) stargazer(fit1, fit2, header = F, type = "latex", digits = 2, digits.extra = 0, align = T, omit.table.layout = "n", intercept.bottom = F, keep.stat = c("n", "adj.rsq", "f"), df = F, title = "回帰分析の結果", covariate.labels = c("定数項", "花弁幅", "花弁長"), dep.var.caption = "モデル1", dep.var.labels = "萼長")
\normalsize
\scriptsize
Table: 得点一覧
クラス 科目 平均
------ ----- -----
A 算数 $90$
B 算数 $95$
------ ----- -----
\normalsize
Table: 得点一覧
クラス 科目 平均
A 算数 $90$ B 算数 $95$
[RStudio](https://rstudio.com/)
[@ref]
で番号引用: \citep{ref}
([1]
) に対応@ref
で著者名引用: \citet{ref}
(hogehoge et al.
) に対応[@ref1; @ref1]
で連番引用 [1, 2]
[@R-tidyverse; @R-rmarkdown; @rmarkdown2018; @R-bookdown] [@R-citr; @wickham2016Data; @Okumura2017LaTeX]
[@R-tidyverse; @R-rmarkdown; @rmarkdown2018; @R-bookdown] [@R-citr; @wickham2016Data; @Okumura2017LaTeX]
citr
パッケージを使うと楽Addins
から選択knitr::include_graphics(file.path(file_loc, "img/citr.png"))
RefManageR
パッケージfontspec
で制御beamer
なので main
という名に反してサンセリフが主に使われる*options
というオプションパラメータ指定が可能mainfont: <欧文フォント> mainfontoptions: - Scale=1.1 - Ligatures=TeX sansfont: <欧文サンセリフ体フォント> monofont: <等幅フォント>
*options
があるjmainfont: <和文フォント> jmainfontoptions: <オプション> jsansfont: <和文ゴシックフォント> jmonofont: <和文等幅フォント>
{\jfontspec{Noto Serif CJK JP} Noto}
{=latex}, {\jfontspec{IPAMincho} IPA}
{=latex}, {\jfontspec{Harano Aji Mincho} 原ノ味}
{=latex}, ヒラギノ, 游, モリサワ, 小塚, MS などjfontpreset: noto-otf jfontpresetoptions: - match - deluxe - no-math
Table: 主なプリセット名対照表
|フォント |\XeLaTeX |\LuaLaTeX|
|:--------|---------:|-------------:|
|ヒラギノ |hiragino
|hiragino-pro
|
|MS |ms
|ms
|
|Noto |noto
/noto-jp
|noto-otf
/noto-otc
|
ym-win
, yu-win10
, yu-osx
noto
で OK\textmc
/\textrm
\jfontspec{}
を使う\fontspec{}
luatex-ja
のマニュアルここはいつものフォント.
`\textmc{ここだけ明朝 \textrm{Mincho}}`{=latex}
ここはいつものフォント.\textmc{ ここだけ明朝 \textrm{Mincho}.}
{=latex}
metropolis
テーマはあまりカラーバリエーションがないcode_rownumber
=デフォルトで行番号を付けるかどうかoutput: rmdja::beamer_presentation_ja: fonttheme: professionalfonts code_rownumber: true
default
, tango
, pygments
, kate
, monochrome
, espresso
, zenburn
, haddock
, breezedark
, textmate
output: rmdja::beamer_presentation_ja: highlight: tango
linkcolor
スライド内リンクcitecolor
参考文献リストへのリンクurlcolor
urlリンクlinkcolor: blue citecolor: green urlcolor: red
output: rmdja::beamer_presentation_ja: fig_width: 6.29921 fig_height: 3.54331 aspectratio: 169
natbib
以外で良いならTeXLive不要natbib
jecon.bst
が使えるbiblatex
(+biber
)citeproc
: pandoc-citeproc
の機能csl
ファイルで参考文献リストの体裁指定natbib
パッケージを使用natbib
で「著者(出版年)」表示にしたい場合は以下.output: rmdja::beamer_presentation_ja: citation_package: natbib citation_options: authoryear
.bib
, .bst
は以下にファイルパスを指定する.bst
は TeX側が認識していればフルパス・相対パスである必要なしbibliography: examples.bib biblio-style: jecon
biblio-title
で見出しを変更できるoutput: rmdja::beamer_presentation_ja: figurename: Fig. tablename: Tab. biblio-title: Further Readings
?rmdja::beamer_presentation_ja
{ファイル名}_cache
, {ファイル名}_files
を消すcache = F
rmarkdown
/knitr
と\LaTeX どちらのエラーか確認output file: {ファイル名}.md
と出ればpandoc
までは機能しているpandoc
の変換が意図したものでない可能性はあるlstlisting.sty
より見やすいシンタックスハイライトggplot2
で作らねばという強迫症状 tinytex
とrmarkdown
両方がネック XeLaTeX
とLuaLaTeX
で微妙に文字サイズが違うggplot2
以外で描かれたグラフの対応igraph
みたいなのとか...zxjatype
とulem
の競合と思われるxeCJKnftef
を読み込むとなんか解決した詳細: TeX フォーラム
\LuaLaTeX と \XeLaTeX で文字サイズが変わってしまう
metropolis
特有の仕様jecon.bst
を使いたいbiblatex
ではフォーマットに不満rmarkdown
/tinytex
は日本語書誌情報処理未対応latexmk
を呼び出しtinytex.latexmk.emulation = F
.latexmkrc
設定Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.