Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am having difficulty formatting an ellipse within a Tikz box. I am a little bit of a loss on how to describe the issue, so I will let the code speak for itself.

I want it to look like this:

\documentclass[11pt, oneside]{article}  
\usepackage{pgf,tikz}
\usetikzlibrary{shapes,snakes,backgrounds,arrows}   
\begin{tikzpicture}[line width=1pt,line cap=round,line join=round,x=1.0cm,y=1.0cm]%
\tikzstyle{number}=[text=black,font=\Large]%
\tikzstyle{largedigit}=[draw=blue,ellipse,minimum height=20pt,minimum width=50pt]%
\clip (0,-1) rectangle  (5,1);%
% Expression%
\node      [number]      at     (1.85,0.5)      {$5$};%
\node                    at     (2.35,0.5)      {$+$};%
\draw node [largedigit]  at     (2.5,0.5)       {};%
\node      [number]      at     (3,0.5)         {$81$};%
\end{tikzpicture}
\end{document}

But I would like to have it within this tikz minipage that I scalped from somebody somewhere. But I fear there is a conflict:

\documentclass[11pt, oneside]{article} 
\usepackage{pgf,tikz}
\usetikzlibrary{shapes,snakes,backgrounds,arrows}   

\tikzstyle{fancytitle} =[right=8pt,fill=black, text=white, ellipse]%
\tikzstyle{mybox} = [draw=black,fill=white,thick,rectangle, inner sep=10pt, inner     ysep=14pt,minimum height=2.5in]%
\begin{tikzpicture}[transform shape]%
\node [mybox] (box) {%
\begin{minipage}{.48\linewidth}%
{% 
\begin{tikzpicture}[line width=1pt,line cap=round,line join=round,x=1.0cm,y=1.0cm]%
\tikzstyle{number}=[text=black,font=\Large]%
\tikzstyle{largedigit}=[draw=blue,ellipse,minimum height=20pt,minimum width=50pt]
\clip       (0,-1) rectangle    (5,1.5);
% Expression
\node   [number]       at   (1.85,0.5)          {$5$};
\node                  at   (2.35,0.5)          {$+$};
\draw node  [largedigit]   at   (2.5,0.5)           {};
\node   [number]       at       (3,0.5)         {$81$};
\end{tikzpicture}
}%
\end{minipage}%
};%
\node[fancytitle] at (box.north west) {Step 4: ``A'' \& ``S''};%
\end{tikzpicture}%

The first code works just great, but as soon as I inbed it within the tikz minipage, the ellipse acts very differently. Is there some incompatibility with my code? I have messed with minimum width=? and minimum height=? but from within the tikz minipage the parameters don't work the same.

share|improve this question
    
The problem here is that the settings for mybox will be inherited by the nodes in the inner tikzpicture; in particular, by the one with largedigit style. Why do you need a tikzpicture nested inside another one? –  Gonzalo Medina Apr 19 '13 at 2:24
    
All styles, settings and options you declare outside of the node that contains the inner TikZ picture are inheritted by that inner TikZ picture. There is probably somewhere a conflict (which can resolved by giving the conflicting option/key/style to the inner contents). I suggest to save the inner TikZ picture in a box (\newsavebox\myBox\sbox\myBox{\begin{minipage} … \end{minipage}}) and use this box in the node: \node[mybox](box){\usebox\myBox};. –  Qrrbrbirlbel Apr 19 '13 at 2:24
    
@Qrrbrbirlbel I see that we were doing the same thing! –  Gonzalo Medina Apr 19 '13 at 2:30
    
@Qrrbrbirlbel First, I don't have too much experience with Latex. Regarding why, I am essentially typesetting a test prep booklet for students and I am looking to create boxes of text that are decorative. I really only need the labeled border for my purposes, which seem to be met by the answer below. –  Calhistorian Apr 19 '13 at 2:34
    
Oops, replied to wrong individual. –  Calhistorian Apr 19 '13 at 2:35

2 Answers 2

up vote 4 down vote accepted

