调整 tikz 图片中的标题

调整 tikz 图片中的标题

在下面的代码图片中,我如何垂直调整标题“C”和“D”(实际上,我想将标题“D”稍微下拉一点)。谢谢。

\documentclass[10pt,xcolor={dvipsnames,table}]{beamer}

\mode<article> % only for the article version
{
  \usepackage{fullpage}
  \usepackage{hyperref}
}


\mode<presentation>
{
  %\setbeamertemplate{background canvas}[vertical shading][bottom=red!10,top=blue!10]
  \setbeamercovered{transparent}
  \usefonttheme{serif}
  \usecolortheme{crane}
}

\setbeamercovered{dynamic}

\setbeamertemplate{items}[circle]

\usepackage{tikz}
\usetikzlibrary{tikzmark,positioning,fit,backgrounds,shapes.geometric}

\newcommand\drawnestedsets[4]{
  % initial position
  \def\position{#1}
  % number of sets
  \def\nbsets{#2}
  % list of sets
  \def\listofnestedsets{#3}
  % reversed list of colors
  \def\reversedlistofcolors{#4}

  % position and draw labels of sets
  \coordinate (circle-0) at (#1);
  \coordinate (set-0) at (#1);
  \foreach \set [count=\c] in \listofnestedsets {
    \pgfmathtruncatemacro{\cminusone}{\c - 1}
    % label of current set (below previous nested set)
    \node[below=3pt of circle-\cminusone,inner sep=0]
    (set-\c) {\set};
    % current set (fit current label and previous set)
    \node[circle,inner sep=0,fit=(circle-\cminusone)(set-\c)]
    (circle-\c) {};
  }

  % draw and fill sets in reverse order
  \begin{scope}[on background layer]
    \foreach \col[count=\c] in \reversedlistofcolors {
      \pgfmathtruncatemacro{\invc}{\nbsets-\c}
      \pgfmathtruncatemacro{\invcplusone}{\invc+1}
      \node[circle,draw,fill=\col,inner sep=0,
      fit=(circle-\invc)(set-\invcplusone)] {};
    }
  \end{scope}
}


\begin{document}

\begin{frame}

\begin{tikzpicture}
\drawnestedsets{0,-1}{4}{A,
B,C,D}{blue!50,red!50,yellow!50,orange}
\end{tikzpicture}

\end{frame}

\end{document}

答案1

这是一个替代宏,它只需要最小圆的中心坐标以及形式为 的条目列表<label>/<color>。该宏计算集合的数量,这些集合应从最大到最小列出并将结果存储在 中\numsets,然后计算yshift每个圆的中心和标签位置。最小圆的标签没有移动,因此\b==1?1:0使用条件(如果 b=1 返回 1,否则返回 0)。

在此处输入图片描述

\documentclass[10pt,xcolor={dvipsnames,table}]{beamer}

\mode<article> % only for the article version
{
  \usepackage{fullpage}
  \usepackage{hyperref}
}


\mode<presentation>
{
  %\setbeamertemplate{background canvas}[vertical shading][bottom=red!10,top=blue!10]
  \setbeamercovered{transparent}
  \usefonttheme{serif}
  \usecolortheme{crane}
}

\setbeamercovered{dynamic}

\setbeamertemplate{items}[circle]

\usepackage{tikz}

\newcommand\drawnestedsets[2]{\begin{scope}[scale=.7, transform shape]
    \foreach \n[count=\k] in {#2} {\xdef\numsets{\k}} 
    \foreach \setname/\setcolor[
        count=\c, 
        evaluate=\c as \b using \numsets-\c+1,
        evaluate=\c as \lshift using {-(4*\b-3-(\b==1?1:0))/8}, 
        evaluate=\c as \cshift using -.25*(\b-1)
    ] in {#2}{
        \node[draw, fill=\setcolor, circle, minimum size=\b cm, label={[yshift=\lshift cm]center:\setname}] at ([yshift=\cshift cm]#1){};
    }\end{scope}
}


\begin{document}

\begin{frame}

\begin{tikzpicture}
\drawnestedsets{0,-1}{D/blue!50, C/red!50, B/yellow!50, A/orange}
\end{tikzpicture}

\end{frame}

\end{document}

相关内容