I have a question on scaling a graph when the graph is included using \includegraphics
.
A code snippet is below.
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{tikzscale}
\usetikzlibrary{external}
\tikzexternalize
%\tikzset{external/mode=list and make}
%\tikzset{external/check=diff}
\tikzset{external/force remake}
%\tikzsetexternalprefix{figure-build/, up to date check=md5, force remake}
\pgfplotsset{compat=1.8}
%\pgfplotsset{compat=newest} % necessary for new features
\usepackage{filecontents}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\vspace{0.5cm}
\begin{filecontents*}{testCross1.tikz}
\begin{tikzpicture}
\draw (0,0) -- (1,1) (0,1) -- (1,0);
\end{tikzpicture}
\end{filecontents*}
\begin{filecontents*}{testCross2.tikz}
\begin{tikzpicture}[xscale=3.0,yscale=2.0]
\draw (0,0) -- (1,1) (0,1) -- (1,0);
\end{tikzpicture}
\end{filecontents*}
\begin{figure}[bth]
\begin{tabular}{p{3in}}
\includegraphics[]{testCross1} \\
\includegraphics[width=0.35\linewidth,height=0.2\linewidth]{testCross1} \\
\includegraphics[]{testCross2}
\end{tabular}
\caption{\small{Plot.}}
\end{figure}
\end{document}
This code snippet is compiled by
pdflatex -shell-escape main.tex
I have tried three ways of scaling a graph.
First, I used \includegraphics[width=0.35\linewidth,height=0.2\linewidth]{testCross1}
, but it does not work. The graph stays the same size as the original graph.
Second, I specified the scaling together the declaration of the graph as below.
\begin{tikzpicture}[xscale=3.0,yscale=2.0]
\draw (0,0) -- (1,1) (0,1) -- (1,0);
\end{tikzpicture}
It works. But, I really want to be able to dynamically specify the scaling parameters without changing the specification of the tikzpicture.
So, I tried to scale the graph by the following code:
\includegraphics[xscale=3.0,yscale=2.0]{testCross1}
But, an error is reported in compilation. The error message in the .log file says that
! Package pgfkeys Error: I do not know the key '/tikzscale/xscale' and I am going to ignore it. Perhaps you misspelled it.
Could you help me to show the two ways that a graph can be resized through the following declarations?
\includegraphics[xscale=3.0,yscale=2.0]{testCross1}
and
\includegraphics[width=0.35\linewidth,height=0.2\linewidth]{testCross1}
Best Answer
The package is doing something very strange with the includegraphics arguments:-)
generates an error, as does
but bizarrely this works:
and you can hide the fbox rules by:
The above image is made with: