# Scaling different components of tikzpicture together.

Wants to scale all the components of the following image together.

\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{tikz,pgfplots,pgfplotstable}
\hyphenation{op-tical net-works semi-conduc-tor}
\newdimen\zerolinewidth
\tikzset{
mymat/.style={
matrix of math nodes,
text height=2.5ex,
text depth=0.75ex,
text width=3.25ex,
align=center,
column sep=-\pgflinewidth
},
mymats/.style={
mymat,
nodes={draw,fill=#1}
}
}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[>=latex]
\matrix[mymat,anchor=west,row 2/.style={nodes=draw}]
at (0,0)
(mat1)
{
& \\
n1 \\
};

\matrix[mymat,right=of mat1,row 2/.style={nodes={draw,fill=gray!30}}]
(mat2)
{
& &\\
t_2 & t_4 & t_6 \\
};

\matrix[mymat,anchor=west,row 2/.style={nodes=draw}]
at (0,-1)
(mat3)
{
& \\
n2 \\
};

\matrix[mymat,right=of mat3,row 2/.style={nodes={draw,fill=gray!30}}]
(mat4)
{
&  &  \\
t_1 & t_3 & t_4  \\
};
\matrix[mymat,anchor=west,row 2/.style={nodes=draw}]
at (0,-2)
(mat5)
{
& \\
n3 \\
};

\matrix[mymat,right=of mat5,row 2/.style={nodes={draw,fill=gray!30}}]
(mat6)
{
& &\\
t_1 & t_2 & t_3 \\
};
\matrix[mymat,anchor=west,row 2/.style={nodes=draw}]
at (0,-3)
(mat7)
{
& \\
n4 \\
};

\matrix[mymat,right=of mat7,row 2/.style={nodes={draw,fill=gray!30}}]
(mat8)
{
& \\
t_3 & t_4 & t_5 \\
};
\matrix[mymat,anchor=west,row 2/.style={nodes=draw}]
at (0,-4)
(mat9)
{
& \\
n5 \\
};

\matrix[mymat,right=of mat9,row 2/.style={nodes={draw,fill=gray!30}}]
(mat10)
{
& \\
t_1 & t_3  \\
};

\matrix[mymat, anchor=west,row 2/.style={nodes={draw,fill=gray!30}}]
at (1.65,-5.5)
(mat11)
{
& & & & & \\
t_1 & t_2 & t_3 & t_4 & t_5 & t_6\\
};
\node[ draw, red, dashed, line width=0.7pt, fit=(mat2)(mat4)(mat6)(mat8)(mat10)](node1){};
\node[ draw, red, left=of node1, line width=0.7pt]at(2, -5.5)(node2){Space};
\draw[red,->] (node1) to[out=-90,in=90] (mat11-2-3.north);
\begin{scope}[shorten <= -0pt]
\draw[->]
(mat1-2-1.east) -- (mat2-2-1.west);
\draw[->]
(mat3-2-1.east) -- (mat4-2-1.west);
\draw[->]
(mat5-2-1.east) -- (mat6-2-1.west);
\draw[->]
(mat7-2-1.east) -- (mat8-2-1.west);
\draw[->]
(mat9-2-1.east) -- (mat10-2-1.west);
\draw[->, red]
(node2) -- (mat11-2-1);
\end{scope}

%\draw[blue, dashed](node1.south west) -- (mat11-2-1.north west);
%\draw[blue, dashed](node1.south east) -- (mat11-2-4.north east);
\end{tikzpicture}
\label{fig:5}
\end{figure}

\end{document}

• How about replacing \begin{tikzpicture}[>=latex] by \begin{tikzpicture}[>=latex,scale=2]?
– user121799
Jun 8 '18 at 7:03
• I wants to reduce the size of the figure by 50% and if I use the proposed method, the whole structure gets changed. Is there any other method using which the given figure can be scaled in one go? Jun 8 '18 at 7:18
• If I understand your question correctly, I would probably use the standalone documentclass to create the image files on their own and use \includegraphics with the needed image size in the main document later. Jun 8 '18 at 9:26

To establish a framework, to be able to handle integrated tikz drawings to text documents; It seems to me a good practice to make all the tikz drawings, in a separate document, using the standalone class, that cut the canvas to the size that occupies the drawing and with a certain border; this allows the image to be imported into a main document already processed, which reduces the compilation time of the main document, without losing any type of svg drawing property, which is maintained if you work with the pdf format.

The graphicx package, can also be used in a tikzpicture environment, and place an imported image as a node; in document type environments like the one in the example that is IEEEtran type, so I show an example that requires you to create three tex files in the same folder, or you can create a folder for tikz drawings but you should include the directory in the includegraphics macro. \includegraphics[modifier1,modifier2,..etc]{folder_name/pdf_tex_output_file.pdf}, the MWE is explained in three steps.

MWE:

1. Create a file named Matrix-01.tex , that contains the tikz latex code for the graphic that will be modified. the document class is standalone, border =14pt; the tikz code is the following (optimizing and compressing your code).

\documentclass[tikz,border=14pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{fit,matrix,shapes,arrows}

\begin{document}
\begin{tikzpicture}[
%Global config
>=latex,
line width=1pt
]

\matrix[% General option for all nodes
matrix of math nodes,
text height=2.5ex,
text depth=0.75ex,
text width=3.25ex,
align=center,
line width=1pt,
column sep=-1pt,
nodes={draw, fill=black!10},
column 1/.style={% Style option for column 1
rectangle,
nodes={draw, fill=white}
},
row 6 column 1/.style={% Style option for row 6 column 1
rectangle,
red,
text width=8ex,
nodes={draw, fill=white}
},
] at (0,0) (M1){ % Macrix contents
% PSD: n1 & [horizontal separation between nodes] & t_2 ... could be n1 & [separation] t_2 & t_3 ...
n1 &[30pt,between borders] t_2 & t_3 & t_6\\ [5pt] % \\[separation]
n2 & t_1 & t_3 & t_4\\ [5pt]
n3 & t_1 & t_2 & t_3\\ [5pt]
n4 & t_3 & t_4 & t_5\\ [5pt]
n5 & t_1 & t_3 & \\ [35pt]
Space & t_1 & t_2 & t_3 & t_4 & t_5 & t_6\\
};

\node[
draw,
red,
dashed,
rounded corners,
inner sep=10pt,
line width=1pt,
fit=(M1-5-2)(M1-1-4) % Nice option
](node1){};
\foreach \i in {1,...,5}{
\draw[->] (M1-\i-1.east) -- (M1-\i-2.west);
}
\draw[->,red] (M1-6-1.east) -- (M1-6-2.west);
\draw[->,red] (node1) to[out=-90,in=90] (M1-6-5.north);

\end{tikzpicture}
\end{document}


RESULT: As you can see in the Matrix-01.pdf output file obtained before compile the tex file, the canvas is cropped!.

1. Create a second file Matrix-02.tex, that contains a tikz code and the package graphicx, here is done that you want, the output pdf file from Matrix-01.tex is imported as a node using the standard node definition in tikz, but using the graphicx package, were the text is placed: \node[inner sep=0pt] (FIG1) at (0,0) {\includegraphics[scale=1]{Matrix-01.pdf}};; as you can see in the result and code, the modifiers scale and angle are used; Background library is used to demostrate that no afects the vector working and transparency.

\documentclass[tikz,border=0pt]{standalone}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{fit,matrix,shapes,arrows,backgrounds,positioning}

\begin{document}
\begin{tikzpicture}[
background rectangle/.style={% Background style
rectangle,
rounded corners,
opacity=0.8,
top color=black!3,
bottom color=black!30,
draw=black!40!black!60,
},
show background rectangle,
%Global config
>=latex,
line width=1pt
]

\node[inner sep=0pt] (FIG1) at (0,0) {\includegraphics[scale=1]{Matrix-01.pdf}};
\draw (FIG1)++(0,-4) node[font=\bf]{Imported scale =1};
\node[inner sep=0pt] (FIG2) at (6,1) {\includegraphics[scale=0.7]{Matrix-01.pdf}};
\draw (FIG2)++(0,-3) node[font=\bf]{Imported scale =0.7};
\node[inner sep=0pt] (FIG3) at (6,-5) {\includegraphics[scale=0.5]{Matrix-01.pdf}};
\draw (FIG3)++(0,-2.5) node[font=\bf]{Imported scale =0.5};
\node[inner sep=0pt] (FIG3) at (0,-5.5) {\includegraphics[scale=0.25,angle=45]{Matrix-01.pdf}};
\draw (FIG3)++(0,-2) node[font=\bf, align=center]{Imported scale =0.25 and \\ rotate 45 degrees};

\end{tikzpicture}
\end{document}


RESULT: Output file Matrix-02.pdf, border 0pt, you can see that the canvas is cropped without border.

1. Finally, the code including these elements in a document type IEEEtran, the graphics are also included using the pdf format, now if within an environment figure, where the includegrapics macro uses the width modifier to vary the width of the image without losing the aspect ratio. \includegraphics[width=0.8\columnwidth]{Matrix-01.pdf}

% arara: pdflatex: {synctex: yes, action: nonstopmode}
% arara: bibtex
% arara: bibtex
% arara: pdflatex: {synctex: yes, action: nonstopmode}
% arara: pdflatex: {synctex: yes, action: nonstopmode}

\documentclass[conference,letterpaper]{IEEEtran}
\usepackage[letterpaper, left=1in, right=1in, bottom=1in, top=0.75in]{geometry}
\usepackage[utf8]{inputenc} % input encoding for interpreter
\usepackage[T1]{fontenc}
\usepackage{amssymb}
\usepackage{newtxtext}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage[usenames,dvipsnames]{xcolor} % Allows the definition of hex colors
\usepackage{colortbl} % colors library.
\definecolor{klein}{HTML}{002fa7} % Klein blue
\usepackage[hyphens,spaces,obeyspaces]{url}

\usepackage[all]{hypcap}
%\usepackage{natbib} %Is not compatible with IEEEtran %Try using plainnat
% Enables to cite using author names  commands \citet \citep
\usepackage{lipsum}

\title{IEEEtran Conference Mode}
\author{\IEEEauthorblockN{Foo Bar}
\IEEEauthorblockA{School of Electrical and\\
Computer Engineering\\
Foo Institute of Technology\\
Foo, Bar 454545--4545\\
Email: foo@bar.edu}
\and
\IEEEauthorblockN{Homer Simpson}
\IEEEauthorblockA{Twentieth Century Fox\\
Springfield, USA\\
Email: homer@thesimpsons.com}
\and
\IEEEauthorblockN{Foo Bar\\
and Bar Foo}
San Francisco, California 45454-4545\\
Telephone: (800) 454--4545\\
Fax: (888) 454--4545}}
\IEEEspecialpapernotice{(Testing Paper)}

\begin{document}

\maketitle
\begin{abstract}
\lipsum[1]
\end{abstract}

\begin{IEEEkeywords}
Broad band networks, quality of service, WDM.
\end{IEEEkeywords}
\vspace{2\baselineskip}
\IEEEPARstart{S}{ome} author \cite{cultLIBRE}, another author or reference\cite{cisco}. some text that is used to complete\footnote{\lipsum[5]} a line.\\
\lipsum[1-2]
\begin{figure}[h!]
\centering
\noindent\includegraphics[width=0.8\columnwidth]{Matrix-01.pdf}
\caption{Pdf exported from Matrix-01.tex tikz code in standalone mode.}
\label{example1}
\end{figure}
\vspace{3\baselineskip}
\lipsum[3-4]
\begin{figure}[h!]
\centering
\noindent\includegraphics[width=\columnwidth]{Matrix-02.pdf}
\caption{Pdf exported from Matrix-02.tex tikz code in standalone mode border 0, with background and some imported draws from Matrix-01}
\label{example2}
\end{figure}

\lipsum[6]
\begin{figure}[h!]
\centering
\noindent\includegraphics[width=0.5\columnwidth]{Matrix-02.pdf}
\caption{PIdem but with 0.5 column width}
\label{example3}
\end{figure}
\lipsum[7-8]
\bibliographystyle{IEEEtran}

\bibliography{references}

\end{document}


NOTE: To correct compile this file you need to create the file references.bib with the next content:

@article{cultLIBRE,
author = { Lessig, Lawrence },
title = {{Free Culture: How Big Media uses Technology and the Law to lock down Culture
and control Creativity}},
journal ={ Versión en Español, por LOM Ediciones},
year = {2005},
numpages ={270},
url = {https://www.derechosdigitales.org/culturalibre/cultura_libre.pdf},
pages={31-209},
Abstract={Todo sobre la cultura libre},
language = {spanish}}

@Report{cisco,
title = {{Cisco Visual Networking Index: Global Mobile Data Traffic Forecast Update, 2016–2021 White Paper}},
year  = {2017},
date  = {2017-03-28},
url  = {https://www.cisco.com/c/en/us/solutions/collateral/service-provider/visual-networking-index-vni/mobile-white-paper-c11-520862.html}}


RESULT:

Adding the option transform canvas={scale=.5} to the tikzpicture does the trick.

\begin{tikzpicture}[>=latex,transform canvas={scale=.5}]