6

I have some plots generated from matlab2tikz which I would like to overlay. Each plot is a seperate .tikz file which I input using \input. My code currently is:

\pgfplotsset{
every axis/.append style={
scale only axis,   
},
/tikz/every picture/.append style={
trim axis left,
trim axis right,
    }
}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{table}[h!]\centering  
     \begin{center}
     \begin{tabular}{P{6cm} P{6cm}}
     \toprule
      R220expt21 & R60expt\\
      \cmidrule(r){1-1}\cmidrule(l){2-2}
      \scalebox{0.4}{\input{images/expt21nrmse.tikz}}\llap{\raisebox{0.5cm}{\scalebox{0.2}                  {\input{images/expt21nrmse.tikz}}}}
      \scalebox{0.4}{\input{images/expt21fitD.tikz}}        
      &     
      \scalebox{0.4}{\input{images/expt2nrmse.tikz}}
      \scalebox{0.4}{\input{images/expt2fitD.tikz}}
      \\ \bottomrule
      \end{tabular}
      \caption{Fitted results for two samples. (top) NRMSE values for each q. (bottom) Fitted diffusion. (bottom insert) 2 Highlighted DICF and theoretical fits.}
      \label{tbl:1}
      \end{center}
\end{table}

Currently this code produces:

Output from code

As you can see the inset of the top left image is looking fine, but I would like to shift it around horizontally too. I tried the solutions in the topic "Horizontal equivalent to \raisebox?" but I get an error about being in horizontal mode.

My questions are:

  • Is there a method, keeping with what I do currently in using \input, to neatly position a subplot?
  • Is my method bad practice, if so what should I be doing?

Thanks for your time.

Edit 2: FULL MWE:

\documentclass[11pt,a4paper]{report}

\usepackage[a4paper,vmargin={30mm,30mm},hmargin={30mm,30mm}]{geometry}
\usepackage{graphicx,array,booktabs,pgfplots}
\usetikzlibrary{calc}

\newsavebox{\mybox}
%\sbox{\mybox}{\input{images/exp5nrmse.tikz}}
\sbox{\mybox}{%   Just use \input{images/exp5nrmse.tikz} instead of following
 \begin{tikzpicture}
\begin{axis}[%
width=4.52083333333333in,
height=3.565625in,
scale only axis,
xmin=1,
xmax=511,
xlabel={$q (\mu m^{-1})$},
ymin=0.5,
ymax=1,
ylabel={Normalized RMS error}
]
\addplot [color=blue,solid,line width=1.0pt,forget plot]
  table[row sep=crcr]{
10  0.49608542  \\
11  0.5509195   \\
12  0.54464869  \\
13  0.54379236  \\
14  0.60808362  \\
15  0.49726539  \\
16  0.61919337  \\
17  0.66339954  \\
18  0.72671426  \\
19  0.71607429  \\
};
\end{axis}
\end{tikzpicture}%
}

\pgfplotsset{
every axis/.append style={
scale only axis,   
},
/tikz/every picture/.append style={
trim axis left,
trim axis right,
    }
}

\begin{document}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{table}[htb!]
 \centering
     \begin{tabular}{P{5.5cm} P{5.5cm}}
     \toprule
      R220expt21 & R60expt\\
      \cmidrule(r){1-1}\cmidrule(l){2-2}
      \tikz[remember picture,baseline=(a.base)]\node[scale=0.4,outer sep=0pt]
               (a){\usebox{\mybox}};
       %%% Change dimensions in $(a.east)+(-0.9,0cm)$
      \tikz[remember picture,overlay]\node[anchor=east,outer sep=0pt,scale=0.2] at
               ($(a.east)+(-0.9,0cm)$){\usebox{\mybox}};
      \scalebox{0.4}{\usebox{\mybox}}
      &
      \scalebox{0.4}{\usebox{\mybox}}
      \scalebox{0.4}{\usebox{\mybox}}
      \\ \bottomrule
      \end{tabular}
      \caption{Fitted results for two samples. (top) NRMSE values for each q. (bottom) Fitted diffusion. (bottom insert) 2 Highlighted DICF and theoretical fits.}
      \label{tbl:1}
\end{table}

\end{document}
2
  • Providing a full MWE starting with \documentclass would be helpful. I was going to suggest \stackinset from the stackengine package, but I don't know what package options it takes to make your example compile. Commented Mar 11, 2014 at 10:36
  • Okay, thanks. I was originally from stackoverflow where they just show bits of code. But I fix it up tomorrow once Im back at the pc that has this code. Commented Mar 11, 2014 at 10:59

1 Answer 1

4

Hopefully this will work with \input too.

You can use a node to put your .tikz files