I removed the minipage (I added minimum width=.48\linewidth to set the width of the main node but I set inner sep in the second tikzpicture (this is the problem for the ellipse). I removed some options and the load of pgf.

\documentclass[11pt, oneside]{article} 
\usepackage{tikz}
\usetikzlibrary{shapes,snakes,backgrounds,arrows}   

\tikzstyle{fancytitle} =[right=8pt,fill=black, text=white, ellipse]%
\tikzstyle{mybox} = [draw=black,fill=white,thick,rectangle, inner sep=10pt, inner  ysep=14pt,minimum height=2.5in,
minimum width=.48\linewidth]%
\begin{document}


    \begin{tikzpicture}
    \node [mybox] (box) {%
    \begin{tikzpicture}[line width=1pt,line cap=round,line join=round]%
    \tikzstyle{number}=[text=black,font=\Large]%
    \tikzstyle{largedigit}=[draw=blue,ellipse,minimum height=20pt,minimum width=50pt,inner sep=2pt]
  %  \clip       (0,-1) rectangle    (5,1.5);
    % Expression
    \node   [number]       at   (1.85,0.5)          {$5$};
    \node                  at   (2.35,0.5)          {$+$};
    \node   [number]       at   (3,0.5)             {$81$};
    \node  [largedigit]    at   (2.5,0.5)           {};

    \end{tikzpicture}
    };%
    \node[fancytitle] at (box.north west) {Step 4: ``A'' \& ``S''};%
    \end{tikzpicture}%
\end{document}

enter image description here

I agree that when it's simple it's preferable to avoid the nested tikzpicture but if you used the options carefully you can do it. You need to reset ome options inherited. There are some questions about these problems.

share|improve this answer
    
Thank you for your response. Regarding the inheritance of parameters, I understand that using the ellipse in both the frame title and within the minipage creates a conflict. But does this also pertain to other shapes. For instance, if I used a rectangle for the title and kept the ellipse exclusively for within the minipage, will the inheritance problem remain. –  Calhistorian Apr 25 '13 at 22:04
    
Ok, I answered my own question to @AlainMatthes . Thanks for everybody's help. The answer is yes it does. –  Calhistorian Apr 25 '13 at 22:15

The problem here is that the settings for mybox will be inherited by the nodes in the inner tikzpicture; in particular, by the one with largedigit style. One possible solution (if nested tikzpictures are really needed) is to use a box to store the inner tikzpicture:

\documentclass[11pt, oneside]{article} 
\usepackage{pgf,tikz}
\usetikzlibrary{shapes,snakes,backgrounds,arrows}   

\tikzset{
fancytitle/.style={right=8pt,fill=black, text=white, ellipse},
mybox/.style= {draw=black,fill=white,thick,rectangle,
  inner xsep=10pt, inner ysep=14pt,minimum height=2.5in},
number/.style={text=black,font=\Large},
largedigit/.style={draw=blue,ellipse,minimum height=20pt,minimum width=50pt}
}

\newsavebox\mybox
\savebox\mybox{\begin{minipage}{.48\linewidth}
{% 
\begin{tikzpicture}[line width=1pt,line cap=round,line join=round,x=1.0cm,y=1.0cm]%
\clip       (0,-1) rectangle    (5,1.5);
% Expression
\node   [number]       at   (1.85,0.5)          {$5$};
\node                  at   (2.35,0.5)          {$+$};
\draw node  [largedigit]   at   (2.5,0.5)           {};
\node   [number]       at       (3,0.5)         {$81$};
\end{tikzpicture}
}%
\end{minipage}%
}
\begin{document}
\begin{tikzpicture}
\node [mybox] (box) {\usebox\mybox};
\node[fancytitle] at (box.north west) {Step 4: ``A'' \& ``S''};%
\end{tikzpicture}

\end{document}

enter image description here

Perhaps something like the following would be better? With this new version there's no need to use nested tikzpictures. The \myframe command has three arguments:

\myframe[<options>]{<name>}{<title>}

<options> can be used to pass additional options to the node; <name> is the string used to reference the current frame, and <title> is the string that will be placed as title of the frame. By setting a value for text width, there's also no need now for a minipage (as Alain Matthes noted in a comment):

\documentclass[11pt, oneside]{article} 
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}   

\tikzset{
fancytitle/.style={right=8pt,fill=black, text=white, ellipse},
mybox/.style= {draw=black,fill=white,thick,rectangle,
  inner xsep=10pt, inner ysep=14pt,minimum height=2.5in,text width=.4\textwidth},
number/.style={text=black,font=\Large},
largedigit/.style={draw=blue,ellipse,minimum height=20pt,minimum width=50pt}
}

\newcommand\myframe[3][]{
  \node[mybox,#1] (#2) {};
  \node[fancytitle] at (#2.north west) {#3};%
}

\begin{document}

\noindent\begin{tikzpicture}[node distance=0pt,outer sep=0pt]
\myframe{box}{Step 4: ``A'' \& ``S''}
\node[largedigit]  at   (box.center)  (ellipse) {};
\node[number] at  (ellipse.center) {$5 + 81$};
\myframe[right=of box]{box1}{Step 5: ``B'' \& ``T''}
\fill[orange] 
  ([xshift=-20pt,yshift=-30pt]box1.center) rectangle
  ([xshift=20pt,yshift=30pt]box1.center);
\myframe[below=of box]{box2}{Step 6: ``C'' \& ``U''}
\fill[green] 
  (box2.center) circle (30pt);
\myframe[right=of box2]{box3}{Step 6: ``C'' \& ``U''}
\node[number] at (box3.center) {$a+b=c$};
\end{tikzpicture}

\end{document}

enter image description here

Not directly related to the question, but I also changed the old \tikzstyle to the current \tikzset.

share|improve this answer
    
You don't need the minipage and you can remove the package pgf –  Alain Matthes Apr 19 '13 at 5:47
    
@AlainMatthes yes, you're right. Thank you! –  Gonzalo Medina Apr 19 '13 at 13:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.