我使用 matlab2tikz 将两个 matlab 图像转换为 .tex 文件,第一个图像生成了以下代码:
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\definecolor{mycolor3}{rgb}{0.92900,0.69400,0.12500}%
%
\begin{tikzpicture}
\begin{axis}[%
width=4.521in,
height=3.566in,
at={(0.758in,0.481in)},
scale only axis,
xmode=log,
xmin=1,
xmax=1023,
xminorticks=true,
ymode=log,
ymin=0.000605918006841938,
ymax=1,
yminorticks=true,
axis background/.style={fill=white},
title style={font=\bfseries},
title={$\text{Mesh uniforme, }\alpha\text{ = 5/3}$},
legend style={legend cell align=left, align=left, draw=white!15!black}
]
\addplot [color=mycolor1, mark=asterisk, mark options={solid, mycolor1}]
table[row sep=crcr]{%
3 0.139792014524203\\
7 0.072479842055017\\
15 0.0370157945331386\\
31 0.0187746232975879\\
63 0.00948601785348729\\
127 0.00478085586105112\\
255 0.00240517988982091\\
511 0.00120838462520132\\
1023 0.000606477293609539\\
};
\addlegendentry{Quadratura}
\addplot [color=mycolor2, mark=asterisk, mark options={solid, mycolor2}]
table[row sep=crcr]{%
3 0.138651919621344\\
7 0.0720316322486566\\
15 0.036847197754512\\
31 0.0187112162712767\\
63 0.00946188033580206\\
127 0.00477154931108847\\
255 0.00240155605217295\\
511 0.00120696404181309\\
1023 0.000605918006841938\\
};
\addlegendentry{Calcolo esatto}
\addplot [color=mycolor3, dashed]
table[row sep=crcr]{%
3 0.25\\
7 0.125\\
15 0.0625\\
31 0.03125\\
63 0.015625\\
127 0.0078125\\
255 0.00390625\\
511 0.001953125\\
1023 0.0009765625\\
};
\addlegendentry{h}
\end{axis}
\begin{axis}[%
width=5.833in,
height=4.375in,
at={(0in,0in)},
scale only axis,
xmin=0,
xmax=1,
ymin=0,
ymax=1,
axis line style={draw=none},
ticks=none,
axis x line*=bottom,
axis y line*=left
]
\end{axis}
\end{tikzpicture}%
这是第二张图片的结果
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\definecolor{mycolor3}{rgb}{0.92900,0.69400,0.12500}%
%
\begin{tikzpicture}
\begin{axis}[%
width=4.521in,
height=3.566in,
at={(0.758in,0.481in)},
scale only axis,
xmode=log,
xmin=1,
xmax=1023,
xminorticks=true,
ymode=log,
ymin=0.0009765625,
ymax=1,
yminorticks=true,
axis background/.style={fill=white},
title style={font=\bfseries},
title={$\text{Mesh uniforme, }\alpha\text{ = 10}$},
legend style={legend cell align=left, align=left, draw=white!15!black}
]
\addplot [color=mycolor1, mark=asterisk, mark options={solid, mycolor1}]
table[row sep=crcr]{%
3 0.197209957231232\\
7 0.125510101886693\\
15 0.0652111253628991\\
31 0.0328432469804731\\
63 0.0164486751222861\\
127 0.00822763156405254\\
255 0.00411422476433522\\
511 0.00205716341817707\\
1023 0.00102858808587584\\
};
\addlegendentry{Quadratura}
\addplot [color=mycolor2, mark=asterisk, mark options={solid, mycolor2}]
table[row sep=crcr]{%
3 0.153395370790933\\
7 0.112257863184386\\
15 0.0631720206082784\\
31 0.0325749327203\\
63 0.0164147037161947\\
127 0.00822337153398153\\
255 0.00411369183465216\\
511 0.00205709678865042\\
1023 0.00102857975676872\\
};
\addlegendentry{Calcolo esatto}
\addplot [color=mycolor3, dashed]
table[row sep=crcr]{%
3 0.25\\
7 0.125\\
15 0.0625\\
31 0.03125\\
63 0.015625\\
127 0.0078125\\
255 0.00390625\\
511 0.001953125\\
1023 0.0009765625\\
};
\addlegendentry{h}
\end{axis}
\begin{axis}[%
width=5.833in,
height=4.375in,
at={(0in,0in)},
scale only axis,
xmin=0,
xmax=1,
ymin=0,
ymax=1,
axis line style={draw=none},
ticks=none,
axis x line*=bottom,
axis y line*=left
]
\end{axis}
\end{tikzpicture}%
现在,我成功地按照以下说明在我的 Latex 主程序中显示了这两个图表:
\begin{figure}[h]
\centering
\input{Error_uniform_53}
\caption{Caption 1}
\label{fig:1}
\end{figure}
\begin{figure}[h]
\centering
\input{Error_uniform_10}
\caption{Caption 2}
\label{fig:2}
\end{figure}
Error_uniform_53
第一个 .tex 文件的名称在哪里Error_uniform_10
,第二个 .tex 文件的名称是什么。我想将这两个图表并排放置,我已经尝试使用 subfigure,但似乎不起作用,可能是因为 tikzpiucture。有人能帮帮我吗?
我在这里留下一个 MWE(记住我给包含图片的 .tex 文件起的名字):
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{graphicx, subfigure}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{caption}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\usepackage{tikz-cd}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}[h]
\centering
\input{Error_uniform_53}
\caption{Caption 1}
\label{fig:1}
\end{figure}
\begin{figure}[h]
\centering
\input{Error_uniform_10}
\caption{Caption 2}
\label{fig:2}
\end{figure}
\end{document}
答案1
好的,这里有一种方法可以做到。恐怕您需要重新制作生成的tikz
图片,因为如果不产生布局问题,您就无法\input
直接使用它们。即首先注释掉下面提到的部分。
我们来看一下。
前言
和你一起工作真是……令人讨厌。因此,这个在下面给出的上下文中工作,其中 ams-packages 仅适用于在内部创建的标题pgfplots
:
\documentclass[10pt,a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{caption}
需要包caption
,因为 minipage 不使用浮动环境。使用方式如下:
\captionof{figure}{Cap 2}\label{fig:2}
使用小页面
与@Zarko 提出的类似,结构如下:
\begin{minipage}{7cm}% ~~~ minipage 1 ~~~~~~~~~~
... // first drawing
\end{minipage}
\hfill
\begin{minipage}{7cm}% ~~~ minipage 2 ~~~~~~~~~~
... // second drawing
\end{minipage}
现在,我对minipage
环境的使用肯定可以得到改善,而这个环境是有效的。
让我们来看看戏剧性的一幕,生成的两个文件
简而言之,该代码在您想要的上下文中带来了一些不愉快的惊喜,尽管它们单独运行良好。因此,为了消除\input
它们,您需要稍微注释掉它们。下面的代码只是复制了两个部分,以更好地显示哪些是过时的,甚至会造成麻烦。
对布局、比例、定位进行毫无意义且具有反作用的改变;只需将其删除:
%width=4.521in,% <<< all these give unwanted shifts and scalings
%height=3.566in,
%at={(0.758in,0.481in)},
%scale only axis,
最后的这部分很疯狂,导致了更难以定位的问题;所以,摆脱它:
%\begin{axis}[% <<< these are simply not good
%width=5.833in,
%height=4.375in,
%at={(0in,0in)},
%scale only axis,
%xmin=0,
%xmax=1,
%ymin=0,
%ymax=1,
%axis line style={draw=none},
%ticks=none,
%axis x line*=bottom,
%axis y line*=left
%]
%\end{axis}
请检查每个生成的图表开头的这一行,您必须添加或修改它以进行缩放:
\begin{tikzpicture}[scale=.8,transform shape]
将此缩放因子与您用于小页面的宽度平衡。
结果+代码
\documentclass[10pt,a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{caption}
\begin{document}
% ~~~ using 2 minipage-environments, with a \hfill inbetween ~~~~~
\begin{minipage}{7cm}% ~~~ minipage 1 ~~~~~~~~~~
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\definecolor{mycolor3}{rgb}{0.92900,0.69400,0.12500}%
%
\begin{tikzpicture}[scale=.8,transform shape]
\begin{axis}[%
%width=4.521in,% <<< all these give unwanted shifts and scalings
%height=3.566in,
%at={(0.758in,0.481in)},
%scale only axis,
xmode=log,
xmin=1,
xmax=1023,
xminorticks=true,
ymode=log,
ymin=0.000605918006841938,
ymax=1,
yminorticks=true,
axis background/.style={fill=white},
title style={font=\bfseries},
title={$\text{Mesh uniforme, }\alpha\text{ = 5/3}$},
legend style={legend cell align=left, align=left, draw=white!15!black}
]
\addplot [color=mycolor1, mark=asterisk, mark options={solid, mycolor1}]
table[row sep=crcr]{%
3 0.139792014524203\\
7 0.072479842055017\\
15 0.0370157945331386\\
31 0.0187746232975879\\
63 0.00948601785348729\\
127 0.00478085586105112\\
255 0.00240517988982091\\
511 0.00120838462520132\\
1023 0.000606477293609539\\
};
\addlegendentry{Quadratura}
\addplot [color=mycolor2, mark=asterisk, mark options={solid, mycolor2}]
table[row sep=crcr]{%
3 0.138651919621344\\
7 0.0720316322486566\\
15 0.036847197754512\\
31 0.0187112162712767\\
63 0.00946188033580206\\
127 0.00477154931108847\\
255 0.00240155605217295\\
511 0.00120696404181309\\
1023 0.000605918006841938\\
};
\addlegendentry{Calcolo esatto}
\addplot [color=mycolor3, dashed]
table[row sep=crcr]{%
3 0.25\\
7 0.125\\
15 0.0625\\
31 0.03125\\
63 0.015625\\
127 0.0078125\\
255 0.00390625\\
511 0.001953125\\
1023 0.0009765625\\
};
\addlegendentry{h}
\end{axis}
%\begin{axis}[% <<< these are simply not good
%width=5.833in,
%height=4.375in,
%at={(0in,0in)},
%scale only axis,
%xmin=0,
%xmax=1,
%ymin=0,
%ymax=1,
%axis line style={draw=none},
%ticks=none,
%axis x line*=bottom,
%axis y line*=left
%]
%\end{axis}
\end{tikzpicture}%
\captionof{figure}{Cap 1}\label{fig:2}
\end{minipage}
\hfill
\begin{minipage}{7cm}% ~~~ minipage 2 ~~~~~~~~~~
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\definecolor{mycolor3}{rgb}{0.92900,0.69400,0.12500}%
%
\begin{tikzpicture}[scale=.8,transform shape]
\begin{axis}[%
%width=4.521in,
%height=3.566in,
%at={(0.758in,0.481in)},
%scale only axis,
xmode=log,
xmin=1,
xmax=1023,
xminorticks=true,
ymode=log,
ymin=0.0009765625,
ymax=1,
yminorticks=true,
axis background/.style={fill=white},
title style={font=\bfseries},
title={$\text{Mesh uniforme, }\alpha\text{ = 10}$},
legend style={legend cell align=left, align=left, draw=white!15!black}
]
\addplot [color=mycolor1, mark=asterisk, mark options={solid, mycolor1}]
table[row sep=crcr]{%
3 0.197209957231232\\
7 0.125510101886693\\
15 0.0652111253628991\\
31 0.0328432469804731\\
63 0.0164486751222861\\
127 0.00822763156405254\\
255 0.00411422476433522\\
511 0.00205716341817707\\
1023 0.00102858808587584\\
};
\addlegendentry{Quadratura}
\addplot [color=mycolor2, mark=asterisk, mark options={solid, mycolor2}]
table[row sep=crcr]{%
3 0.153395370790933\\
7 0.112257863184386\\
15 0.0631720206082784\\
31 0.0325749327203\\
63 0.0164147037161947\\
127 0.00822337153398153\\
255 0.00411369183465216\\
511 0.00205709678865042\\
1023 0.00102857975676872\\
};
\addlegendentry{Calcolo esatto}
\addplot [color=mycolor3, dashed]
table[row sep=crcr]{%
3 0.25\\
7 0.125\\
15 0.0625\\
31 0.03125\\
63 0.015625\\
127 0.0078125\\
255 0.00390625\\
511 0.001953125\\
1023 0.0009765625\\
};
\addlegendentry{h}
\end{axis}
%\begin{axis}[%
%width=5.833in,
%height=4.375in,
%at={(0in,0in)},
%scale only axis,
%xmin=0,
%xmax=1,
%ymin=0,
%ymax=1,
%axis line style={draw=none},
%ticks=none,
%axis x line*=bottom,
%axis y line*=left
%]
%\end{axis}
\end{tikzpicture}%
\captionof{figure}{Cap 2}\label{fig:2}
\end{minipage}
\end{document}