This repository has been archived by the owner on Feb 15, 2022. It is now read-only.
/
USGSstyle.Rnw
340 lines (256 loc) · 8.78 KB
/
USGSstyle.Rnw
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
%\VignetteIndexEntry{Introduction to the EGRET package}
%\VignetteEngine{knitr::knitr}
%\VignetteDepends{}
%\VignetteSuggests{xtable, dataRetrieval,extrafont}
%\VignetteImports{methods,survival, fields}
%\VignettePackage{EGRET}
\documentclass[a4paper,11pt]{article}
\usepackage{amsmath}
\usepackage{times}
\usepackage{hyperref}
\usepackage[numbers, round]{natbib}
\usepackage[american]{babel}
\usepackage{authblk}
\usepackage{subfig}
\usepackage{placeins}
\usepackage{footnote}
\usepackage{tabularx}
\usepackage{parskip}
\usepackage{threeparttable}
\renewcommand\Affilfont{\itshape\small}
\usepackage{csquotes}
\usepackage{setspace}
\doublespacing
\renewcommand{\topfraction}{0.85}
\renewcommand{\textfraction}{0.1}
\usepackage{graphicx}
\usepackage{mathptmx}% Times Roman font
\usepackage[scaled=.90]{helvet}% Helvetica, served as a model for arial
\usepackage{indentfirst}
\setlength{\parskip}{0pt}
\usepackage{courier}
\usepackage{titlesec}
\usepackage{titletoc}
\titleformat{\section}
{\normalfont\sffamily\bfseries\LARGE}
{\thesection}{0.5em}{}
\titleformat{\subsection}
{\normalfont\sffamily\bfseries\Large}
{\thesubsection}{0.5em}{}
\titleformat{\subsubsection}
{\normalfont\sffamily\large}
{\thesubsubsection}{0.5em}{}
\titlecontents{section}
[2em] % adjust left margin
{\sffamily} % font formatting
{\contentslabel{2.3em}} % section label and offset
{\hspace*{-2.3em}}
{\titlerule*[0.25pc]{.}\contentspage}
\titlecontents{subsection}
[4.6em] % adjust left margin
{\sffamily} % font formatting
{\contentslabel{2.3em}} % section label and offset
{\hspace*{-2.3em}}
{\titlerule*[0.25pc]{.}\contentspage}
\titlecontents{subsubsection}
[6.9em] % adjust left margin
{\sffamily} % font formatting
{\contentslabel{2.3em}} % section label and offset
{\hspace*{-2.3em}}
{\titlerule*[0.25pc]{.}\contentspage}
\titlecontents{table}
[0em] % adjust left margin
{\sffamily} % font formatting
{\textbf{Table}\hspace*{2em} \contentslabel {2em}} % section label and offset
{\hspace*{4em}}
{\titlerule*[0.25pc]{.}\contentspage}
\titlecontents{figure}
[0em] % adjust left margin
{\sffamily} % font formatting
{\textbf{Figure}\hspace*{2em} \contentslabel {2em}} % section label and offset
{\hspace*{4em}}
{\titlerule*[0.25pc]{.}\contentspage}
%Italisize and change font of urls:
\urlstyle{sf}
\renewcommand\UrlFont\itshape
\usepackage{caption}
\captionsetup{
font={sf},
labelfont={bf,sf},
labelsep=period,
justification=justified,
singlelinecheck=false
}
\setlength\parindent{20pt}
\textwidth=6.5in
\textheight=9.2in
\parskip=.3cm
\oddsidemargin=.1in
\evensidemargin=.1in
\headheight=-.3in
%------------------------------------------------------------
% newcommand
%------------------------------------------------------------
\newcommand{\scscst}{\scriptscriptstyle}
\newcommand{\scst}{\scriptstyle}
\newcommand{\Robject}[1]{{\texttt{#1}}}
\newcommand{\Rfunction}[1]{{\texttt{#1}}}
\newcommand{\Rclass}[1]{\textit{#1}}
\newcommand{\Rpackage}[1]{\textit{#1}}
\newcommand{\Rexpression}[1]{\texttt{#1}}
\newcommand{\Rmethod}[1]{{\texttt{#1}}}
\newcommand{\Rfunarg}[1]{{\texttt{#1}}}
\begin{document}
\renewenvironment{knitrout}{\begin{singlespace}}{\end{singlespace}}
\renewcommand*\listfigurename{Figures}
\renewcommand*\listtablename{Tables}
<<openLibrary, echo=FALSE>>=
library(xtable)
options(continue=" ")
options(width=60)
library(knitr)
@
<<include=TRUE ,echo=FALSE,eval=TRUE>>=
opts_chunk$set(highlight=TRUE, tidy=TRUE, keep.space=TRUE, keep.blank.space=FALSE, keep.comment=TRUE, concordance=TRUE,tidy=FALSE,comment="")
knit_hooks$set(inline = function(x) {
if (is.numeric(x)) round(x, 3)})
knit_hooks$set(crop = hook_pdfcrop)
bold.colHeaders <- function(x) {
x <- gsub("\\^(\\d)","$\\^\\1$",x)
x <- gsub("\\%","\\\\%",x)
x <- gsub("\\_"," ",x)
returnX <- paste("\\multicolumn{1}{c}{\\textbf{\\textsf{", x, "}}}", sep = "")
}
addSpace <- function(x) ifelse(x != "1", "[5pt]","")
@
%------------------------------------------------------------
\title{Sample Title}
%------------------------------------------------------------
\author[1]{Laura De Cicco}
\affil[1]{United States Geological Survey}
% \maketitle
\noindent{\huge\textsf{\textbf{Sample Title}}}
\noindent\textsf{By Laura De Cicco}
\newpage
\tableofcontents
\listoffigures
\listoftables
\newpage
%------------------------------------------------------------
\section{Header 1}
%------------------------------------------------------------
Some text. With a url: \url{http://www.cida.usgs.gov}. More text.
%------------------------------------------------------------
\section{Header 2}
%------------------------------------------------------------
Blah blah
<<workflowFlowHistory, echo=TRUE,eval=FALSE, message=FALSE>>=
library(boot)
# Some R code
@
%------------------------------------------------------------
\section{Header 3}
\label{sec:dataframes}
%------------------------------------------------------------
Text blah blah. Here's a table with xtable. Also, has a bit of formatting (in the ft$^3$/s).
<<tableParameterCodes, echo=FALSE,results='asis'>>=
pCode <- c('00060', '00065', '00010','00045','00400')
shortName <- c("Discharge [ft$^3$/s]","Gage height [ft]","Temperature [C]", "Precipitation [in]", "pH")
data.df <- data.frame(pCode, shortName, stringsAsFactors=FALSE)
print(xtable(data.df,
label="tab:params",
caption="Common USGS Parameter Codes"),
caption.placement="top",
size = "\\footnotesize",
latex.environment=NULL,
sanitize.text.function = function(x) {x},
sanitize.colnames.function = bold.colHeaders,
sanitize.rownames.function = addSpace
)
@
%------------------------------------------------------------
\subsection{Subsection 1}
\label{sec:dataframesDaily}
%------------------------------------------------------------
Here's a table without using xtable, table \ref{table:Daily1}).
\begin{table}[!ht]
{\footnotesize
\caption{Daily dataframe}
\label{table:Daily1}
\begin{tabular}{llll}
\hline
\multicolumn{1}{c}{\textbf{\textsf{ColumnName}}} &
\multicolumn{1}{c}{\textbf{\textsf{Type}}} &
\multicolumn{1}{c}{\textbf{\textsf{Description}}} &
\multicolumn{1}{c}{\textbf{\textsf{Units}}} \\
\hline
Date & Date & Date & date \\
[5pt]Q & number & Discharge in m\textsuperscript{3}/s & m\textsuperscript{3}/s \\
[5pt]Qualifier & string & Qualifing code & character \\
[5pt]Q7 & number & 7 day running average of Q & m\textsuperscript{3}/s \\
[5pt]Q30 & number & 30 running average of Q & m\textsuperscript{3}/s \\
\hline
\end{tabular}
}
\end{table}
\FloatBarrier
There's also a table with a footnote.
\begin{table}
{\footnotesize
\begin{threeparttable}[b]
\caption{Sample dataframe}
\label{tab:SampleDataframe}
\begin{tabular}{llll}
\hline
\multicolumn{1}{c}{\textbf{\textsf{ColumnName}}} &
\multicolumn{1}{c}{\textbf{\textsf{Type}}} &
\multicolumn{1}{c}{\textbf{\textsf{Description}}} &
\multicolumn{1}{c}{\textbf{\textsf{Units}}} \\
\hline
Date & Date & Date & date \\
[5pt]CosDY & number & Cosine of DecYear & numeric \\
[5pt]Q \tnote{1} & number & Discharge & m\textsuperscript{3}/s \\
[5pt]LogQ \tnote{1} & number & Natural logarithm of discharge & numeric \\
\hline
\end{tabular}
\begin{tablenotes}
\item[1] Discharge columns are populated from data in the Daily dataframe after calling the \texttt{mergeReport} function.
\end{tablenotes}
\end{threeparttable}
}
\end{table}
\FloatBarrier
%------------------------------------------------------------
\subsection{Subsection 2}
\label{sec:dataframesSample}
%------------------------------------------------------------
\FloatBarrier
%------------------------------------------------------------
\section{Next Section}
\label{sec:flowHistory}
%------------------------------------------------------------
We will walk through an example from Columbia River at The Dalles, OR.
<<flowHistory,echo=TRUE,eval=TRUE,message=FALSE>>=
#Some R stuff
x <- 1
@
\FloatBarrier
%------------------------------------------------------------
\subsection{Plotting Options}
\label{sec:plotOptions}
%------------------------------------------------------------
<<plotSingleandSD, echo=TRUE, fig.cap="Plots of discharge statistics",fig.subcap=c("plot(1:10)","plot(rnorm(10))"),out.width='.5\\linewidth',out.height='.5\\linewidth',fig.show='hold',fig.pos="h">>=
plot(1:10)
plot(rnorm(10))
@
\clearpage
%------------------------------------------------------------
\subsection{Plotting Options}
\label{sec:plotOptionsWQ}
%------------------------------------------------------------
More text
<<plotBoxes, echo=TRUE, fig.cap="Concentration box plots",out.width='.5\\linewidth',out.height='.5\\linewidth',fig.show='hold',fig.pos="h">>=
plot(rnorm(10))
@
\clearpage
\end{document}