cameronbracken / pgfSweave

Quality graphics and speedy compilation with Sweave
http://r-forge.r-project.org/projects/pgfsweave/
29 stars 6 forks source link

possible to add an option to center the graphics? #5

Closed yihui closed 13 years ago

yihui commented 13 years ago

I might have asked this before, but recently I feel it is important again with the highlight package. I wish there could be an option to control the alignment of the graphics. This could be implemented as a hidden option as well (like the option keep.blank.line), e.g. if isTRUE(getOption('center.graphics')), then wrap the graphics with \begin{center} and \end{center}. This gives us the flexibility to align texts and graphics separately, which is impossible (or at least tedious) in the current Sweave setting.

Finally the output will look like this:

\begin{Schunk}
\begin{Soutput}
[1] "2010-12-23 01:58:08 CST"
\end{Soutput}
\end{Schunk}

\beginpgfgraphicnamed{figure/Rfig-test1}
\begin{center}
\input{figure/Rfig-test1.tikz}
\end{center}
\endpgfgraphicnamed
cameronbracken commented 13 years ago

I agree that there is not currently an elegant solution to this currently. And this has been an annoyance for me as well. I will consider it for an option if I can get it to work. Currently this does not work for me.

Does centering like this even work for you? I cannot use any centering or \hfill{} to get graphic to be centered when they are surrounded by externalization commands. The only thing that works for me is to use \hspace which is a pain. It does work without externalization.

yihui commented 13 years ago

I remember this worked for me (even with externalization). I will double check later.

yihui commented 13 years ago

Sorry, it does not work for me either with externalization, but I have found another solution.

For external = FALSE, just insert the figure in the center environment like:

\begin{center}
\input{figure/Rfig-test1.tikz}
\end{center}

For external = TRUE, an additional minipage environment can help kill the beast:

\begin{center}
\begin{minipage}{\linewidth}
\beginpgfgraphicnamed{newfile1-test2}
\input{newfile1-test2.tikz}
\endpgfgraphicnamed
\end{minipage}
\end{center}
cameronbracken commented 13 years ago

Ok this is good to know, I will put this on my todo list.

yihui commented 13 years ago

I found things were not so complicated as I thought. The reason I failed on the first example seems to be I should put \begin{center} outside of \beginpgfgraphicnamed. I tested with a simple modification on pgfSweaveRuncode and it worked (at least under my Ubuntu).

cameronbracken commented 13 years ago

Fixed.

916336b