![双栏纸张中的图例位置](https://linux22.com/image/427532/%E5%8F%8C%E6%A0%8F%E7%BA%B8%E5%BC%A0%E4%B8%AD%E7%9A%84%E5%9B%BE%E4%BE%8B%E4%BD%8D%E7%BD%AE.png)
如何在多列纸上更改图例位置?我的代码有什么问题吗?我想将图例放在这两个图的顶部中央。
谢谢。
\begin{figure}[t]
\ref{testLegend}
\subfigure[Figure 1]{
\begin{tikzpicture}
\begin{axis}[xlabel={x}, ylabel={y}, width=4cm, ylabel near ticks, xlabel near ticks, y label style={font=\small}, x label style={font=\small}, ymajorgrids, cycle list name=exotic]
\addplot coordinates {(0,0) (1,1)};
\addplot coordinates {(0,0) (1,2)};
\end{axis}
\end{tikzpicture}
\label{fig:a}
}
\vspace{-1em}
\subfigure[Figure 2]{
\begin{tikzpicture}
\begin{axis}
[xlabel={x}, ylabel={y}, width=4cm, ylabel near ticks, xlabel near ticks, y label style={font=\small}, x label style={font=\small}, legend entries={line1, line2}, legend columns=2, legend to name=testLegend, legend style={font=\scriptsize}, legend pos=north east, legend style={font=\small}, ymajorgrids, cycle list name=exotic]
\addplot coordinates {(0,0) (1,1)};
\addplot coordinates {(0,0) (1,2)};
\end{axis}
\end{tikzpicture}
\label{fig:b}
}
\caption{Caption test, \label{fig:c}}
\vspace{-1.5em}
\end{figure}
但是我想要这个结果,
答案1
使用自定义的 edfinedaxis
样式来避免重复,subfig
而不是使用弃用的subfigure
包和单独的tikzpicture
图例:
\documentclass[twocolumn]{article}
\usepackage{pgfplots}
\usepackage{subfig}
\pgfplotsset{
compat=1.17,
my axis style/.style={
xlabel={x},
ylabel={y},
width=4cm,
ylabel near ticks,
xlabel near ticks,
y label style={font=\small},
x label style={font=\small},
ymajorgrids,
cycle list name=exotic
},
}
\usepackage{lipsum} % For dummy text using the \lipsum command. Do not use in actual document.
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\node[draw=black, inner sep=6pt]{\ref{plot:teal} line1 \ref{plot:orange} line2};
\end{tikzpicture}
\subfloat[Figure 1]{
\begin{tikzpicture}
\begin{axis}[my axis style]
\addplot coordinates {(0,0) (1,1)}; \label{plot:teal}
\addplot coordinates {(0,0) (1,2)}; \label{plot:orange}
\end{axis}
\end{tikzpicture}
\label{fig:a}
}
\hfill
\subfloat[Figure 2]{
\begin{tikzpicture}
\begin{axis}[my axis style]
\addplot coordinates {(0,0) (1,1)};
\addplot coordinates {(0,0) (1,2)};
\end{axis}
\end{tikzpicture}
\label{fig:b}
}
\caption{Caption test, \label{fig:c}}
\end{figure}
\lipsum[1-5]
\end{document}