メモ:rmarkdown
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン次のリビジョン両方とも次のリビジョン | ||
メモ:rmarkdown [2020/05/12 12:10] – [テーブルなどのラベルを改行する] admin | メモ:rmarkdown [2020/10/05 18:24] – Wiki Editor | ||
---|---|---|---|
行 19: | 行 19: | ||
header-includes: | header-includes: | ||
- \usepackage{amsmath, | - \usepackage{amsmath, | ||
- | - \usepackage{mathspec} | + | |
+ | # 別のパッケージと競合して1ページ目に無駄な文字列が出力されるので無効に | ||
+ | #- \usepackage{mathspec} | ||
+ | | ||
- \usepackage{indentfirst} | - \usepackage{indentfirst} | ||
- \parindent = 1em | - \parindent = 1em | ||
行 25: | 行 28: | ||
- \setmainfont{Century} | - \setmainfont{Century} | ||
- \setsansfont{Century} | - \setsansfont{Century} | ||
- | - \setjamainfont{MS Mincho} | + | - \setjamainfont{IPAexMincho} |
- | - \setjasansfont{MS Gothic} | + | - \setjasansfont{IPAexGothic} |
- \usepackage{float} | - \usepackage{float} | ||
- \setpagelayout * {margin=20mm} | - \setpagelayout * {margin=20mm} | ||
行 34: | 行 37: | ||
- \titlespacing{\section}{0pt}{5pt}{3pt} | - \titlespacing{\section}{0pt}{5pt}{3pt} | ||
- \titlespacing{\subsection}{0pt}{5pt}{3pt} | - \titlespacing{\subsection}{0pt}{5pt}{3pt} | ||
- | - | + | |
+ | | ||
+ | | ||
- \renewcommand{\labelitemi}{■} | - \renewcommand{\labelitemi}{■} | ||
- \renewcommand{\labelitemii}{$\circ$} | - \renewcommand{\labelitemii}{$\circ$} | ||
行 64: | 行 69: | ||
- \@addtoreset{table}{section} | - \@addtoreset{table}{section} | ||
- \makeatother | - \makeatother | ||
+ | | ||
+ | - \usepackage{xcolor} % kableExtraのkable_stylingでlatex_optionsをstripedで表を縞模様にする場合に必要(以前はいらなった) | ||
+ | #- \definecolor{my_color}{rgb}{0.95, | ||
+ | | ||
+ | # ページを横置きにするコマンドを定義:\blandscapeで開始、\elandscapeで戻す | ||
+ | - \usepackage{lscape} | ||
+ | - \newcommand{\blandscape}{\begin{landscape}} | ||
+ | - \newcommand{\elandscape}{\end{landscape}} | ||
+ | | ||
+ | # header、footerのカスタマイズ | ||
+ | # 余白を調整するとそのままでは本文文字にページ番号などが被る場合がある | ||
+ | # fancyhdrパッケージで調整する。複雑なヘッダ、フッタも作成できるが、とりあえず余白との兼ね合いを調整するためだけに読み込み | ||
+ | - \usepackage{fancyhdr} | ||
+ | - \pagestyle{fancy} # ページスタイルを適用 | ||
+ | - \lhead{} # ヘッダ左 | ||
+ | - \chead{} # ヘッダ中央 | ||
+ | - \rhead{} # ヘッダ右・・・いずれも空にする | ||
+ | - \renewcommand{\headrulewidth}{0.0pt} # ヘッダの区切り線を消す | ||
+ | - \cfoot{\thepage} # フッタ中央にページ番号記載 | ||
| | ||
documentclass: | documentclass: | ||
行 95: | 行 119: | ||
# * family には OS にインストールされているフォント名を指定する。 | # * family には OS にインストールされているフォント名を指定する。 | ||
# | # | ||
- | knitr:: | + | knitr:: |
} | } | ||
+ | ``` | ||
図のチャンクオプション | 図のチャンクオプション | ||
行 224: | 行 249: | ||
) | ) | ||
+ | ===== 図のテキスト回り込み ===== | ||
+ | |||
+ | 例によってRmarkdownからPDFを出力する際の細かい設定は、RmarkdownからLatexを制御しなければならないため、やや複雑になる。他に利用しているパッケージによってはうまく動かないなど、実用レベルではない気もする。とりあえず現状のメモ。 | ||
+ | |||
+ | * [[https:// | ||
+ | |||
+ | まず、Latexでwrapfigを読み込む。 | ||
+ | |||
+ | header-includes: | ||
+ | - \usepackage{wrapfig} | ||
+ | |||
+ | ただし、titlesecパッケージを読み込むとうまく動かない。 | ||
+ | |||
+ | - \usepackage[compact]{titlesec} | ||
+ | |||
+ | |||
+ | bxjsarticleのクラスオプションにeveryparhook=compatを指定しないとうまく動かない。 | ||
+ | |||
+ | documentclass: | ||
+ | classoption: | ||
+ | |||
+ | |||
+ | 次に、Rmarkdownで図を出力する際にLatex側に指定する環境を書き換える(たぶん) | ||
+ | |||
+ | ```{r, include = F} | ||
+ | defOut <- knitr:: | ||
+ | knitr:: | ||
+ | x <- defOut(x, options) | ||
+ | if(!is.null(options$wrapfigure)) { # then, if option wrapfigure is given ... | ||
+ | # create the new opening string for the wrapfigure environment ... | ||
+ | wf <- sprintf(" | ||
+ | x <- gsub(" | ||
+ | x <- gsub(" | ||
+ | } | ||
+ | return(x) | ||
+ | }) | ||
+ | ``` | ||
+ | |||
+ | 図を出力するチャンクでwrapfigureオプションを指定する。ここでは図を右寄せで行幅の70%の大きさに指定している。 | ||
+ | |||
+ | ```{r echo = F, warning = F, message = F, fig.width=7, | ||
+ | plot(mpg ~ hp, data = mtcars) | ||
+ | ``` | ||
+ | |||
+ | ということで、何とか回り込みを設定できるものの、いろいろと問題が多い。素直にRmarkdownから指定できるようになってほしい。 | ||
メモ/rmarkdown.txt · 最終更新: 2023/06/22 11:00 by Wiki Editor