1

In a current project I have the following figure structure (using example figures here): enter image description here

The file has been created using two files, main.tex:

\documentclass{article}
\usepackage{standalone}
\usepackage{tikz}
\usepackage{caption}
\usetikzlibrary{external}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\usepackage{filecontents}
\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}

\begin{document} \begin{figure}[htpb] \centering \hspace{\fill}% \begin{subfigure}[t]{.3\linewidth} \includegraphics[width=\linewidth]{sub.tikz} \caption{Image I} \end{subfigure}\hfill% \begin{subfigure}[t]{.3\linewidth} \includegraphics[width=\linewidth]{subII.tikz} \caption{Image II} \end{subfigure}\hfill% \begin{subfigure}[t]{.3\linewidth} \includegraphics[width=\linewidth]{subIII.tikz} \caption{Image III} \end{subfigure}\hspace{\fill}% \end{figure} \end{document}

and sub[, II, III].tex:

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

sub.tikz, subII.tikz and subIII.tikz are identical.

As they all share the same y axis, I wanted to remove the y-axis labels from figure b) and figure c) and increase all figures in size to decrease the space between them, to use the y-axis of figure a) as common y-axis. Still, I do not want to entirely remove the white space between the figures, I still want a bit distance between the figures left.

Because I am re-using the figures at different places, though, I do not want to modify the figure files (i.e. the tikz-files) itself, but rather enable/disable the different settings from the main file.

As initial test to disable the y-labels selectively I rewrote the figure-environment into:

\begin{figure}[htpb]
    \centering
    \hspace*{\fill}%
    \begin{subfigure}[t]{.3\linewidth}
        \includegraphics[width=\linewidth]{sub.tikz}
        \caption{Image I}
    \end{subfigure}\hfill\pgfplotsset{/pgfplots/ylabel=\empty}%
    \begin{subfigure}[t]{.3\linewidth}
        \includegraphics[width=\linewidth]{subII.tikz}
        \caption{Image II}
    \end{subfigure}\hfill%
    \begin{subfigure}[t]{.3\linewidth}
        \includegraphics[width=\linewidth]{subIII.tikz}
        \caption{Image III}
    \end{subfigure}\hspace*{\fill}%
\end{figure}

to disable the y-labels for figure b) and c), but this setting did not show any results.

What would be a better way to achieve my goal, to make the figures more compact, as described above, without modifying the original tikz-files?

arc_lupus
  • 1,781

1 Answers1

1

Using \pgfplotsset{/pgfplots/ylabel=\empty} at this place won't have any effect because it will be overridden by the option ylabel={$y$-entry, typically long} that is added to the axis macro in your .tikz files.

However, your approach does work, if you use some other options that are not set insinde the .tikz files, for example \pgfplotsset{/pgfplots/ylabel style={opacity=0}}. You can also crop the left axis using trim axis left.

If you crop away the left axis, the three images don't have the same width anymore, so you should probably replace \includegraphics[width=\linewidth] by someting like \includegraphics[height=4cm]. Also, you need to adjust the width of each of the three subfigures of course.

Taken together all this, you would get the following code:

\documentclass{article}
\usepackage{tikz}
%\usetikzlibrary{external}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18} 
\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}

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

\begin{document} \begin{figure}[htpb] \centering \begin{subfigure}[t]{.35\linewidth} \includegraphics[height=4cm]{sub.tikz} \caption{Image I} \end{subfigure}\hfill% \pgfplotsset{trim axis left, /pgfplots/ylabel style={opacity=0}}% \begin{subfigure}[t]{.275\linewidth} \includegraphics[height=4cm]{subII.tikz} \caption{Image II} \end{subfigure}\hfill% \begin{subfigure}[t]{.275\linewidth} \includegraphics[height=4cm]{subIII.tikz} \caption{Image III} \end{subfigure}% \end{figure} \end{document}

I commented out the externalization stuff. But it should not make a difference.

enter image description here