双栏纸张中的图例位置

双栏纸张中的图例位置

如何在多列纸上更改图例位置?我的代码有什么问题吗?我想将图例放在这两个图的顶部中央。

谢谢。

\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}

相关内容