根据我收到的答案https://tex.stackexchange.com/a/652074/61517我想通过将相应的标签移动到图形上方/左侧来使图形更加紧凑(例如通过子图。将 A 和 B 添加到子图(左上角),并标记它们以供参考)代码如下
\documentclass{article}
\usepackage{standalone}
\usepackage{tikz}
\usepackage{caption}
\usepackage{subfig}
\usetikzlibrary{external}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage{floatrow}
\usepackage{tikzscale}
\begin{filecontents*}{file1.dat}
x y
0 0
1 1
2 2
3 3
4 4
5 5
\end{filecontents*}
%\usepackage{subcaption}
\tikzexternalize[prefix=tikz-cache/]
\tikzset{external/force remake}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{every axis/.append style={
label style={font=\footnotesize\bfseries},
tick label style={font=\footnotesize},
legend style={font=\footnotesize}
},
y axis/.append style={align=center}}
\tikzset{Line Label/.style={font=\footnotesize,scale=2}}
\newcommand{\figurefontsize}{\footnotesize}
\floatsetup[figure]{style=plain,subcapbesideposition=top}
\begin{document}
\begin{figure}[htpb]
\centering
\hspace*{\fill}%
\pgfplotsset{trim axis left, /pgfplots/ylabel style={opacity=0}}%
\pgfplotsset{/pgfplots/xlabel style = {opacity=0}}%
\pgfplotsset{/pgfplots/ylabel style={opacity=100}}%
\sidesubfloat[]{\hspace{-.5cm}\includegraphics[height=.33\linewidth]{sub.tikz}\hspace{.5cm}}\hfill%
\pgfplotsset{trim axis left, /pgfplots/ylabel style={opacity=0}}%
\sidesubfloat[]{\hspace{-.5cm}\includegraphics[height=.33\linewidth]{subII.tikz}\hspace{.5cm}}\hfill%
\sidesubfloat[]{\hspace{-.5cm}\includegraphics[height=.33\linewidth]{subIII.tikz}\hspace{.5cm}}\hspace*{\fill}\vspace{-.5cm}\\%
\hspace*{\fill}%
\pgfplotsset{trim axis left, /pgfplots/ylabel style={opacity=0}}%
\pgfplotsset{/pgfplots/xlabel style = {opacity=100}}%
\pgfplotsset{/pgfplots/ylabel style={opacity=100}}%
\sidesubfloat[]{\hspace{-.5cm}\includegraphics[height=.33\linewidth]{subIV.tikz}\hspace{.5cm}}\hfill%
\pgfplotsset{trim axis left, /pgfplots/ylabel style={opacity=0}}%
\sidesubfloat[]{\hspace{-.5cm}\includegraphics[height=.33\linewidth]{subV.tikz}\hspace{.5cm}}\hfill%
\sidesubfloat[]{\hspace{-.5cm}\includegraphics[height=.33\linewidth]{subVI.tikz}\hspace{.5cm}}\hspace*{\fill}%
\end{figure}
\end{document}
在主文件中,并且
\pgfplotstableread{file1.dat}{\tablea}
\begin{tikzpicture}
\begin{axis}[
ymin=0, ymax=30,
xmin=0, xmax=5,
xlabel={$x$},
ylabel={$y$-entry, typically long},
grid=major,
legend entries={\(y_1\),\(y_2\),\(y_1+y_2\)},
legend pos = north west
]
% Select appropriate columns
\addplot [blue, mark=*] table [x=x,y=y] {\tablea};
\end{axis}
\end{tikzpicture}
不幸的是,我的项目已经严重依赖了subcaption
,现在我不想改变其他所有数字,这使我无法使用subfig
。因此,我遇到了两个问题:
- 如何使用
subfigure
(或类似的,包含在subcaption
?中)复制所演示的行为 - 理想情况下,我如何将标签移动到图形的左上角,而不必手动将它们放置在那里?
我目前不确定如何解决这两个问题。我有哪些选择?
答案1
我可能会将外部 .tikz 文件重命名为sub1.tikz
,sub6.tikz
因为这样您就可以轻松循环这些文件,从而减少您的代码。
至于子图内的标题,您可以使用extra x tick
位于常规 x 刻度对面的零处的标题。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage{tikzscale}
\usepackage{subcaption}
\usetikzlibrary{pgfplots.groupplots}
%\usetikzlibrary{external}
%\tikzexternalize[prefix=tikz-cache/]
%\tikzset{external/force remake}
\pgfplotsset{
every axis/.append style={
label style={font=\footnotesize\bfseries},
tick label style={font=\footnotesize},
legend style={font=\footnotesize}
},
trim axis left,
y axis/.append style={align=center},
extra x ticks={0},
extra x tick style={ticklabel pos=top}
}
\begin{filecontents*}{file1.dat}
x y
0 0
1 1
2 2
3 3
4 4
5 5
\end{filecontents*}
\begin{document}
\begin{figure}[htpb]
\centering
\foreach \i in {1,...,6} {%
\pgfplotsset{extra x tick labels={(\symbol{\numexpr96+\i\relax})}}%
\ifnum\i>1%
\ifnum\i=4\else%
\pgfplotsset{/pgfplots/ylabel style={opacity=0}}%
\fi%
\fi%
\ifnum\i<4%
\pgfplotsset{/pgfplots/xlabel style={opacity=0}}%
\fi%
\begin{subfigure}[t]{.33\linewidth}
\includegraphics[height=4cm]{sub\i.tikz}
\end{subfigure}%
\ifnum\i=3%
\newline
\fi%
}
\end{figure}
\end{document}