The res
class uses its own method for defining \section
and this can't work with titlesec
that assumes the standard method.
\documentclass{res}
\usepackage{lipsum} % just for the example
\makeatletter
\def\section#1{%
\ifx\\\@tabcr
\@stopfield
\else
\@@par
\fi
\begingroup
\everypar={}%
\def\par{\@@par}\def\\{ }%
\addpenalty{\@secpenalty}%
\addvspace{\sectionskip}%
\hbox to \textwidth{\hss\sectionfont #1\hss}%
\addpenalty{-\@secpenalty}%
\endgroup
\ifx\\\@tabcr
\@startline
\else
\vskip-\parskip\fi
\ignorespaces
}
\makeatother
\renewcommand\sectionfont{\large\scshape}
\begin{document}
\section{Test section}
Lala\lipsum[1-2]
\end{document}
With the command line with Sweave
:
Really you need only two steps for a simple document as this my_sweave_file.Rnw
:
\documentclass{article}
\begin{document}
Some text
<<RTest>>=
2+2
@
\end{document}
From the command line is enough:
R CMD Sweave my_sweave_file.Rnw
pdflatex my_sweave_file.tex
Or even only one:
R CMD Sweave --pdf my_sweave_file.Rnw
In case that you have cross-references (\ref
or \cite
commands, table of contents, index, glossaries, etc.) this will not enough, so you must also compile the generated .tex
file with the appropriate tools and rerun pdlatex
as needed. See Tools for automating document compilation if you have some problem with the compilation sequences.
With the command line with knitr
:
A compilation of a simple document could be done with:
Rscript -e "library(knitr); knit('my_sweave_file.Rnw')"
pdflatex my_sweave_file.tex
Obviously, in complex Latex documents, you will need to add some compilation steps as above.
Without the command line
For the sake of completeness, an easy way to compile LateX+R documents is to work with LyX instead of LaTeX directly, loading the Sweave
or Rnw(knitr)
modules, making automatically in both case the "R Noweb" (.Rnw
) to LaTeX exportation, and all the compilation steps of the LaTeX file.
Another possibility is use Rstudio to edit the .Rnw file and just push the PDF icon with the "Compile PDF" label. It is worth mention that you use also here Rmarkdown files (.Rmd extension) that offer the simplified syntax of markdown for text but can be converted as well to a LaTeX PDF. In this in case the compilation icon in changed by a is done by a dropdown menu "Knit" where you can select "Knit to PDF", with an obvious meaning.
Warning: The MWE without R chunk options options can be compiled equally with Sweave
and knit
functions, but there are chunk options specific for each of these functions: Some options cannot be used with knitr
and many knitr
options cannot be used with the older Sweave
, so actually is preferable use knitr
.
Best Answer
As you noted, there are no chapters but sections in an article document class. Therefore, it's funny that you try to redefine a command that does not exist. On the other hand, it is not clear to me what are you trying to do with
\titleformat
, but I guess that you are searching for some like this: