-
Notifications
You must be signed in to change notification settings - Fork 0
/
A-Quarto-Template-Repo-to-Create-Big-Reports-and-Very-Long-Title-Because-Long-Titles-are-Common.tex
1555 lines (1238 loc) · 67.8 KB
/
A-Quarto-Template-Repo-to-Create-Big-Reports-and-Very-Long-Title-Because-Long-Titles-are-Common.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
letterpaper,
oneside]{scrbook}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
% xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\usepackage[a4paper]{geometry}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\setcounter{secnumdepth}{5}
% Make \paragraph and \subparagraph free-standing
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{241,243,245}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.40,0.45,0.13}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\BuiltInTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\ExtensionTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.28,0.35,0.67}{#1}}
\newcommand{\ImportTok}[1]{\textcolor[rgb]{0.00,0.46,0.62}{#1}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\NormalTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\RegionMarkerTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.07,0.07,0.07}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newlength{\cslentryspacingunit} % times entry-spacing
\setlength{\cslentryspacingunit}{\parskip}
\newenvironment{CSLReferences}[2] % #1 hanging-ident, #2 entry spacing
{% don't indent paragraphs
\setlength{\parindent}{0pt}
% turn on hanging indent if param 1 is 1
\ifodd #1
\let\oldpar\par
\def\par{\hangindent=\cslhangindent\oldpar}
\fi
% set entry spacing
\setlength{\parskip}{#2\cslentryspacingunit}
}%
{}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{#1\hfill\break}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
\newcommand*{\plogo}{\fbox{$\mathcal{PL}$}} % Generic dummy publisher logo
\usepackage[utf8]{inputenc} % Required for inputting international characters
\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage{hyphenat}
\usepackage{authblk}
% for nicer tables
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage{xcolor}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{multicol}
\usepackage{hhline}
\newlength\Oldarrayrulewidth
\newlength\Oldtabcolsep
\usepackage{hyperref}
\usepackage{caption}
\makeatletter
\makeatother
\makeatletter
\@ifpackageloaded{bookmark}{}{\usepackage{bookmark}}
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\AtBeginDocument{%
\ifdefined\contentsname
\renewcommand*\contentsname{Table of contents}
\else
\newcommand\contentsname{Table of contents}
\fi
\ifdefined\listfigurename
\renewcommand*\listfigurename{List of Figures}
\else
\newcommand\listfigurename{List of Figures}
\fi
\ifdefined\listtablename
\renewcommand*\listtablename{List of Tables}
\else
\newcommand\listtablename{List of Tables}
\fi
\ifdefined\figurename
\renewcommand*\figurename{Figure}
\else
\newcommand\figurename{Figure}
\fi
\ifdefined\tablename
\renewcommand*\tablename{Table}
\else
\newcommand\tablename{Table}
\fi
}
\@ifpackageloaded{float}{}{\usepackage{float}}
\floatstyle{ruled}
\@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}[chapter]}
\floatname{codelisting}{Listing}
\newcommand*\listoflistings{\listof{codelisting}{List of Listings}}
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\@ifpackageloaded{subcaption}{}{\usepackage{subcaption}}
\makeatother
\makeatletter
\@ifpackageloaded{tcolorbox}{}{\usepackage[skins,breakable]{tcolorbox}}
\makeatother
\makeatletter
\@ifundefined{shadecolor}{\definecolor{shadecolor}{rgb}{.97, .97, .97}}
\makeatother
\makeatletter
\makeatother
\makeatletter
\makeatother
\ifLuaTeX
\usepackage{selnolig} % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same} % disable monospaced font for URLs
\hypersetup{
pdftitle={A Quarto Template Repo to Create Big Reports and Very Long Title Because Long Titles are Common},
pdfauthor={Jane Doe; Eva Nováková; Matti Meikäläinen},
hidelinks,
pdfcreator={LaTeX via pandoc}}
\title{A Quarto Template Repo to Create Big Reports and Very Long Title
Because Long Titles are Common}
\usepackage{etoolbox}
\makeatletter
\providecommand{\subtitle}[1]{% add subtitle to \maketitle
\apptocmd{\@title}{\par {\large #1 \par}}{}{}
}
\makeatother
\subtitle{Some tips on creating reports with Quarto with a focus on
tables and replicated tables and figures}
\author{Jane Doe \and Eva Nováková \and Matti Meikäläinen}
\date{}
\begin{document}
\begin{frontmatter}
\raggedleft % Right align the title page
\rule{1pt}{\textheight} % Vertical line
\hspace{0.05\textwidth} % Whitespace between the vertical line and title page text
\parbox[b]{0.85\textwidth}{ % Paragraph box for holding the title page text, adjust the width to move the title page left or right on the page
{\large\bfseries\nohyphens{A Quarto Template Repo to Create Big Reports
and Very Long Title Because Long Titles are
Common}}\\[2\baselineskip] % Title
{\large\textit{Some tips on creating reports with Quarto with a focus on
tables and replicated tables and
figures}}\\[4\baselineskip] % Subtitle or further description
{\large{Jane Doe}},
{\large{Eva Nováková}} {and \large{Matti Meikäläinen}}
\vspace{0.5\textheight} % Whitespace between the title block and the publisher
{\noindent The Publisher~~\plogo}\\[\baselineskip] % Publisher and logo
}
\end{frontmatter}\ifdefined\Shaded\renewenvironment{Shaded}{\begin{tcolorbox}[interior hidden, borderline west={3pt}{0pt}{shadecolor}, sharp corners, frame hidden, breakable, boxrule=0pt, enhanced]}{\end{tcolorbox}}\fi
\renewcommand*\contentsname{Table of contents}
{
\setcounter{tocdepth}{2}
\tableofcontents
}
\listoffigures
\listoftables
\mainmatter
\bookmarksetup{startatroot}
\hypertarget{open-issues}{%
\chapter{Open Issues}\label{open-issues}}
\hypertarget{april-26-2023-update}{%
\section{April 26, 2023 update}\label{april-26-2023-update}}
\begin{itemize}
\tightlist
\item
Everything broken in the Aug 13, 2022 update is still broken.
\item
flextable cross-refs and captions are still not working in Word output
\item
The flextable 0.9.1 CRAN release broke PDF output in Quarto books.
Known problem and fixed in the development version on GitHub (0.9.2)
\texttt{devtools::install\_github("davidgohel/flextable")}
\item
gt (v0.9.0) cross-refs still broken in Word
\end{itemize}
\hypertarget{aug-13-2022-update}{%
\section{Aug 13, 2022 update}\label{aug-13-2022-update}}
I have mostly figured out workarounds for the table package issues. The
remaining big issues are
\begin{itemize}
\tightlist
\item
For HTML, if you have two chapters (h1 level) in a single qmd it
totally messes up the TOC. Word and PDF converters seem to figure it
out ok and number things correctly.
\begin{itemize}
\tightlist
\item
I posted an issue
https://github.com/quarto-dev/quarto-cli/issues/1712
\item
This is important because we often don't know how many appendix
chapters we will need. These are dynamically created based on the
data. There is no good way to know this ahead of time. These report
templates are used across very different regions and each region has
a different number of appendices based on the number of, say,
species or cities or whatever, in the region.
\end{itemize}
\item
When I have appendices so \texttt{appendices:} in my YAML, the HTML
TOC is messed up.
\begin{itemize}
\tightlist
\item
see https://rverse-tutorials.github.io/QmdReport/ and look at TOC
\item
why doesn't the HTML figure out that the appendix A title is
CRchum.csv?? Word and PDF figure that out.
\end{itemize}
\item
When I have \texttt{appendices:}, the PDF TOC and levels look right,
but if I click on ``Appendices'' in the TOC, I go to References.
\begin{itemize}
\tightlist
\item
Look here to see what I mean
\href{https://rverse-tutorials.github.io/QmdReport/A-Quarto-Template-Repo-to-Create-Big-Reports-and-Very-Long-Title-Because-Long-Titles-are-Common.pdf}{PDF
version}
\item
I would like to be able to have a \texttt{appendices.qmd} that I
would go to. Maybe I can. I haven't tried.
\end{itemize}
\item
No merge and knit option. :( so no memory across chapters. That is a
``feature'' in many cases but some report writers use memory across
chapters heavily.
\end{itemize}
\hypertarget{aug-11-2022-update}{%
\section{Aug 11, 2022 update}\label{aug-11-2022-update}}
\begin{itemize}
\tightlist
\item
flextable cross-refs don't work in pdf but kableExtra tables work and
look better in some ways. So I use kableExtra for pdf's.
\item
flextable is best for Word but cross-refs are broken. The Quarto dev
team knows about the problem.
\item
The Quarto \{\{include filename\}\} option for including files seems
very limited or I don't know how to use it (most definitely true). The
file has to be in same folder as the qmd that calls it.
\item
The Quarto \{\{include filename\}\} breaks if the thing you call is
calling \texttt{knit\_expand()}. Why? So weird. I might be doing
something wrong.
\item
No merge and knit option. :( no sharing of variables across chapters
\item
Can't have two chapters (h1 level) in a single qmd so can't
dynamically create chapters (one qmd with many h1 levels where that
qmd is created dynamically)
\item
\{gt\} package and PDF table numbering don't mix! Breaks all numbering
after a single \texttt{gt()} call. \emph{Update. Fixed in the new gt
update}
\end{itemize}
\hypertarget{citation}{%
\section*{Citation}\label{citation}}
\addcontentsline{toc}{section}{Citation}
\markright{Citation}
EE Holmes, 2022. Quarto Report Template. Northwest Fisheries Science
Center.
\bookmarksetup{startatroot}
\hypertarget{preface}{%
\chapter{Preface}\label{preface}}
\hypertarget{acknowledgements}{%
\section*{Acknowledgements}\label{acknowledgements}}
\markright{Acknowledgements}
Phasellus non diam posuere, laoreet velit sed, egestas felis. Etiam eget
neque in tellus lacinia tincidunt. Pellentesque scelerisque odio velit,
nec fringilla nibh iaculis non. Aenean sit amet nulla ipsum. Cras felis
lacus, pulvinar ac nisi et, convallis pulvinar turpis. Morbi non nibh
lacus. Morbi vitae lorem massa. Sed ut turpis vel felis posuere commodo
lacinia ac mi. Donec finibus lectus sit amet elit finibus, vitae rhoncus
ligula tincidunt. Phasellus vitae blandit lacus. Integer sed nisl
fermentum, pulvinar mauris in, posuere enim. Proin sit amet semper urna.
Vivamus aliquet rutrum diam ac luctus.
\hypertarget{abstract}{%
\section*{Abstract}\label{abstract}}
\addcontentsline{toc}{section}{Abstract}
\markright{Abstract}
Phasellus non diam posuere, laoreet velit sed, egestas felis. Etiam eget
neque in tellus lacinia tincidunt. Pellentesque scelerisque odio velit,
nec fringilla nibh iaculis non. Aenean sit amet nulla ipsum. Cras felis
lacus, pulvinar ac nisi et, convallis pulvinar turpis. Morbi non nibh
lacus. Morbi vitae lorem massa. Sed ut turpis vel felis posuere commodo
lacinia ac mi. Donec finibus lectus sit amet elit finibus, vitae rhoncus
ligula tincidunt. Phasellus vitae blandit lacus. Integer sed nisl
fermentum, pulvinar mauris in, posuere enim. Proin sit amet semper urna.
Vivamus aliquet rutrum diam ac luctus.
\bookmarksetup{startatroot}
\hypertarget{tips}{%
\chapter{Tips}\label{tips}}
\hypertarget{overview}{%
\section{Overview}\label{overview}}
\begin{figure}
{\centering \includegraphics{text/tips_files/figure-pdf/fig-chinook-1.pdf}
}
\caption{\label{fig-chinook}chapter 1 plot}
\end{figure}
\hypertarget{general-set-up}{%
\section{General set-up}\label{general-set-up}}
\begin{itemize}
\item
Be as modular and simple as you can.
\item
Don't make everyone in your team be the markdown wizard. You only need
one person to build the framework.
\item
Use simple child Rmds so that other team members work only on simple
Rmd/qmd flat files.
\item
Don't put all your tables or figures in one huge file:
\texttt{Table\ xyz.Rmd/qmd}, \texttt{Table\ abc.Rmd/qmd}. Have your
dedicated markdown wizard figure out the automatic numbering.
\item
Copy reports built by others who are doing something similar to you.
TALK within your center or across centers and share work.
\end{itemize}
\hypertarget{tips-1}{%
\section{Tips}\label{tips-1}}
\hypertarget{cross-references}{%
\subsection{Cross-references}\label{cross-references}}
This can be really troublesome unless you use an output that already has
cross-references as part of the design. For R Markdown,
\begin{itemize}
\tightlist
\item
\{bookdown\} outputs for html and PDF
\item
\{officedown\} for Word
\end{itemize}
These output formats give you access to cross-referencing via the
\texttt{\textbackslash{}@ref(xxx:yyy)} format and if you use
\texttt{bookdown::pdf\_book}, this will also work with PDF.
However, Quarto makes cross-references, auto-numbering and
cross-referencing of tables and figures super easy.
\href{https://quarto.org/docs/authoring/cross-references.html}{Quarto
cross-ref page}.
For example, we can make a figure with the chunk label \texttt{fig-plot}
like so.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{\textasciigrave{}\textasciigrave{}\textasciigrave{}\{r\}}
\NormalTok{\#| label: fig{-}plot}
\NormalTok{\#| fig{-}cap: "Plot"}
\NormalTok{plot(cars)}
\NormalTok{\textasciigrave{}\textasciigrave{}\textasciigrave{}}
\end{Highlighting}
\end{Shaded}
The later in the text we use \texttt{@fig-plot} to get
Figure~\ref{fig-plot}.
\begin{figure}
{\centering \includegraphics{text/tips_files/figure-pdf/fig-plot-1.pdf}
}
\caption{\label{fig-plot}This is a plot of some data}
\end{figure}
\hypertarget{chunk-labels}{%
\subsection{Chunk labels}\label{chunk-labels}}
\begin{itemize}
\tightlist
\item
When using R Markdown (or Quarto), it is best not to use chunk labels
in the your Rmd/qmd children. It's too easy to get duplicate labels
accidentally.
\end{itemize}
\hypertarget{file-paths}{%
\subsection{File paths}\label{file-paths}}
\begin{itemize}
\tightlist
\item
if you need to reference a file in a folder, let R create the path so
that it is compatible across systems:
\end{itemize}
\begin{verbatim}
file.path('figures', 'figure1.Rmd')
\end{verbatim}
\begin{itemize}
\tightlist
\item
I typically use the \{here\} package so that my code doesn't break if
I happen to issue a change workspace directory command.
\end{itemize}
\begin{verbatim}
here::here('images', 'logo.png')
\end{verbatim}
\hypertarget{tables-in-for-loops}{%
\subsection{Tables in for loops}\label{tables-in-for-loops}}
Making tables within \texttt{for} loops is tricky and it is different if
you are outputting to Word versus html and also depends on what package
that you use. See my Rmd/qmd files in the tables folder for examples of
how to set it up, but also be prepared for things breaking in the future
as package writers change things. This feature is really fluid. Web
searches on stackoverflow are key for solving these problems.
\hypertarget{working-with-word}{%
\section{Working with Word}\label{working-with-word}}
For many of us, Word is part of our team's workflow. Here are some tips
if that is the case for you:
\begin{itemize}
\tightlist
\item
Check out the
\href{https://ardata-fr.github.io/officeverse/index.html}{officeverse}:
\href{https://CRAN.R-project.org/package=officedown}{officedown} and
\href{https://CRAN.R-project.org/package=flextable}{flextable} R
packages.
\item
Quarto has greatly
\href{https://quarto.org/docs/output-formats/ms-word.html}{improved
Word} integration so many of the problems we faced with Word output
may soon be solved.
\item
Don't build the whole report in one file. Work on individual text
sections and then have RStudio (via pandoc/knitr) assemble the report
(text, figures, tables) from the individual parts.
\item
How to deal with the team needing to review the assembled document
(text, figures, tables):
\begin{itemize}
\tightlist
\item
Try to modularize. So maybe make individual chapters and have review
happen at that level. Then you incorporate the changes into the
plain text manually.
\item
Use templates to make your Word doc look the way you want. The
default Word template is bare bones. See my example and read about
using Word templates with Quartro
\href{https://quarto.org/docs/output-formats/ms-word-templates.html}{here}
and R Markdown
\href{https://bookdown.org/yihui/rmarkdown-cookbook/word-template.html}{here}
.
\end{itemize}
\end{itemize}
\hypertarget{making-tables-look-nice-in-word}{%
\subsection{Making tables look nice in
Word}\label{making-tables-look-nice-in-word}}
The example in \texttt{Table\_Counts.Rmd} and
\texttt{Table\_Counts\_flex.Rmd} shows you tricks to make nice Word
tables.
\begin{itemize}
\tightlist
\item
how to include a page break in your Word doc between tables.
\item
using \texttt{format="pandoc"} for the table
\item
using \texttt{results=\textquotesingle{}asis\textquotesingle{}} and
\texttt{print()} so you can use \texttt{for} loops.
\item
centering your tables is next to impossible with \texttt{kable()}. Use
the \{\href{https://ardata-fr.github.io/flextable-book/}{flextable}\}
package if you need that.
\end{itemize}
\hypertarget{new-pages}{%
\subsection{New pages}\label{new-pages}}
This is how to get a new page in Word. Make sure you are in print view
on the word doc, otherwise you won't see any of the pages.
\begin{verbatim}
```{=openxml}
<w:p><w:r><w:br w:type="page"/></w:r></w:p>
```
\end{verbatim}
\hypertarget{output-templates-with-quarto}{%
\section{Output templates with
Quarto}\label{output-templates-with-quarto}}
Quarto is working on templates to make output to different formats easy.
Here is an example of journal templates
\href{https://github.com/quarto-journals/}{quarto-journals}.
\hypertarget{weird-quarto-quirks}{%
\section{Weird Quarto quirks}\label{weird-quarto-quirks}}
\begin{itemize}
\tightlist
\item
If you use
\end{itemize}
\begin{verbatim}
---
title: MyTitle
---
\end{verbatim}
as your title spec, then you won't get the first header 2 in your pdf.
Use \texttt{\#} instead.
\begin{itemize}
\item
If you have 2 \texttt{\#} levels in a qmd file, you only the first
chapter appearing in the TOC. The others appear weirdly as
sub-chapters.
\item
with flextable, your table captions from knitr yaml disappear if the
table breaks across a page.
\end{itemize}
\bookmarksetup{startatroot}
\hypertarget{tables-intro}{%
\chapter{Tables intro}\label{tables-intro}}
This chapter shows a few simple examples of including tables and getting
cross-referencing to work across formats (HTML, Word, PDF). See
Chapter~\ref{sec-kableflexgt} for more examples and comparisons of
different table outputs.
In this chapter, I am going to use \{flextable\} for Word and HTML and
\{kabelExtra\} for PDF. See Chapter~\ref{sec-kableflexgt} for a
comparison of \{flextable\}, \{kableExtra\} and \{gt\}. There is a
current problem that Quarto is not processing the cross-references with
\{flextable\} into PDF and Word. But this is a known problem and they
are working on it. \{flextable\} is the only table package that I have
found the tends to work as expected across platforms. The \{officer\}
package uses it so it works well with Word and works well with LaTeX.
*Note, I am using some customized functions to be able have a uniform
look for my tables. These are in \texttt{tables/\_common.R}.
\hypertarget{example-table}{%
\section{Example table}\label{example-table}}
This is an example a table. We can reference Table~\ref{tbl-example}
(note this is broken in Word output) easily and it is auto-numbered.
\hypertarget{tbl-example}{}
\begin{table}
\caption{\label{tbl-example}This is a simple table. }\tabularnewline
\centering
\begin{tabular}[t]{lrrrrrr}
\toprule
& mpg & cyl & disp & hp & drat & wt\\
\midrule
Mazda RX4 & 21.0 & 6 & 160.0 & 110 & 3.90 & 2.620\\
Mazda RX4 Wag & 21.0 & 6 & 160.0 & 110 & 3.90 & 2.875\\
Datsun 710 & 22.8 & 4 & 108.0 & 93 & 3.85 & 2.320\\
Hornet 4 Drive & 21.4 & 6 & 258.0 & 110 & 3.08 & 3.215\\
Hornet Sportabout & 18.7 & 8 & 360.0 & 175 & 3.15 & 3.440\\
\addlinespace
Valiant & 18.1 & 6 & 225.0 & 105 & 2.76 & 3.460\\
Duster 360 & 14.3 & 8 & 360.0 & 245 & 3.21 & 3.570\\
Merc 240D & 24.4 & 4 & 146.7 & 62 & 3.69 & 3.190\\
Merc 230 & 22.8 & 4 & 140.8 & 95 & 3.92 & 3.150\\
Merc 280 & 19.2 & 6 & 167.6 & 123 & 3.92 & 3.440\\
\bottomrule
\multicolumn{7}{l}{\rule{0pt}{1em}\textit{Note: }}\\
\multicolumn{7}{l}{\rule{0pt}{1em}kable}\\
\end{tabular}
\end{table}
\hypertarget{including-table-files}{%
\section{Including table files}\label{including-table-files}}
It is often good to have your files in separate files so that when you
edit your tables, you only have to work on the table code.
\begin{Shaded}
\begin{Highlighting}[]
\InformationTok{\textasciigrave{}\textasciigrave{}\textasciigrave{}\{r child=here::here("tables", "Table\_flex.Rmd")\}}
\InformationTok{\textasciigrave{}\textasciigrave{}\textasciigrave{}}
\end{Highlighting}
\end{Shaded}
\hypertarget{tbl-flexchild}{}
\global\setlength{\Oldarrayrulewidth}{\arrayrulewidth}
\global\setlength{\Oldtabcolsep}{\tabcolsep}
\setlength{\tabcolsep}{0pt}
\renewcommand*{\arraystretch}{1.5}
\providecommand{\ascline}[3]{\noalign{\global\arrayrulewidth #1}\arrayrulecolor[HTML]{#2}\cline{#3}}
\begin{longtable}[c]{|p{1.34in}|p{0.45in}|p{0.96in}|p{0.95in}|p{1.07in}}
\caption{\label{tbl-flexchild}This table is created in \texttt{Table\_flex.Rmd}. flextable. } \\
\multicolumn{1}{>{\raggedright}m{\dimexpr 1.34in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{11}{11}\selectfont{\textbf{}}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.45in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{11}{11}\selectfont{\textbf{Df}}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.96in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{11}{11}\selectfont{\textbf{Deviance}}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.95in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{11}{11}\selectfont{\textbf{Resid.\ Df}}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 1.07in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{11}{11}\selectfont{\textbf{Resid.\ Dev}}}} \\
\endhead
\multicolumn{1}{>{\raggedright}m{\dimexpr 1.34in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{\textbf{NULL}}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.45in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.96in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.95in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{99}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 1.07in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{129.5}}} \\
\ascline{1pt}{000000}{1-5}
\multicolumn{1}{>{\raggedright}m{\dimexpr 1.34in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{\textbf{ethnicty}}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.45in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{3}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.96in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{47.2}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.95in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{96}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 1.07in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{82.2}}} \\
\multicolumn{1}{>{\raggedright}m{\dimexpr 1.34in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{\textbf{grade}}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.45in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{1}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.96in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{1.7}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.95in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{95}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 1.07in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{80.5}}} \\
\multicolumn{1}{>{\raggedright}m{\dimexpr 1.34in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{\textbf{ethnicty:grade}}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.45in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{3}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.96in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{7.2}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 0.95in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{92}}} & \multicolumn{1}{>{\raggedleft}m{\dimexpr 1.07in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{12}{12}\selectfont{73.3}}} \\
\end{longtable}
\arrayrulecolor[HTML]{000000}
\global\setlength{\arrayrulewidth}{\Oldarrayrulewidth}
\global\setlength{\tabcolsep}{\Oldtabcolsep}
\renewcommand*{\arraystretch}{1}
We can add a captions to a flextable with \texttt{set\_caption} but then
we won't have access to Quarto's cross-format (Word, HTML, PDF)
cross-referencing engine. We can also use \texttt{tab.cap="caption"} in
the chunk yaml but again we don't get the cross-referencing engine.
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{set\_caption}\NormalTok{(ft, }
\AttributeTok{caption =} \StringTok{"a table caption with set\_caption"}\NormalTok{, }
\AttributeTok{style =} \StringTok{"Table Caption"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\hypertarget{cross-references-1}{%
\section{Cross-references}\label{cross-references-1}}
In Quarto,
\href{https://quarto.org/docs/authoring/cross-references.html\#tables}{table
links} use the table label \texttt{@tbl-tablabel} where
\texttt{tablabel} is the label you put on the table chunk. In the text
it looks like this Table~\ref{tbl-tablabel} (note this is broken in Word
output). The chunk yaml looks like this
\begin{verbatim}
#| label: tbl-tablabel
#| tbl-cap: "my caption"
\end{verbatim}
\hypertarget{tbl-tablabel}{}
\begin{table}
\caption{\label{tbl-tablabel}This is a table with a number. }\tabularnewline
\centering
\begin{tabular}[t]{lrrrrrrrrrrrr}
\toprule
Year & Jan & Feb & Mar & Apr & May & Jun & Jul & Aug & Sep & Oct & Nov & Dec\\
\midrule
1954 & NA & NA & NA & NA & NA & NA & 0 & 2 & 4 & 5 & 4 & 4\\
1955 & 6 & 8 & 11 & 13 & 14 & 16 & 17 & 18 & 18 & 18 & 20 & 21\\
1956 & 23 & 24 & 25 & 27 & 29 & 29 & 29 & 31 & 32 & 32 & 34 & 37\\
1957 & 39 & 39 & 40 & 40 & 43 & 44 & 45 & 44 & 46 & 48 & 49 & 51\\
1958 & 52 & 54 & 55 & 57 & 57 & 58 & 59 & 59 & 60 & 59 & 60 & 62\\
\addlinespace
1959 & 63 & 64 & 65 & 66 & 67 & 67 & 67 & 68 & 69 & 68 & 69 & 70\\
1960 & 71 & 74 & 74 & 74 & 75 & 76 & 76 & 75 & 76 & 78 & 78 & 79\\
1961 & 80 & 80 & 82 & 85 & 85 & 87 & 87 & 89 & 89 & 91 & 95 & 95\\
1962 & 98 & 97 & 98 & 98 & 100 & 101 & 102 & 105 & 104 & 105 & NA & NA\\
\bottomrule
\multicolumn{13}{l}{\rule{0pt}{1em}\textit{Note: }}\\
\multicolumn{13}{l}{\rule{0pt}{1em}kable}\\
\end{tabular}
\end{table}
\hypertarget{dynamic-table-captions}{%
\section{Dynamic table captions}\label{dynamic-table-captions}}
You can create captions dynamically.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{dt }\OtherTok{\textless{}{-}}\NormalTok{ mtcars[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{6}\NormalTok{]}
\NormalTok{tbl\_cap }\OtherTok{\textless{}{-}} \FunctionTok{paste}\NormalTok{(}\StringTok{"This is a dynamically created caption. The length of mtcars is"}\NormalTok{, }\FunctionTok{nrow}\NormalTok{(mtcars), }\StringTok{"rows. Here we show"}\NormalTok{, }\FunctionTok{nrow}\NormalTok{(dt), }\StringTok{"rows."}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
Unfortunately you cannot dynamically create your chunk labels too.
\hypertarget{tbl-test3}{}
\begin{table}
\caption{\label{tbl-test3}This is a dynamically created caption. The length of mtcars is 32 rows.
Here we show 10 rows. }\tabularnewline
\centering
\begin{tabular}[t]{lrrrrrr}
\toprule
& mpg & cyl & disp & hp & drat & wt\\
\midrule
Mazda RX4 & 21.0 & 6 & 160.0 & 110 & 3.90 & 2.620\\
Mazda RX4 Wag & 21.0 & 6 & 160.0 & 110 & 3.90 & 2.875\\
Datsun 710 & 22.8 & 4 & 108.0 & 93 & 3.85 & 2.320\\
Hornet 4 Drive & 21.4 & 6 & 258.0 & 110 & 3.08 & 3.215\\
Hornet Sportabout & 18.7 & 8 & 360.0 & 175 & 3.15 & 3.440\\
\addlinespace
Valiant & 18.1 & 6 & 225.0 & 105 & 2.76 & 3.460\\
Duster 360 & 14.3 & 8 & 360.0 & 245 & 3.21 & 3.570\\
Merc 240D & 24.4 & 4 & 146.7 & 62 & 3.69 & 3.190\\
Merc 230 & 22.8 & 4 & 140.8 & 95 & 3.92 & 3.150\\
Merc 280 & 19.2 & 6 & 167.6 & 123 & 3.92 & 3.440\\
\bottomrule
\multicolumn{7}{l}{\rule{0pt}{1em}\textit{Note: }}\\
\multicolumn{7}{l}{\rule{0pt}{1em}kable}\\
\end{tabular}
\end{table}
\bookmarksetup{startatroot}
\hypertarget{tables-in-a-for-loop}{%
\chapter{Tables in a for loop}\label{tables-in-a-for-loop}}
Outputting tables (or figure) in a for loop works fine in Quarto, but
there is no way to set the table numbers dynamically and get all the
cross-references working in Word, HTML and PDF. We really need that
dynamic numbering and cross-reference feature in a big report.
\hypertarget{example-of-tables-produced-in-a-for-loop}{%
\section{Example of tables produced in a for
loop}\label{example-of-tables-produced-in-a-for-loop}}
Look at the Code (link at top in HTML output) to see the
\texttt{cat(knitr::knit\_print(tab))} trick for getting your tables to
appear.
\begin{table}
\caption{We can set a caption but no way to cross-reference it}
\centering
\begin{tabular}[t]{lrrrr}
\toprule
& mpg & cyl & disp & hp\\
\midrule
Mazda RX4 & 21 & 6 & 160 & 110\\
Mazda RX4 Wag & 21 & 6 & 160 & 110\\
\bottomrule
\multicolumn{5}{l}{\rule{0pt}{1em}\textit{Note: }}\\
\multicolumn{5}{l}{\rule{0pt}{1em}kable}\\
\end{tabular}
\end{table}
\begin{table}
\caption{We can set a caption but no way to cross-reference it}
\centering
\begin{tabular}[t]{lrrrr}
\toprule
& mpg & cyl & disp & hp\\
\midrule
Mazda RX4 & 21 & 6 & 160 & 110\\
Mazda RX4 Wag & 21 & 6 & 160 & 110\\
\bottomrule
\multicolumn{5}{l}{\rule{0pt}{1em}\textit{Note: }}\\
\multicolumn{5}{l}{\rule{0pt}{1em}kable}\\
\end{tabular}
\end{table}
\hypertarget{getting-the-cross-reference-links}{%
\section{Getting the cross-reference
links}\label{getting-the-cross-reference-links}}
We have to use a bit of magic to get our dynamic table numbers and links
using Quarto's cross-referencing. The trick is to use a child Rmd (or
qmd) in a for loop. This trick can be used for figures too but I'll just
show it here with tables. This code inspired from
\href{https://gist.github.com/rmoff/a043676a2f084b81a434}{this gist}.
We use \texttt{knit\_expand()} and make a child Rmd that uses double
curly braces like \texttt{\{\{value.to.match\}\}} in the code. That way
the value at the time this Rmd was embedded can be referenced. Note that
if \texttt{value.to.match} were a string (which it is not in this
example), we would need to add quotes around
\texttt{\{\{value.to.match\}\}} in our code.
With this approach we get our numbered tables and we can reference the
tables usual such as Table~\ref{tbl-cyl8} (note this is broken in Word