想要将下图的所有组件缩放到一起。
\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{tikz,pgfplots,pgfplotstable}
\usetikzlibrary{fit,matrix,positioning,decorations.pathreplacing,calc ,shapes,arrows,shadows,patterns}
\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}
答案1
建立一个框架,以便能够将集成的 tikz 绘图处理到文本文档中;在我看来,将所有 tikz 绘图放在一个单独的文档中,使用standalone class
,将画布剪切为占据绘图的大小并具有一定的边框,是一种很好的做法;这允许将图像导入已经处理过的主文档中,从而减少了主文档的编译时间,而不会丢失任何类型的 svg 绘图属性,如果您使用 pdf 格式,该属性将会保留。
,还graphicx package
可以在 tikzpicture 环境中使用,并将导入的图像作为节点放置;在文档类型环境中,例如示例中的 IEEEtran 类型,因此我展示了一个示例,要求您在同一个文件夹中创建三个 tex 文件,或者您可以为 tikz 图纸创建一个文件夹,但您应该在 includegraphics 宏中包含该目录。\includegraphics[modifier1,modifier2,..etc]{folder_name/pdf_tex_output_file.pdf}
,MWE 分三个步骤进行解释。
梅威瑟:
- 创建一个名为的文件
Matrix-01.tex
,其中包含将要修改的图形的 tikz latex 代码。文档类是独立的,边框 =14pt;tikz 代码如下(优化和压缩您的代码)。
\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}
结果:正如您在编译 tex 文件之前获得的输出文件中看到的Matrix-01.pdf
,画布被裁剪了!
- 创建第二个文件
Matrix-02.tex
,其中包含 tikz 代码和包 graphicx,这里完成了您想要的操作,Matrix-01.tex
使用 tikz 中的标准节点定义将输出的 pdf 文件作为节点导入,但使用 graphicx 包,放置文本:\node[inner sep=0pt] (FIG1) at (0,0) {\includegraphics[scale=1]{Matrix-01.pdf}};
;正如您在结果和代码中所看到的,使用了修饰符 scale 和 angle;背景库用于演示不影响矢量工作和透明度。
\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,
shade,
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}
结果:输出文件Matrix-02.pdf
,,border 0pt
您可以看到画布被裁剪,没有边框。
- 最后,将这些元素包含在文档类型 IEEEtran 中的代码,图形也使用 pdf 格式包含在内,现在如果在环境图中,其中 includegrapics 宏使用宽度修改器来改变图像的宽度而不会丢失纵横比。
\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[colorlinks=True,citecolor=red,urlcolor=klein]{hyperref}% For Hyperlinks
\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: [email protected]}
\and
\IEEEauthorblockN{Homer Simpson}
\IEEEauthorblockA{Twentieth Century Fox\\
Springfield, USA\\
Email: [email protected]}
\and
\IEEEauthorblockN{Foo Bar\\
and Bar Foo}
\IEEEauthorblockA{Foo Academy\\
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}
\IEEEraisesectionheading{\section{Introduction}\label{sec:introduction}}
\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}
\IEEEraisesectionheading{\section{MORE TEXT}\label{sec:MORETEXT}}
\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}
注意:要正确编译此文件,您需要创建具有以下内容的文件 references.bib:
@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}}
结果:
答案2
添加选项transform canvas={scale=.5}
即可达到tikzpicture
目的。
\begin{tikzpicture}[>=latex,transform canvas={scale=.5}]