为 tikzpicture 图添加标签

为 tikzpicture 图添加标签

如何向下面的两个图中 添加像A和这样的标签?B

在此处输入图片描述

我尝试了一些变体\node (A) at ([xshift=-1.3cm, yshift=1cm]group c1r1.north west) {\color{black} (A)};,但没有成功,主要是因为我没有使用组图环境。这是我的代码:

\documentclass[]{article}
    \usepackage{pgfplots, alphalph}
    \usepgfplotslibrary{groupplots}
    \pagenumbering{gobble}

\begin{document}

\begin{figure}
\hspace*{-3.5cm}
\centering
\begin{minipage}{.5\textwidth}
  \centering
  \begin{tikzpicture}
\begin{axis}[ 
    title={My title},
    axis lines=middle,
    axis line style={->},
    ylabel near ticks,
    xlabel near ticks,
    scaled y ticks = false,
    yticklabel style={/pgf/number format/fixed},
    xlabel={x-label},
    ylabel={y-label}]


\end{axis} 
\end{tikzpicture}
\end{minipage}%
\begin{minipage}{1.3\textwidth}
  \centering
  \begin{tikzpicture}
\begin{axis}[ 
    title={My title},
    axis lines=middle,
    axis line style={->},
    ylabel near ticks,
    xlabel near ticks,
    scaled y ticks = false,
    yticklabel style={/pgf/number format/fixed},
    xlabel={x-label},
    ylabel={y-label}]
\end{axis} 
\end{tikzpicture}
\end{minipage}
\end{figure}

\end{document}

答案1

您想将AB放在图表的右上角吗?

current bounding box然后就可以使用该节点了。此方法独立于包工作pgfplots

\documentclass[]{article}
    \usepackage{pgfplots, alphalph}
    \usepgfplotslibrary{groupplots}
    \pagenumbering{gobble}

\begin{document}

\begin{figure}
\hspace*{-3.5cm}
\centering
\begin{minipage}{.5\textwidth}
  \centering
  \begin{tikzpicture}
\begin{axis}[
    title={My title},
    axis lines=middle,
    axis line style={->},
    ylabel near ticks,
    xlabel near ticks,
    scaled y ticks = false,
    yticklabel style={/pgf/number format/fixed},
    xlabel={x-label},
    ylabel={y-label}]
\end{axis}
  \node[below right]
    at (current bounding box.north west) {A};
\end{tikzpicture}
\end{minipage}%
\begin{minipage}{1.3\textwidth}
  \centering
  \begin{tikzpicture}
\begin{axis}[
    title={My title},
    axis lines=middle,
    axis line style={->},
    ylabel near ticks,
    xlabel near ticks,
    scaled y ticks = false,
    yticklabel style={/pgf/number format/fixed},
    xlabel={x-label},
    ylabel={y-label}]
\end{axis}
  \node[below right]
    at (current bounding box.north west) {B};
\end{tikzpicture}
\end{minipage}
\end{figure}

\end{document}

结果

答案2

我把节点放在上面,把子标题放在下面。

我认为您意识到了您的图形超出了边距。我做了一些更改,以便更好地居中。在调整尺寸时,在小页面周围放置一个 \fbox 会有所帮助。

    \documentclass[]{article}
    \usepackage{pgfplots, alphalph, subcaption}
    \usepgfplotslibrary{groupplots}
    \pagenumbering{gobble}

\begin{document}

\begin{figure}
\hspace*{-3.5cm}%
\begin{minipage}{\dimexpr .5\textwidth + 3.5cm}
  \centering
  \begin{tikzpicture}
\begin{axis}[ 
    title={My title},
    axis lines=middle,
    axis line style={->},
    ylabel near ticks,
    xlabel near ticks,
    scaled y ticks = false,
    yticklabel style={/pgf/number format/fixed},
    xlabel={x-label},
    ylabel={y-label},
    name=border]
\end{axis} 
\node[above=1cm] at (border.north) {A above};
\end{tikzpicture}
\subcaption{below}
\end{minipage}%
\begin{minipage}{\dimexpr .5\textwidth + 3.5cm}
  \centering
  \begin{tikzpicture}
\begin{axis}[ 
    title={My title},
    axis lines=middle,
    axis line style={->},
    ylabel near ticks,
    xlabel near ticks,
    scaled y ticks = false,
    yticklabel style={/pgf/number format/fixed},
    xlabel={x-label},
    ylabel={y-label},
    name=border]
\end{axis} 
\node[above=1cm] at (border.north) {B above};
\end{tikzpicture}
\subcaption{below}
\end{minipage}\hspace*{-3.5cm}
\textbf{}
\end{figure}

\end{document}

标题为 tikzpictures

相关内容