![在 Sweave 输出上涂鸦](https://linux22.com/image/268104/%E5%9C%A8%20Sweave%20%E8%BE%93%E5%87%BA%E4%B8%8A%E6%B6%82%E9%B8%A6.png)
这可能无法做到这一点,但我想知道是否有办法在 LaTeX 输出之上涂鸦,或者在我的情况下在 Sweave 输出之上涂鸦。
参见下面的示例!
\begin{tikzpicture}
\node[right,text width=11.7cm,rounded corners,fill=blue!20,inner sep=1ex]{
\begin{center}
\textbf{EXERCISE \ex}
\end{center}
Let's create a random sample of 10 smaller case letters from the alphabet as follows:
<<>>=
test.letters <- sample(letters,10)
@
\begin{enumerate}
\item Create a factor out of this vector and inspect it.
\item What do you notice when inspecting the given levels of this factor?
\item How can you make sure that the whole alphabet is taken into account in the levels? \end{enumerate}
\vspace{.1in}};
\end{tikzpicture}
这是普通乳胶出口
\batchmode
\makeatletter
\def\input@path{{\string"C:/Documents and Settings/LSDEMMLJ/Desktop/R intro v1.1/\string"/}}
\makeatother
\documentclass[british]{beamer}
\usepackage{mathptmx}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parskip}{\bigskipamount}
\setlength{\parindent}{0pt}
\usepackage{amsmath}
\usepackage{amssymb}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
% this default might be overridden by plain title style
\newcommand\makebeamertitle{\frame{\maketitle}}%
\AtBeginDocument{
\let\origtableofcontents=\tableofcontents
\def\tableofcontents{\@ifnextchar[{\origtableofcontents}{\gobbletableofcontents}}
\def\gobbletableofcontents#1{\origtableofcontents}
}
\def\lyxframeend{} % In case there is a superfluous frame end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{graphicx}
\usepackage{mdwlist}
\usepackage{xr}
\usepackage{units}
\usepackage{fancyhdr}
\usepackage{textcomp}
\usepackage{latexsym}
\usepackage{multicol}
\usepackage{dirtree}
\usepackage{keystroke}
\usepackage{url}
\usepackage{hyperref}
\usetheme{Madrid}
\makeatletter
\defbeamertemplate*{title page}{mytitlepage}[1][]
{
\vbox{}
\vfill
\begin{centering}
\begin{beamercolorbox}[sep=8pt,center,#1]{}
\usebeamerfont{title}\inserttitle\par%
\ifx\insertsubtitle\@empty%
\else%
\vskip0.25em%
{\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}%
\fi%
\end{beamercolorbox}%
\vskip1em\par
\begin{beamercolorbox}[sep=8pt,center,#1]{author}
\usebeamerfont{author}\insertauthor
\end{beamercolorbox}
\begin{beamercolorbox}[sep=8pt,center,#1]{institute}
\usebeamerfont{institute}\insertinstitute
\end{beamercolorbox}
\begin{beamercolorbox}[sep=8pt,center,#1]{date}
\usebeamerfont{date}\insertdate
\end{beamercolorbox}\vskip0.5em
{\usebeamercolor[fg]{titlegraphic}\inserttitlegraphic\par}
\end{centering}
\vfill
}
\makeatother
\title[Intro to R \theframenumber]{An Introduction to the R Statistical Environment}
\author{Joanne Demmler}
\institute[Swansea University]{CIPHER\\ College of Medicine}
\date{5th of June 2013 \\{\tiny Version 1.2}}
\AtBeginPart{%
{% start a group to keep the template change local
\setbeamertemplate{background canvas}{%
\color{blue!20!white!80}\rule{\paperwidth}{\paperheight}%
}%
\frame{\partpage}%
}% end group
}
\hypersetup{pdfpagemode=None}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{decorations.pathreplacing}
\newcounter{bar}
\newcommand{\ex}{%
\stepcounter{bar}%
\thebar}
% add highlighting to text
\usepackage{color}
\newcommand{\hilight}[1]{\colorbox{yellow}{#1}}
\makeatother
\usepackage{babel}
\usepackage{Sweave}
\begin{document}
\begin{frame}[fragile,allowframebreaks]
\frametitle{Vector exercises}
\begin{tikzpicture}
\node[right,text width=11.7cm,rounded corners,fill=blue!20,inner sep=1ex]{
\begin{center}
\textbf{EXERCISE \ex}
\end{center}
Let's create a random sample of 10 smaller case letters from the alphabet as follows:
\begin{Schunk}
\begin{Sinput}
> test.letters <- sample(letters,10)
\end{Sinput}
\end{Schunk}
\begin{enumerate}
\item Create a factor out of this vector and inspect it.
\item What do you notice when inspecting the given levels of this factor?
\item How can you make sure that the whole alphabet is taken into account in the levels?
\end{enumerate}
\vspace{.1in}};
\end{tikzpicture}
\end{frame}
\lyxframeend{}
\end{document}
LYX 示例:
#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass beamer
\begin_preamble
\usepackage{graphicx}
\usepackage{mdwlist}
\usepackage{xr}
\usepackage{units}
\usepackage{fancyhdr}
\usepackage{textcomp}
\usepackage{latexsym}
\usepackage{multicol}
\usepackage{dirtree}
\usepackage{keystroke}
\usepackage{url}
\usepackage{hyperref}
\usetheme{Madrid}
\makeatletter
\defbeamertemplate*{title page}{mytitlepage}[1][]
{
\vbox{}
\vfill
\begin{centering}
\begin{beamercolorbox}[sep=8pt,center,#1]{}
\usebeamerfont{title}\inserttitle\par%
\ifx\insertsubtitle\@empty%
\else%
\vskip0.25em%
{\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}%
\fi%
\end{beamercolorbox}%
\vskip1em\par
\begin{beamercolorbox}[sep=8pt,center,#1]{author}
\usebeamerfont{author}\insertauthor
\end{beamercolorbox}
\begin{beamercolorbox}[sep=8pt,center,#1]{institute}
\usebeamerfont{institute}\insertinstitute
\end{beamercolorbox}
\begin{beamercolorbox}[sep=8pt,center,#1]{date}
\usebeamerfont{date}\insertdate
\end{beamercolorbox}\vskip0.5em
{\usebeamercolor[fg]{titlegraphic}\inserttitlegraphic\par}
\end{centering}
\vfill
}
\makeatother
\title[Intro to R \theframenumber]{An Introduction to the R Statistical Environment}
\author{Joanne Demmler}
\institute[Swansea University]{CIPHER\\ College of Medicine}
\date{5th of June 2013 \\{\tiny Version 1.2}}
\AtBeginPart{%
{% start a group to keep the template change local
\setbeamertemplate{background canvas}{%
\color{blue!20!white!80}\rule{\paperwidth}{\paperheight}%
}%
\frame{\partpage}%
}% end group
}
\hypersetup{pdfpagemode=None}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{decorations.pathreplacing}
\newcounter{bar}
\newcommand{\ex}{%
\stepcounter{bar}%
\thebar}
% add highlighting to text
\usepackage{color}
\newcommand{\hilight}[1]{\colorbox{yellow}{#1}}
\end_preamble
\use_default_options false
\begin_modules
beamer-fragile
sweave
\end_modules
\maintain_unincluded_children false
\language british
\language_package default
\inputencoding auto
\fontencoding global
\font_roman times
\font_sans default
\font_typewriter default
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\default_output_format pdf2
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry true
\use_amsmath 2
\use_esint 1
\use_mhchem 1
\use_mathdots 1
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation skip
\defskip bigskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 3
\html_css_as_file 0
\html_be_strict false
\end_header
\begin_body
\begin_layout Standard
\begin_inset Flex FragileFrameAllowframebreaks
status open
\begin_layout Plain Layout
\begin_inset Flex FragileTitle
status open
\begin_layout Plain Layout
Vector exercises
\end_layout
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset ERT
status open
\begin_layout Plain Layout
\backslash
begin{tikzpicture}
\end_layout
\begin_layout Plain Layout
\backslash
node[right,text width=11.7cm,rounded corners,fill=blue!20,inner sep=1ex]{
\end_layout
\begin_layout Plain Layout
\backslash
begin{center}
\end_layout
\begin_layout Plain Layout
\backslash
textbf{EXERCISE
\backslash
ex}
\end_layout
\begin_layout Plain Layout
\backslash
end{center}
\end_layout
\begin_layout Plain Layout
Let's create a random sample of 10 smaller case letters from the alphabet
as follows:
\end_layout
\begin_layout Plain Layout
<<>>=
\end_layout
\begin_layout Plain Layout
test.letters <- sample(letters,10)
\end_layout
\begin_layout Plain Layout
@
\end_layout
\begin_layout Plain Layout
\backslash
begin{enumerate}
\end_layout
\begin_layout Plain Layout
\backslash
item Create a factor out of this vector and inspect it.
\end_layout
\begin_layout Plain Layout
\backslash
item What do you notice when inspecting the given levels of this factor?
\end_layout
\begin_layout Plain Layout
\backslash
item How can you make sure that the whole alphabet is taken into account
in the levels?
\end_layout
\begin_layout Plain Layout
\backslash
end{enumerate}
\end_layout
\begin_layout Plain Layout
\backslash
vspace{.1in}};
\end_layout
\begin_layout Plain Layout
\backslash
end{tikzpicture}
\end_layout
\end_inset
答案1
您发布的 LyX 文件在这里不起作用,但看起来您的tikzpicture
环境处于 ERT 中。通过添加更多 TikZ 代码,您可以做很多事情,包括图像中的椭圆和文本。这种方法可能有点不切实际,因为您必须尝试多次才能正确获取添加的位置和大小。
首先,您必须命名节点,因此将第一行更改tikzpicture
为
\node (block) [right, ...
该节点现在将被命名为block
,我们可以使用它的角作为坐标,并相对于该角放置东西。在这里,我简单地使用xshift
和yshift
来相对于左下角放置东西。(另一种方法可能是使用与我在 中描述的类似的技术使用矩形覆盖突出显示表格行。
\draw [red,very thick] ([xshift=3.55cm,yshift=3.65cm]block.south west) circle[x radius=.7cm,y radius=.3cm];
\node [red,right] at ([xshift=3.25cm,yshift=4.2cm]block.south west) {random sample and permutations, see \texttt{> ?sample}};
\draw [blue,very thick] ([xshift=4.9cm,yshift=3.65cm]block.south west) circle[x radius=.7cm,y radius=.3cm];
\node [blue,right] at ([xshift=3.9cm,yshift=3cm]block.south west) {26 lower case letters of the Roman alphabet};
这些线画出椭圆(注意和的\draw
不同。正如您可能猜到的,是左下角,是该角右侧 3.25 厘米处和上方 4.2 厘米处的点。x radius
y radius
circle
block.south west
([xshift=3.25cm,yshift=4.2cm]block.south west)
以下是此的完整代码tikzpicture
。我稍微修改了代码,以获得与您的类似的输出(我没有该Sweave
包)。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node (block) [right,text width=11.7cm,rounded corners,fill=blue!20,inner sep=1ex] {
\begin{center}
\textbf{EXERCISE 1}
\end{center}
Let's create a random sample of 10 smaller case letters from the alphabet as follows:
\begin{verbatim}
<<>>=
test.letters <- sample(letters,10)
@
\end{verbatim}
\begin{enumerate}
\item Create a factor out of this vector and inspect it.
\item What do you notice when inspecting the given levels of this factor?
\item How can you make sure that the whole alphabet is taken into account in the levels? \end{enumerate}
\vspace{.1in}};
\draw [red,very thick] ([xshift=3.55cm,yshift=3.65cm]block.south west) circle[x radius=.7cm,y radius=.3cm];
\node [red,right] at ([xshift=3.25cm,yshift=4.2cm]block.south west) {random sample and permutations, see \texttt{> ?sample}};
\draw [blue,very thick] ([xshift=4.9cm,yshift=3.65cm]block.south west) circle[x radius=.7cm,y radius=.3cm];
\node [blue,right] at ([xshift=3.9cm,yshift=3cm]block.south west) {26 lower case letters of the Roman alphabet};
\end{tikzpicture}
\end{document}