1

Following the answer I received in https://tex.stackexchange.com/a/652074/61517 I wanted to make the figures even more compact by moving the corresponding labels above/to the left of the figure (as for example demonstrated by Subfigures. To add A and B to subfigures (in the top left corner), and to label them for referencing). With the code, given as

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

in the main file, and

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

in the tikz-files I got the following result:
enter image description here

Unfortunately, I am already heavily relying on subcaption in my project, and I do not want to change all other figures now, which prevents me using subfig. Therefore, I arrived at two problems:

  • How can I replicate the demonstrated behavior by using subfigure (or similar, contained in subcaption?
  • Ideally, how can I move the labels into the figures, to the top left corner, without having to place them there manually?

I am currently not sure how to solve either of them. Which options do I have?

arc_lupus
  • 1,781

1 Answers1

1

I would probably rename the external .tikz files to sub1.tikz to sub6.tikz, since then you can easily loop over these files which would reduce you code.

As for the caption inside the subplots, you could use an extra x tick that is positioned at zero opposite to the regular x ticks.

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

enter image description here