我想添加:我的 Keviat 圖的圖例(紅色、藍色和綠色)和圖形標題(帶有圖例)。下面列出了我的 keviat 的程式碼。謝謝
\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[upright]{fourier}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-kiviat,numprint,fullpage}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[label distance=.15cm,rotate=30,scale=0.75]
\tkzKiviatDiagram[radial=3,lattice=7,gap=1,step=1,label space=2]%
{Cover,
Droppings,
Other,
}
\tkzKiviatLine[thick,color=red,fill=red,label=SiteA](0.78,5.59,2.02);label{p4}
\tkzKiviatLine[thick,color=blue,fill=blue](5.92,1.57,3.06);label{p5}
\tkzKiviatLine[thick,color=green,fill=green](2.9,4.6,3.6);label{p6}
\tkzKiviatGrad[suffix=\%,unity=10](0)
\end{tikzpicture}
\end{document}
答案1
這是一種可能性。如果您希望將對象視為浮動對象,則可以使用環境figure
,然後使用標準\caption
命令來提供標題(就像我在第一個範例程式碼中所做的那樣)。如果您不希望圖表浮動,您可以使用整合到 KOMA-Script 類別中的minipage
環境和\captionof
命令來提供標題(就像我在第二個範例程式碼中所做的那樣)。
要設計圖例,您可以在所需位置使用 a\node
和 a ;tabular
當然,您可以根據需要更改設定。
首先,將圖表視為浮動figure
物件:
\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[upright]{fourier}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-kiviat,numprint,fullpage}
\usepackage{pgfplots}
\usetikzlibrary{arrows}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\newcommand\ColorBox[1]{\textcolor{#1}{\rule{2ex}{2ex}}}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[label distance=.15cm,rotate=30,scale=0.75]
\tkzKiviatDiagram[radial=3,lattice=7,gap=1,step=1,label space=2]%
{Cover,
Droppings,
Other,
}
\tkzKiviatLine[thick,color=red,fill=red,label=SiteA](0.78,5.59,2.02);label{p4}
\tkzKiviatLine[thick,color=blue,fill=blue](5.92,1.57,3.06);label{p5}
\tkzKiviatLine[thick,color=green,fill=green](2.9,4.6,3.6);label{p6}
\tkzKiviatGrad[suffix=\%,unity=10](0)
\node[anchor=south west,xshift=-60pt,yshift=40pt] at (current bounding box.south east)
{
\begin{tabular}{@{}lp{3cm}@{}}
\ColorBox{red!50} & red description \\
\ColorBox{green!50} & green description \\
\ColorBox{blue!50} & blue description \\
\end{tabular}
};
\end{tikzpicture}
\caption{A caption for the diagram}
\label{fig:test}
\end{figure}
\end{document}
沒有浮選:
\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[upright]{fourier}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-kiviat,numprint,fullpage}
\usepackage{capt-of}
\usepackage{pgfplots}
\usetikzlibrary{arrows}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\newcommand\ColorBox[1]{\textcolor{#1}{\rule{2ex}{2ex}}}
\begin{document}
\noindent\begin{minipage}{\linewidth}
\centering
\begin{tikzpicture}[label distance=.15cm,rotate=30,scale=0.75]
\tkzKiviatDiagram[radial=3,lattice=7,gap=1,step=1,label space=2]%
{Cover,
Droppings,
Other,
}
\tkzKiviatLine[thick,color=red,fill=red,label=SiteA](0.78,5.59,2.02);label{p4}
\tkzKiviatLine[thick,color=blue,fill=blue](5.92,1.57,3.06);label{p5}
\tkzKiviatLine[thick,color=green,fill=green](2.9,4.6,3.6);label{p6}
\tkzKiviatGrad[suffix=\%,unity=10](0)
\node at (current bounding box.east)
{
\begin{tabular}{@{}ll@{}}
\ColorBox{red} & red description \\
\ColorBox{green} & green description \\
\ColorBox{blue} & blue description \\
\end{tabular}
};
\end{tikzpicture}
\captionof{figure}{A caption for the diagram}
\label{fig:test}
\end{minipage}
\end{document}
在標準類別book
, report
,中,可以透過其中一個套件存取article
該命令\captionof
capt-of
或者caption
。
答案2
使用 PSTricks。
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node}
\usepackage{multido}
\makeatletter
\def\LoadVerbs{\pstVerb{/pt2cm {\strip@pt\psunit\space div} bind def}}
\makeatother
\psset{opacity=0.5,fillstyle=solid}
\def\Atom#1%
{
\multido{\i=1+1}{#1}{\psline[linecolor=gray](\i,0)(0,\i)}
\psline{->}(!#1 12 pt2cm add 0)
}
\def\Molecule#1%
{
\multido{\i=0+90}{4}{\rput{\i}(0,0){\Atom{#1}}}
\multido{\ix=1+1,\i=10+10}{#1}{\rput*{*0}(!\ix\space 6 pt2cm sub -10 pt2cm){\i\%}}
\foreach \a/\t in {0/Right,90/Top,180/Left,270/Bottom}{\pnode(!#1 42 pt2cm add \a\space PtoC){\t}}
}
\def\Label(#1,#2)#3%
{
\psframe[linecolor=#3,fillcolor=#3](#1,#2)(!#1 12 pt2cm add #2 12 pt2cm add)
\rput[l](!#1 18 pt2cm add #2 6 pt2cm add){#3 description}
}
\addtopsstyle{gridstyle}{griddots=0}
\begin{document}
\begin{pspicture}[showgrid=false](-8,-8)(9,8)
\LoadVerbs
\rput{30}(0,0)
{
\Molecule{7}
\pspolygon[linecolor=red,fillcolor=red](0.75,0)(0,6.75)(-2,0)
\pspolygon[linecolor=green,fillcolor=green](3,0)(0,4.75)(-3.75,0)
\pspolygon[linecolor=blue,fillcolor=blue](6,0)(0,1.75)(-3,0)
\foreach \n/\t in {Right/Cover,Top/Droppings,Left/Other}{\rput{*0}(\n){\t}}%! removing white space
}
\foreach \y/\c in {-3/red,-4/green,-5/blue}{\Label(5,\y){\c}}
\end{pspicture}
\end{document}
它是如何製作的?
\documentclass{beamer}
\usepackage{pst-node}
\usepackage{multido}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{pspicture}
\PreviewBorder=12pt
\makeatletter
\def\LoadVerbs{\pstVerb{/pt2cm {\strip@pt\psunit\space div} bind def}}
\makeatother
\psset{opacity=0.5,fillstyle=solid}
\def\Atom#1%
{
\multido{\i=1+1}{#1}{\psline[linecolor=gray](\i,0)(0,\i)}
\psline{->}(!#1 12 pt2cm add 0)
}
\def\Molecule#1%
{
\multido{\i=0+90}{4}{\only<+->{\rput{\i}(0,0){\Atom{#1}}}}
\only<+->{\multido{\ix=1+1,\i=10+10}{#1}{\rput*{*0}(!\ix\space 6 pt2cm sub -10 pt2cm){\i}}}%!
\foreach \a/\t in {0/Right,90/Top,180/Left,270/Bottom}{\pnode(!#1 42 pt2cm add \a\space PtoC){\t}}%!
}
\def\Label(#1,#2)#3%
{
\psframe[linecolor=#3,fillcolor=#3](#1,#2)(!#1 12 pt2cm add #2 12 pt2cm add)
\rput[l](!#1 18 pt2cm add #2 6 pt2cm add){#3 description}
}
\addtopsstyle{gridstyle}{griddots=0}
\begin{document}
\begin{frame}
\begin{pspicture}[showgrid=false](-8,-8)(9,8)
\LoadVerbs
\rput{30}(0,0)
{
\Molecule{7}%!
\only<+->{\pspolygon[linecolor=red,fillcolor=red](0.75,0)(0,6.75)(-2,0)}%!
\only<+->{\pspolygon[linecolor=green,fillcolor=green](3,0)(0,4.75)(-3.75,0)}%!
\only<+->{\pspolygon[linecolor=blue,fillcolor=blue](6,0)(0,1.75)(-3,0)}%!
\foreach \n/\t in {Right/Cover,Top/Droppings,Left/Other}{\only<+->{\rput{*0}(\n){\t}}}%! removing white space
}
\foreach \y/\c in {-3/red,-4/green,-5/blue}{\only<+->{\Label(5,\y){\c}}}
\end{pspicture}
\end{frame}
\end{document}
答案3
使用 tikz 最簡單的方法:
首先,我定義了一個點(LegendBox_anchor),它是圖例框的錨點。然後我用一條線來顯示 tkzKiviatDiagram Line 所使用的顏色。不同的線用(LegendBox_anchor)放置。描述是在行尾添加一個簡單的節點。anchor=west
用於正確對齊描述
\coordinate[xshift=-2cm] (LegendBox_anchor) at (current bounding box.south east) ;
\draw[line width=3mm,color=red] (LegendBox_anchor) -- ++(.5,0) node[anchor=west] {red description};
\draw[line width=3mm,color=blue] ([yshift=8mm]LegendBox_anchor) -- ++(.5,0) node[anchor=west] {blue description};
\draw[line width=3mm,color=green] ([yshift=16mm]LegendBox_anchor) -- ++(.5,0) node[anchor=west] {green description};
可以使用矩形或節點來代替直線。這些節點有幾個優點可以進行一些改進,但我試圖創建一些易於使用的東西。
另一種可能性是在不同的描述周圍定義一個框。如果您稍後添加這種可能性,我可以。
現在,向套件中添加一個巨集來獲取圖例可能會很有趣。這裡我加入了一個簡單的巨集(先嘗試擴充包)
\newcommand{\LegendBox}[3][]{%
\coordinate[#1] (LegendBox_anchor) at (#2) ;
\foreach \col/\item [count=\hi from 0] in {#3} {
\draw[line width=3mm,color=\col] ([yshift=\hi*8mm]LegendBox_anchor) -- ++(.5,0)
node[anchor=west] {\item}
;}
}
它基於第一行。參數 #1 用於在必要時獲得圖例框的更好位置。
\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[upright]{fourier}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-kiviat,numprint,fullpage}
\usepackage{pgfplots}
\usetikzlibrary{arrows}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\newcommand{\LegendBox}[3][]{%
\coordinate[#1] (LegendBox_anchor) at (#2) ;
\foreach \col/\item [count=\hi from 0] in {#3} {
\draw[line width=3mm,color=\col] ([yshift=\hi*8mm]LegendBox_anchor) -- ++(.5,0)
node[anchor=west] {\item}
;}
}
\begin{document}
\begin{tikzpicture}[label distance=.15cm,scale=0.75]
\begin{scope}[rotate=30]
\tkzKiviatDiagram[radial=3,lattice=7,gap=1,step=1,label space=2]%
{Cover,
Droppings,
Other,}
\tkzKiviatLine[thick,color=red,fill=red,label=SiteA](0.78,5.59,2.02)
\tkzKiviatLine[thick,color=blue,fill=blue](5.92,1.57,3.06)
\tkzKiviatLine[thick,color=green,fill=green](2.9,4.6,3.6)
\tkzKiviatGrad[suffix=\%,unity=10](0)
\end{scope}
\LegendBox[xshift=-2cm]{current bounding box.south east}%
{red/red decription,
blue/blue description,
green/green }
\end{tikzpicture}
\end{document}
;
備註:末尾不需要添加\tkzKiviatLine
更新 :
我在圖例周圍添加了一個框,刪除了一些;
我使用的節點而不是線條
\documentclass[]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[upright]{fourier}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tkz-kiviat,numprint,fullpage}
\usepackage{pgfplots}
\usetikzlibrary{arrows,fit}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\newcommand{\LegendBox}[3][]{%
\xdef\fitbox{}%
\coordinate[#1] (LegendBox_anchor) at (#2) ;
\foreach \col/\item [count=\hi from 0] in {#3} {
\node[color = \col,draw,
fill = \col!50,
minimum width = 4 ex,
minimum height = 2 ex,
label={[anchor = left,name=b\hi]right:\item}] at ([yshift=\hi*4 ex]LegendBox_anchor) {};
\xdef\fitbox{\fitbox(b\hi)}
}%
\node [draw,fit=\fitbox(LegendBox_anchor)] {};
}
\begin{document}
\begin{tikzpicture}[label distance=.15cm,scale=0.75]
\begin{scope}[rotate=30]
\tkzKiviatDiagram[radial=3,lattice=7,gap=1,step=1,label space=2]%
{Cover,
Droppings,
Other}
\tkzKiviatLine[thick,color=red,fill=red,label=SiteA](0.78,5.59,2.02)
\tkzKiviatLine[thick,color=blue,fill=blue](5.92,1.57,3.06)
\tkzKiviatLine[thick,color=green,fill=green](2.9,4.6,3.6)
\tkzKiviatGrad[suffix=\%,unity=10](0)
\end{scope}
\LegendBox[shift={(-3cm,3cm)}]{current bounding box.south east}%
{red/red decription,
blue/blue description,
green/green description }
\end{tikzpicture}
\end{document}