1

I use the standalone package and create my tikz pictures in a seperate .tex file. I create a subfigure in the chapter I want it to be and when I compile main.tex the subfigures is loaded. I created a MWE below that shows how the figures are not the same size. Scaling is going to be an issue, as the font size etc won't be similar. Furthermore, when the caption goes over two lines, it pushes the subfigure up, which is also not ideal.

  1. How can I make all subfigures exactly the same size?
  2. How can I make the caption not pushing up the subfigure if it exceeds 2 lines?

main.tex

\documentclass[8pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[subpreambles=true, mode=buildnew]{standalone}
\usepackage{subfiles}
\usepackage[margin=1.75cm]{geometry}
\usepackage{graphicx}

\begin{document}

\input{Introduction}

\end{document}

Chapter tex - Introduction.tex

\documentclass{standalone}
\usepackage{subfiles}
\usepackage{pgfplots}
\usepackage[section]{placeins}
\usepackage{subcaption}
\usepackage[margin=1.75cm]{geometry}
\pgfplotsset{compat=1.16}

\begin{document}

\begin{figure*}[ht]
        \centering
        \begin{subfigure}[b]{0.475\textwidth}
            \centering
            \includegraphics[width=\textwidth]{Figure1.tex}
            \caption[Network2]%
            {{\small ipsum lopem ipsum lopem ipsum lopem ipsum lopem ipsum lopem ipsum lopem ipsum lopem ipsum lopem }}    
        \end{subfigure}
        \hfill
        \begin{subfigure}[b]{0.475\textwidth}  
            \centering 
            \includegraphics[width=\textwidth]{Figure2.tex}
            \caption[]%
            {{\small ipsum lopem ipsum lopem}}    
        \end{subfigure}
        \vskip\baselineskip
        \begin{subfigure}[b]{0.475\textwidth}   
            \centering 
            \includegraphics[width=\textwidth]{Figure1.tex}
            \caption[]%
            {{\small ipsum lopem ipsum lopem}}    
        \end{subfigure}
        \quad
        \begin{subfigure}[b]{0.475\textwidth}   
            \centering 
            \includegraphics[width=\textwidth]{Figure2.tex}
            \caption[]%
            {{\small -1 days and +1 days}}    
        \end{subfigure}
        \caption[ The average and standard deviation of critical parameters ]
        {\small ipsum lopem ipsum lopem} 
        \label{fig:gammas}
\end{figure*}

\end{document}

Figure 1 - Figure1.tex

\documentclass{standalone}
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\definecolor{blue1}{RGB}{0, 0, 108}
\definecolor{red1}{RGB}{108, 0, 0}

\begin{document}

\begin{filecontents*}{gammagroup1group4afterv2.txt}
days Group1 Group4   
-120    0.16331143  0.390679728
-119    0.139611442 0.299897574
-118    0.166181107 0.336650007
\end{filecontents*}

\begin{tikzpicture}
\begin{axis}[
xlabel=ipsum lopem,
xmin=-120,xmax=-118,
ylabel= ipsum lopem
]
  \addplot [mark=none,blue1] table [x=days,y=Group1] {gammagroup1group4afterv2.txt};
  \addplot [mark=none,red1] table [x=days,y=Group4] {gammagroup1group4afterv2.txt};
\legend{high, low}
\end{axis}
\end{tikzpicture}

\end{document}

Figure 2 - Figure2.tex

\documentclass{standalone}
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\definecolor{blue1}{RGB}{0, 0, 108}
\definecolor{red1}{RGB}{108, 0, 0}

\begin{document}

\begin{filecontents*}{gammagroup1group4after.txt}
days Group1 Group4   
-120    0.41168498  0.454667851
-119    0.405303768 0.438895231
-118    0.416069556 0.448782161
\end{filecontents*}

\begin{tikzpicture}
\begin{axis}[
xlabel=ipsum lopem ,
xmin=-120,xmax=-118,
ylabel= ipsum lopem
]
  \addplot [mark=none,blue1] table [x=days,y=Group1] {gammagroup1group4after.txt};
  \addplot [mark=none,red1] table [x=days,y=Group4] {gammagroup1group4after.txt};

\legend{high, low}
\end{axis}
\end{tikzpicture}

\end{document}

Below the picture with the end-result; as you can see the subfigures between the different figures are not the same size + the top left subfigure is pushed up due to the caption.

enter image description here

  • The [b] option aligns the bottoms of the subfigures, which is the caption.. You should use [t] to align the first baseline, which is the bottom of \includegraphics. – John Kormylo Mar 29 at 17:59
  • @JohnKormylo Thank you, [t] indeed fixes it. Now whats still left is the actual size of the figures being different, – LVB Mar 29 at 18:12
  • You can use the [height=...] option in \incudgraphics to force them all to have the same height (they already have the same width), but this includes the annotation. If what you really want is to force the axes to all have the same size, you need to use [scale only axis] in the axis environment. and possibly specify the width and height there too. If you want all the tikzpictures to have the same bounding box, you need to add \path (common sw) (common ne); for some common rectangle inside each tikzpicture – John Kormylo Mar 29 at 18:24
  • @JohnKormylo Forcing the same height and width for includegraphics does indeed not make the axes to have the same indeed. Would you be able to try scaling the axis correctly for my MWE? – LVB Mar 29 at 18:45
1

For some strange reason, using [scale only axis] messed up the xticks (which can be fixed). OTOH, this by itself seems good enough.

Also, you need to stick with either \hfill or \quad, not alternate.

Figure1.tex

\documentclass{standalone}
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\definecolor{blue1}{RGB}{0, 0, 108}
\definecolor{red1}{RGB}{108, 0, 0}

\begin{document}

\begin{filecontents*}{gammagroup1group4afterv2.txt}
days Group1 Group4   
-120    0.16331143  0.390679728
-119    0.139611442 0.299897574
-118    0.166181107 0.336650007
\end{filecontents*}

\begin{tikzpicture}
\begin{axis}[scale only axis,
xtick={-120, -119.5, -119, -118.5, -118},
xlabel=ipsum lopem,
xmin=-120,xmax=-118,
ylabel= ipsum lopem
]
  \addplot [mark=none,blue1] table [x=days,y=Group1] {gammagroup1group4afterv2.txt};
  \addplot [mark=none,red1] table [x=days,y=Group4] {gammagroup1group4afterv2.txt};
\legend{high, low}
\end{axis}
\end{tikzpicture}

\end{document}

Figure2.tex

\documentclass{standalone}
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\definecolor{blue1}{RGB}{0, 0, 108}
\definecolor{red1}{RGB}{108, 0, 0}

\begin{document}

\begin{filecontents*}{gammagroup1group4after.txt}
days Group1 Group4   
-120    0.41168498  0.454667851
-119    0.405303768 0.438895231
-118    0.416069556 0.448782161
\end{filecontents*}

\begin{tikzpicture}
\begin{axis}[scale only axis,
xtick={-120, -119.5, -119, -118.5, -118},
xlabel=ipsum lopem ,
xmin=-120,xmax=-118,
ylabel= ipsum lopem
]
  \addplot [mark=none,blue1] table [x=days,y=Group1] {gammagroup1group4after.txt};
  \addplot [mark=none,red1] table [x=days,y=Group4] {gammagroup1group4after.txt};

\legend{high, low}
\end{axis}
\end{tikzpicture}

\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.