\documentclass{article}
\usepackage{graphicx,array,booktabs,tikz}
\usetikzlibrary{calc}
\begin{document}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{table}[htb!]
 \centering
     \begin{tabular}{P{5.5cm} P{5.5cm}}
     \toprule
      R220expt21 & R60expt\\
      \cmidrule(r){1-1}\cmidrule(l){2-2}
      \tikz[remember picture,baseline=(a.base)]\node[scale=0.4,outer sep=0pt]
               (a){\includegraphics[width=6cm]{example-image-a}};
       %%% Change dimensions in $(a.east)+(-0.5,0cm)$ 
      \tikz[remember picture,overlay]\node[anchor=east,outer sep=0pt,scale=0.2] at
               ($(a.east)+(-0.5,0cm)$){\includegraphics[width=6cm]{example-image-b}};
      \scalebox{0.4}{\includegraphics[width=6cm]{example-image-c}}
      &
      \scalebox{0.4}{\includegraphics[width=6cm]{example-image-a}}
      \scalebox{0.4}{\includegraphics[width=6cm]{example-image}}
      \\ \bottomrule
      \end{tabular}
      \caption{Fitted results for two samples. (top) NRMSE values for each q. (bottom) Fitted diffusion. (bottom insert) 2 Highlighted DICF and theoretical fits.}
      \label{tbl:1}
\end{table}

\end{document}

enter image description here

update:

\documentclass{article}
\usepackage{graphicx,array,booktabs,pgfplots}
\pgfplotsset{compat=1.9}
\usetikzlibrary{calc}

%% use as many boxes as you need for each plot.
\newsavebox{\mybox}
%\sbox{\mybox}{\input{images/exp5nrmse.tikz}}
\sbox{\mybox}{%   Just use \input{images/exp5nrmse.tikz} instead of following
 \begin{tikzpicture}
\begin{axis}[%
width=4.52083333333333in,
height=3.565625in,
scale only axis,
xmin=1,
xmax=511,
trim axis left,
trim axis right,
xlabel={$q (\mu m^{-1})$},
ymin=0.5,
ymax=1,
ylabel={Normalized RMS error}
]
\addplot [color=blue,solid,line width=1.0pt,forget plot]
  table[row sep=crcr]{
10  0.49608542  \\
11  0.5509195   \\
12  0.54464869  \\
13  0.54379236  \\
14  0.60808362  \\
15  0.49726539  \\
16  0.61919337  \\
17  0.66339954  \\
18  0.72671426  \\
19  0.71607429  \\
};
\end{axis}
\end{tikzpicture}%
}%
\begin{document}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{table}[htb!]
 \centering
     \begin{tabular}{P{5.5cm} P{5.5cm}}
     \toprule
      R220expt21 & R60expt\\
      \cmidrule(r){1-1}\cmidrule(l){2-2}
      \begin{tikzpicture}[baseline=(a.base)]
      \node[scale=0.4,outer sep=0pt]  (a){\usebox{\mybox}};
       %%% Change dimensions in $(a.east)+(-0.9,0cm)$
      \node[anchor=east,outer sep=0pt,scale=0.2] at
               ($(a.east)+(-0.9,0cm)$){\usebox{\mybox}};
      \end{tikzpicture}
      \scalebox{0.4}{\usebox{\mybox}}
      &
      \scalebox{0.4}{\usebox{\mybox}}
      \scalebox{0.4}{\usebox{\mybox}}
      \\ \bottomrule
      \end{tabular}
      \caption{Fitted results for two samples. (top) NRMSE values for each q. (bottom) Fitted diffusion. (bottom insert) 2 Highlighted DICF and theoretical fits.}
      \label{tbl:1}
\end{table}

\end{document}

enter image description here

7
  • Thanks for your assistance. I tried your example just with replacing {\includegraphics[width=6cm]{example-image-a}} with my {\input{images/exp5nrmse.tikz}} and I get an error: No shape named a is known. My .tikz file has been edited into my question. Thanks Commented Mar 11, 2014 at 8:16
  • Hi Harish. Thanks a lot for your input I really appreciate it. Unfortunately I am having some strange results my end. The document does work when keeping it in your form, but only when using \pgfplotsset{compat=1.9}. You might also notice that the left sides of the first column of plots does not line up. I had to use a different pgfplotsset to fix this in/ I have edited my post again to add a proper MWE. I really appreciate all your help though. Commented Mar 11, 2014 at 23:45
  • You will see with my new MWE that everything is a bit strangely aligned. And every time you run it things jump around even more. Commented Mar 11, 2014 at 23:52
  • @SteveHatcher Remove /tikz/every picture/.append style={ trim axis left, trim axis right, . It is causing problems.
    – user11232
    Commented Mar 11, 2014 at 23:59
  • Thanks. That does fix that, but now the y axis of the plots on the left column do not line up. That was what lead me to use trim axis. Commented Mar 12, 2014 at 0:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .