![为 tikzpicture 图添加标签](https://linux22.com/image/317242/%E4%B8%BA%20tikzpicture%20%E5%9B%BE%E6%B7%BB%E5%8A%A0%E6%A0%87%E7%AD%BE.png)
如何向下面的两个图中 添加像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
您想将A
和B
放在图表的右上角吗?
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}