Using Tikz picture environment inside the marginfigure environment.

946 views
Skip to first unread message

ofenerci

unread,
Feb 12, 2011, 1:37:54 PM2/12/11
to tufte-latex
Dear All,

I am playing with tikz and want to put the tikz picture inside the
marginfigure environment. My problem is that the tikz picture doesn't
scale itself according to the default values of \linewidth' and the
aspect ratio defined in Tufte-Latex class. I give a random scale
parameter ( say: 2.0) which is not bad but I want it to have same
default values of Tufte-latex's. I wonder which parameter I should use
inside the '\begin{tikzpicture}[scale = ?,width=?]' so that it has
the same width and height of the 'helix.pdf' figure defined in
'\includegraphics[width=\linewidth}{helix}.

Regards,
Ozhan


Here is the minimal working code:

\begin{document}
This is a Figure 1.

\begin{marginfigure}%
\includegraphics[width=\linewidth]{helix}
\caption{This is a margin figure. The helix is defined by
$x = \cos(2\pi z)$, $y = \sin(2\pi z)$, and $z = [0, 2.7]$. The
figure was
drawn using Asymptote (\url{http://asymptote.sf.net/}).}
\label{fig:marginfig}
\end{marginfigure}
This is Figure 2. I want to have the same default values defined in
'\includegraphics[width=\linewidth]{helix}

\begin{marginfigure}%
\begin{tikzpicture}[scale = 2.0]
%Draw thin grdid lines with color 40% gray + 60% white
\draw[step=0.5,thin,gray!40,dashed](-1,-1) grid(1,1);
\draw(-1,-1) rectangle (1,1);
\draw[dashed,semithick] (0,1)node[above]
{L}--(-1,0)node[left]{K}--(0,-1)node[below]{N} ;
\fill (-0.5,0) circle (1.6pt) node[above]{T} (0,0) circle
(1.6pt)node
[above]{O} (0.5,0) circle (1.6pt)node [above]{S};
%\draw (0,-1.8) node {\c{S}ekil I};
\end{tikzpicture}
\caption{This is a fig. 2}
\label{fig:marginfig1}
\end{marginfigure}

\end{document}



Kevin Godby

unread,
Feb 12, 2011, 2:37:15 PM2/12/11
to tufte...@googlegroups.com
Hello, Ozhan.

On Sat, Feb 12, 2011 at 12:37 PM, ofenerci <ofen...@hotmail.com> wrote:
> I am playing with tikz and want to put the tikz picture inside the
> marginfigure environment. My problem is that the tikz picture doesn't
> scale itself according to the default  values of \linewidth' and the
> aspect ratio defined in Tufte-Latex class.  I give a random scale
> parameter ( say: 2.0) which is not bad but I want it to have same
> default values of Tufte-latex's. I wonder which parameter I should use
> inside the  '\begin{tikzpicture}[scale = ?,width=?]'   so that it has
> the same width and height of the 'helix.pdf' figure defined in
> '\includegraphics[width=\linewidth}{helix}.

Let me preface my response by saying that I know a lot less about
TikZ/PGF than I'd like.

The scale factor that you provide the tikzpicture environment affects
the numbers you use within the tikzpicture. So the scaling factor is
entirely up to you.

Here's an example:


\begin{marginfigure}
\parindent=0pt
\parskip=0pt
\begin{center}
\begin{tikzpicture}[scale=\marginparwidth/17in*2.54]%
% spread border
\draw (0.0, 0.0) rectangle (17, -11);
% gutter
\draw (8.5, 0.0) -- (8.5, -11);
% body text blocks
\filldraw[color=gray!30] (1.0, -1.0) rectangle +(4.33333, -8.55555);
\filldraw[color=gray!30] (9.5, -1.0) rectangle +(4.33333, -8.55555);
% sidenotes
\filldraw[color=gray!30] ( 5.66666, -1.0) rectangle
+(\marginparwidth/2.54, -2.0);
\filldraw[color=gray!30] (14.16666, -1.0) rectangle
+(\marginparwidth/2.54, -2.0);
\end{tikzpicture}%
\par\footnotesize Asymmetric page layout
\end{center}
\end{marginfigure}

In this example, I've set the scaling factor to \marginparwidth / 17
in ⋅ 2.54. This means that all the numbers I use to specify
coordinates and lengths within this environment will be in inches.
The entire picture is then scaled down to fit into the
\marginparwidth—that is, the width of the margin note.

To determine the scaling factor you want to use, you'll need to first
decide what units you want to work in within the tikzpicture
environment. Choose whatever units are simplest to draw your image.
Then you can calculate the scaling factor, knowing that the width of
the marginfigure environment is \marginparwidth. (Note that
\linewidth works equally well here and would allow your image to fill
the width of either the margin note area or the text area if you
changed from the marginfigure environment to the figure environment.)

I hope this helps.

--Kevin Godby

ofenerci

unread,
Feb 13, 2011, 8:00:25 AM2/13/11
to tufte-latex

Hello Kevin,

First of all, thanks for the answer.

I was able to figure out my problem by taking into your
consideration.
I thought first that my tikz picture was misaligned off from the left
column of margin.
But this was due to putting a text at the left of the figure
( node[left]{K}). By putting it on the
right (node[right]{K}), it was aligned with other figures on the
margin.

Although the width of the figures are now the same on the margin, the
heights are not.
I wonder how I could fix it.

Maybe I should have never left my old friend Xfig in favor of TikZ to
produce a simple graphs :)

Here is the minimal working code:
-------------------------------
>--------------------------------------------------------------------
\documentclass{tufte-book}
\usepackage{tikz}

\begin{document}
%This is a fig. 1

\begin{marginfigure}
\parindent=0pt
\parskip=0pt
\begin{center}
\begin{tikzpicture}[scale=\marginparwidth/2cm]%
%Draw thin grdid lines with color 40% gray + 60% white
\draw[step=0.5,thin,gray!40,dashed](-1,-1) grid(1,1);
\draw(-1,-1) rectangle (1,1);
\draw[dashed,semithick] (0,1)node[above]
{L}--(-1,0)node[right]{K}--(0,-1)node[below]{N} ;
\fill (-0.5,0) circle (1.6pt) node[above]{T} (0,0) circle
(1.6pt)node
[above]{O} (0.5,0) circle (1.6pt)node [above]{S};
%\draw (0,-1.8) node {\c{S}ekil I};
\end{tikzpicture}%
\caption{This is a fig. 2}
\label{fig:marginfig1}
\end{center}

This is a fig. 2
\end{marginfigure}
\begin{marginfigure}
\parindent=0pt
\parskip=0pt
\begin{center}
\begin{tikzpicture}[scale=\marginparwidth/17in*2.54]%
% spread border
\draw (0.0, 0.0) rectangle (17, -11);
% gutter
\draw (8.5, 0.0) -- (8.5, -11);
% body text blocks
\filldraw[color=gray!30] (1.0, -1.0) rectangle +(4.33333, -8.55555);
\filldraw[color=gray!30] (9.5, -1.0) rectangle +(4.33333, -8.55555);
% sidenotes
\filldraw[color=gray!30] ( 5.66666, -1.0) rectangle
+(\marginparwidth/2.54, -2.0);
\filldraw[color=gray!30] (14.16666, -1.0) rectangle
+(\marginparwidth/2.54, -2.0);
\end{tikzpicture}%
\par\footnotesize Asymmetric page layout
\end{center}
\end{marginfigure}
\end{document}
-----------------------------
<---------------------------------------------------------
On Feb 12, 9:37 pm, Kevin Godby <god...@gmail.com> wrote:
> Hello, Ozhan.
>
Reply all
Reply to author
Forward
0 new messages