这个问题与这里. 问题在下文中提出。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{mindmap,arrows}
\usepackage{graphicx}
\tikzset{
ld/.style={level distance=#1},lw/.style={line width=#1},
level 1/.style={ld=4.5mm, trunk, lw=1ex ,sibling angle=60},
level 2/.style={ld=3.5mm, trunk!80!leaf a,lw=.8ex,sibling angle=56},
level 3/.style={ld=2.75mm,trunk!60!leaf a,lw=.6ex,sibling angle=52},
level 4/.style={ld=2mm, trunk!40!leaf a,lw=.4ex,sibling angle=48},
level 5/.style={ld=1mm, trunk!20!leaf a,lw=.3ex,sibling angle=44},
level 6/.style={ld=1.75mm,leaf a, lw=.2ex,sibling angle=40},
}
\pgfarrowsdeclare{leaf}{leaf}{
\pgfarrowsleftextend{-2pt} \pgfarrowsrightextend{1pt}
}{
\pgfpathmoveto{\pgfpoint{-2pt}{0pt}}
\pgfpatharc{150}{30}{1.8pt}
\pgfpatharc{-30}{-150}{1.8pt}
\pgfusepathqfill
}
\makeatletter
\def\agobble#1\nil#2{}
\def\mytextcolor@a#1 #2\nil#3{%
\mytextcolor@b#1\nil{#3}
\if\relax\detokenize{#2}\relax\expandafter\agobble\fi
\mytextcolor@a#2\nil{#3}%
}
\def\mytextcolor@b#1#2\nil#3{%
\textcolor{-#3}{\textbf{#1}}\textcolor{#3}{#2}\\
}
\def\mytextcolor#1#2{%
\if\relax\detokenize{#2}\relax\expandafter\agobble\fi
\mytextcolor@a#2 \nil{#1}%
}
\newcommand{\logo}[8]{%
\colorlet{border}{#1}
\colorlet{trunk}{#2}
\colorlet{leaf a}{#3}
\colorlet{leaf b}{#4}
% Question:
% Which tikz feature can I use in place of the following \rotatebox
% to avoid double rotation in the tikzpicture?
% \rotatebox{#8}{%
% One rotation is here:
\begin{tikzpicture}[rotate=#8,font=\scriptsize\scshape]
\draw[border,line width=1ex,yshift=.3cm,
yscale=1.45,xscale=1.05,looseness=1.42]
(1,0) to [out=90, in=0] (0,1) to [out=180,in=90] (-1,0)
to [out=-90,in=-180] (0,-1) to [out=0, in=-90] (1,0) -- cycle;
\coordinate (root) [grow cyclic,rotate=90]
child {
child [line cap=round] foreach \a in {0,1} {
child foreach \b in {0,1} {
child foreach \c in {0,1} {
child foreach \d in {0,1} {
child foreach \leafcolor in {leaf a,leaf b}
{ edge from parent [color=\leafcolor,-#5] }
}
}
}
}
edge from parent [shorten >=-1pt,serif cm-,line cap=butt]
};
% Another rotation here:
\node [rotate=#8,scale=1,align=center,below] at (0pt,-.5ex){%
\mytextcolor{#6}{#7}\\
};
\end{tikzpicture}
% }
}
\makeatother
\begin{document}
\begin{minipage}[c]{\textwidth}
\centering
\logo{green!80!black}{green!25!black!75}{green}{green!80}{leaf}
{border}{Theoretical Computer Science}{45}
\logo{purple!80!black}{purple!25!black!75}{purple}{purple!80}{leaf}
{border}{Theoretical Computer Science}{45}
\end{minipage}
\end{document}
编辑
上面显示了“双重旋转”点。我想为整个图形仅指示一次旋转,因为我的图形包含许多其他节点。
编辑
环境范围不会旋转整个图片。Andrew Stacey 在评论中证实了确实如此。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{mindmap,arrows}
\usepackage{graphicx}
\tikzset{
ld/.style={level distance=#1},lw/.style={line width=#1},
level 1/.style={ld=4.5mm, trunk, lw=1ex ,sibling angle=60},
level 2/.style={ld=3.5mm, trunk!80!leaf a,lw=.8ex,sibling angle=56},
level 3/.style={ld=2.75mm,trunk!60!leaf a,lw=.6ex,sibling angle=52},
level 4/.style={ld=2mm, trunk!40!leaf a,lw=.4ex,sibling angle=48},
level 5/.style={ld=1mm, trunk!20!leaf a,lw=.3ex,sibling angle=44},
level 6/.style={ld=1.75mm,leaf a, lw=.2ex,sibling angle=40},
}
\pgfarrowsdeclare{leaf}{leaf}{
\pgfarrowsleftextend{-2pt} \pgfarrowsrightextend{1pt}
}{
\pgfpathmoveto{\pgfpoint{-2pt}{0pt}}
\pgfpatharc{150}{30}{1.8pt}
\pgfpatharc{-30}{-150}{1.8pt}
\pgfusepathqfill
}
\makeatletter
\def\agobble#1\nil#2{}
\def\mytextcolor@a#1 #2\nil#3{%
\mytextcolor@b#1\nil{#3}
\if\relax\detokenize{#2}\relax\expandafter\agobble\fi
\mytextcolor@a#2\nil{#3}%
}
\def\mytextcolor@b#1#2\nil#3{%
\textcolor{-#3}{\textbf{#1}}\textcolor{#3}{#2}\\
}
\def\mytextcolor#1#2{%
\if\relax\detokenize{#2}\relax\expandafter\agobble\fi
\mytextcolor@a#2 \nil{#1}%
}
\newcommand{\logo}[8]{%
\colorlet{border}{#1}
\colorlet{trunk}{#2}
\colorlet{leaf a}{#3}
\colorlet{leaf b}{#4}
% \rotatebox{#8}{%
\begin{tikzpicture}[font=\scriptsize\scshape]
\begin{scope}[rotate=#8]
\draw[border,line width=1ex,yshift=.3cm,
yscale=1.45,xscale=1.05,looseness=1.42]
(1,0) to [out=90, in=0] (0,1) to [out=180,in=90] (-1,0)
to [out=-90,in=-180] (0,-1) to [out=0, in=-90] (1,0) -- cycle;
\coordinate (root) [grow cyclic,rotate=90]
child {
child [line cap=round] foreach \a in {0,1} {
child foreach \b in {0,1} {
child foreach \c in {0,1} {
child foreach \d in {0,1} {
child foreach \leafcolor in {leaf a,leaf b}
{ edge from parent [color=\leafcolor,-#5] }
}
}
}
}
edge from parent [shorten >=-1pt,serif cm-,line cap=butt]
};
\node [scale=1,align=center,below] at (0pt,-.5ex){%
\mytextcolor{#6}{#7}\\
};
\end{scope}
\end{tikzpicture}
% }
}
\makeatother
\begin{document}
\begin{minipage}[c]{\textwidth}
\centering
\logo{green!80!black}{green!25!black!75}{green}{green!80}{leaf}
{border}{Theoretical Computer Science}{45}
\logo{purple!80!black}{purple!25!black!75}{purple}{purple!80}{leaf}
{border}{Theoretical Computer Science}{45}
\logo{purple!80!black}{purple!25!black!75}{purple}{purple!80}{leaf}
{border}{}{45}
\end{minipage}
\end{document}
答案1
节点形状几乎就像一个独立的 TikZ 图片,在开始绘制节点形状之前,变换矩阵被重置为单位矩阵。以下是几种不同的情况
\begin{tikzpicture}[rotate=45,every node/.style={draw}]
\node (a) {A};
\node (b) at (1,0) {B}; % Location obeys the transform
\node[transform shape] (c) at (-1,0) {C}; % Transformation is passed to the node too
\pgflowlevel{\pgftransformrotate{-45}} % Works directly on the canvas,overrides anything,
% added to the current transformation, and
% the bounding box is not updated.
\node (d) at (1,0) {D};
\end{tikzpicture}
答案2
这个怎么样:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{mindmap,arrows}
\usepackage{graphicx}
\tikzset{
ld/.style={level distance=#1},lw/.style={line width=#1},
level 1/.style={ld=4.5mm, trunk, lw=1ex ,sibling angle=60},
level 2/.style={ld=3.5mm, trunk!80!leaf a,lw=.8ex,sibling angle=56},
level 3/.style={ld=2.75mm,trunk!60!leaf a,lw=.6ex,sibling angle=52},
level 4/.style={ld=2mm, trunk!40!leaf a,lw=.4ex,sibling angle=48},
level 5/.style={ld=1mm, trunk!20!leaf a,lw=.3ex,sibling angle=44},
level 6/.style={ld=1.75mm,leaf a, lw=.2ex,sibling angle=40},
}
\pgfarrowsdeclare{leaf}{leaf}{
\pgfarrowsleftextend{-2pt} \pgfarrowsrightextend{1pt}
}{
\pgfpathmoveto{\pgfpoint{-2pt}{0pt}}
\pgfpatharc{150}{30}{1.8pt}
\pgfpatharc{-30}{-150}{1.8pt}
\pgfusepathqfill
}
\makeatletter
\def\agobble#1\nil#2{}
\def\mytextcolor@a#1 #2\nil#3{%
\mytextcolor@b#1\nil{#3}
\if\relax\detokenize{#2}\relax\expandafter\agobble\fi
\mytextcolor@a#2\nil{#3}%
}
\def\mytextcolor@b#1#2\nil#3{%
\textcolor{-#3}{\textbf{#1}}\textcolor{#3}{#2}\\
}
\def\mytextcolor#1#2{%
\if\relax\detokenize{#2}\relax\expandafter\agobble\fi
\mytextcolor@a#2 \nil{#1}%
}
\newcommand{\logo}[8]{%
\colorlet{border}{#1}
\colorlet{trunk}{#2}
\colorlet{leaf a}{#3}
\colorlet{leaf b}{#4}
% \rotatebox{#8}{%
% \begin{tikzpicture}[font=\scriptsize\scshape]
\begin{scope}[shift={(#8)}]
\draw[border,line width=1ex,yshift=.3cm,
yscale=1.45,xscale=1.05,looseness=1.42]
(1,0) to [out=90, in=0] (0,1) to [out=180,in=90] (-1,0)
to [out=-90,in=-180] (0,-1) to [out=0, in=-90] (1,0) -- cycle;
\coordinate (root) [grow cyclic,rotate=90]
child {
child [line cap=round] foreach \a in {0,1} {
child foreach \b in {0,1} {
child foreach \c in {0,1} {
child foreach \d in {0,1} {
child foreach \leafcolor in {leaf a,leaf b}
{ edge from parent [color=\leafcolor,-#5] }
}
}
}
}
edge from parent [shorten >=-1pt,serif cm-,line cap=butt]
};
\node [scale=1,align=center,below,transform shape] at (0pt,-.5ex){%
\mytextcolor{#6}{#7}\\
};
\end{scope}
% \end{tikzpicture}
% }
}
\makeatother
\begin{document}
\begin{minipage}[c]{\textwidth}
\centering
\begin{tikzpicture}[font=\scriptsize\scshape,rotate=45]
\logo{green!80!black}{green!25!black!75}{green}{green!80}{leaf}
{border}{Theoretical Computer Science}{0,0}
\logo{purple!80!black}{purple!25!black!75}{purple}{purple!80}{leaf}
{border}{Theoretical Computer Science}{3,0}
\logo{purple!80!black}{purple!25!black!75}{purple}{purple!80}{leaf}
{border}{}{6,0}
\end{tikzpicture}
\end{minipage}
\end{document}
- 我从命令中删除了
\begin{tikzpicture}
and ,所以现在你不能再在环境之外使用它了\end{tikzpicture}
\logo
tikzpicture
- 我将参数重新定义
#8
为平移而不是旋转 - 现在,旋转已添加到
tikzpicture
封闭的所有\logo
命令中 - 节点文本也需要
transform shape
旋转