我在文档中的几个地方使用 groupplot 插入了几个图,但我只想要一个图例,因为它对所有图例都是通用的。我使用legend to name=foo
,然后在图后,\ref{foo}
整个事情看起来像这样(这不是 MWE)
\begin{figure}
\centering
\begin{tikzpicture}
\begin{groupplot}[
legend columns=-1,
legend entries={{\tiny ++Cost},{\tiny ++FTE},{\tiny ++Resources},{\tiny Hold All},{\tiny Random},{\tiny Come and Go}},
legend to name=CombinedLegendAlpha2,
group style={
group size=3 by 1,
xlabels at=edge bottom,
ylabels at=edge left
},
legend style={draw=none},
legend style={at={(0.98,0.825)}},
xlabel = {\footnotesize $\alpha_{++}$},
ylabel = {\footnotesize Avg Portfolio Value},
]
\nextgroupplot[title={\scriptsize Empirical CDF},
y tick label style={
font=\tiny,
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd
},
footnotesize,
x tick label style={
font=\tiny,
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1,
/tikz/.cd
}]
\addplot+[black, mark=o,line join=round, mark repeat=10] table[col sep=comma, y=PlusPlusCost, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=x,line join=round, mark repeat=10] table[col sep=comma, y=PlusPlusFTE, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=|,line join=round, mark repeat=10] table[col sep=comma, y=PlusPlusResources, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=square,line join=round, mark repeat=10] table[col sep=comma, y=HoldAll, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=star,line join=round, mark repeat=10] table[col sep=comma, y=Random, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=otimes,line join=round, mark repeat=10] table[col sep=comma, y=ComeAndGo, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\nextgroupplot[title={\scriptsize Triangular CDF},
y tick label style={
font=\tiny,
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd
},
footnotesize,
x tick label style={
font=\tiny,
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd
}]
\addplot+[black, mark=o,line join=round, mark repeat=10] table[col sep=comma, y=PlusPlusCostTri, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=x,line join=round, mark repeat=10] table[col sep=comma, y=PlusPlusFTETri, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=|,line join=round, mark repeat=10] table[col sep=comma, y=PlusPlusResourcesTri, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=square,line join=round, mark repeat=10] table[col sep=comma, y=HoldAll, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=star,line join=round, mark repeat=10] table[col sep=comma, y=Random, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=otimes,line join=round, mark repeat=10] table[col sep=comma, y=ComeAndGo, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\nextgroupplot[title={\scriptsize LN/Exponential CDF},
y tick label style={
font=\tiny,
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd
},
footnotesize,
x tick label style={
font=\tiny,
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd
}]
\addplot+[black, mark=o,line join=round, mark repeat=10] table[col sep=comma, y=PlusPlusCostLN, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=x,line join=round, mark repeat=10] table[col sep=comma, y=PlusPlusFTEExpo, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=|,line join=round, mark repeat=10] table[col sep=comma, y=PlusPlusResourcesExpo, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=square,line join=round, mark repeat=10] table[col sep=comma, y=HoldAll, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=star,line join=round, mark repeat=10] table[col sep=comma, y=Random, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\addplot+[black, mark=otimes,line join=round, mark repeat=10] table[col sep=comma, y=ComeAndGo, x=CostAlpha]{PlusPlusMethodsAlpha.csv};
\end{groupplot}
\end{tikzpicture}
\ref{CombinedLegendAlpha2}
\caption{Triage++ Performance}
\label{PlusPlusAlpha}
\end{figure}
这很好用,并产生了我想要的输出。例如,上面的代码产生
但是,当我构建文件时,我收到警告,说我的标签(在本例中为 CombinedLegendAlpha2)被多次定义。我知道这些是警告,而不是错误,但它们仍然困扰着我。有没有更合适的方法来实现这一点?我是一个 Latex 新手,所以如果我的解决方案很黑客,我一点也不会感到惊讶……
答案1
确实你的legend to name
被定义了多次。
无论您输入的\begin{groupplot}[#1]
内容都#1
将被放置在所有轴图上。
正在做:
\begin{groupplot}[/tikz/font=\small,...]
\nextgroupplot
...
\nextgroupplot
...
\end{groupplot}
因此相当于:
\begin{axis}[/tikz/font=\small,...]
...
\end{axis}
\begin{axis}[/tikz/font=\small,at=<below>,...]
...
\end{axis}
\begin{axis}[/tikz/font=\small,at=<below>,...]
...
\end{axis}
或多或少。
无论你投入的groupplot
是全球的。而是移动一次已使用的键进入各自的范围\nextgroupplot[#1]
以限制其扩展。传递给环境的顶部键的groupplot
目的与scope
环境非常相似。