如何在多列纸上更改图例位置?我的代码有什么问题吗?我想将图例放在这两个图的顶部中央。
谢谢。
\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}