Tikz 椭圆格式

Tikz 椭圆格式

我在 Tikz 框中格式化椭圆时遇到了困难。我有点不知道该如何描述这个问题,所以我会让代码自己说话。

我希望它看起来像这样:

\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}

但我希望将它放在我从某个地方的某人那里获取的这个 tikz 迷你页面中。但我担心存在冲突:

\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}%

第一个代码运行得很好,但是当我将它嵌入 tikz minipage 中时,椭圆的行为就大不相同了。我的代码是否存在不兼容问题?我尝试过 和 ,minimum width=?但是minimum height=?在 tikz minipage 中,参数的工作方式不一样。

答案1

我删除了 minipage (我添加了minimum width=.48\linewidth设置主节点的宽度,但我inner sep在第二个 tikzpicture 中设置了(这是椭圆的问题)。我删除了一些选项和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}

在此处输入图片描述

我同意,如果很简单,最好避免使用嵌套的 tikzpicture,但如果您仔细使用这些选项,您可以做到这一点。您需要重置继承的一些选项。关于这些问题有一些疑问。

答案2

这里的问题是,的设置mybox将被内部的节点继承tikzpicture;特别是具有 style 的节点largedigit。一种可能的解决方案(如果嵌套的tikzpictures 是真的需要)是使用盒子来存储内部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}

在此处输入图片描述

也许像下面这样会更好?使用此新版本,无需使用嵌套的tikzpictures。该\myframe命令有三个参数:

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

<options>可用于向节点传递附加选项;<name>是用于引用当前帧的字符串,<title>是将作为帧标题放置的字符串。通过设置 的值text width,现在也不需要minipage(因为阿兰·马特斯在评论中指出):

\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}

在此处输入图片描述

与问题没有直接关系,但我也将旧的改为了\tikzstyle现在的\tikzset

相关内容