我使用该standalone
包并在单独的.tex
文件中创建我的 tikz 图片。我在我想要的章节中创建一个子图,当我编译时,main.tex
子图会被加载。我在下面创建了一个 MWE,显示了图形的大小不同。缩放将是一个问题,因为字体大小等不会相似。此外,当标题超过两行时,它会将子图向上推,这也不理想。
- 我怎样才能使所有子图的尺寸完全相同?
- 如果标题超过 2 行,如何才能使其不将子图向上推?
main.tex
\documentclass[8pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[subpreambles=true, mode=buildnew]{standalone}
\usepackage{subfiles}
\usepackage[margin=1.75cm]{geometry}
\usepackage{graphicx}
\begin{document}
\input{Introduction}
\end{document}
章节 tex -Introduction.tex
\documentclass{standalone}
\usepackage{subfiles}
\usepackage{pgfplots}
\usepackage[section]{placeins}
\usepackage{subcaption}
\usepackage[margin=1.75cm]{geometry}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{figure*}[ht]
\centering
\begin{subfigure}[b]{0.475\textwidth}
\centering
\includegraphics[width=\textwidth]{Figure1.tex}
\caption[Network2]%
{{\small ipsum lopem ipsum lopem ipsum lopem ipsum lopem ipsum lopem ipsum lopem ipsum lopem ipsum lopem }}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.475\textwidth}
\centering
\includegraphics[width=\textwidth]{Figure2.tex}
\caption[]%
{{\small ipsum lopem ipsum lopem}}
\end{subfigure}
\vskip\baselineskip
\begin{subfigure}[b]{0.475\textwidth}
\centering
\includegraphics[width=\textwidth]{Figure1.tex}
\caption[]%
{{\small ipsum lopem ipsum lopem}}
\end{subfigure}
\quad
\begin{subfigure}[b]{0.475\textwidth}
\centering
\includegraphics[width=\textwidth]{Figure2.tex}
\caption[]%
{{\small -1 days and +1 days}}
\end{subfigure}
\caption[ The average and standard deviation of critical parameters ]
{\small ipsum lopem ipsum lopem}
\label{fig:gammas}
\end{figure*}
\end{document}
图1 -Figure1.tex
\documentclass{standalone}
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\definecolor{blue1}{RGB}{0, 0, 108}
\definecolor{red1}{RGB}{108, 0, 0}
\begin{document}
\begin{filecontents*}{gammagroup1group4afterv2.txt}
days Group1 Group4
-120 0.16331143 0.390679728
-119 0.139611442 0.299897574
-118 0.166181107 0.336650007
\end{filecontents*}
\begin{tikzpicture}
\begin{axis}[
xlabel=ipsum lopem,
xmin=-120,xmax=-118,
ylabel= ipsum lopem
]
\addplot [mark=none,blue1] table [x=days,y=Group1] {gammagroup1group4afterv2.txt};
\addplot [mark=none,red1] table [x=days,y=Group4] {gammagroup1group4afterv2.txt};
\legend{high, low}
\end{axis}
\end{tikzpicture}
\end{document}
图 2Figure2.tex
\documentclass{standalone}
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\definecolor{blue1}{RGB}{0, 0, 108}
\definecolor{red1}{RGB}{108, 0, 0}
\begin{document}
\begin{filecontents*}{gammagroup1group4after.txt}
days Group1 Group4
-120 0.41168498 0.454667851
-119 0.405303768 0.438895231
-118 0.416069556 0.448782161
\end{filecontents*}
\begin{tikzpicture}
\begin{axis}[
xlabel=ipsum lopem ,
xmin=-120,xmax=-118,
ylabel= ipsum lopem
]
\addplot [mark=none,blue1] table [x=days,y=Group1] {gammagroup1group4after.txt};
\addplot [mark=none,red1] table [x=days,y=Group4] {gammagroup1group4after.txt};
\legend{high, low}
\end{axis}
\end{tikzpicture}
\end{document}
下面是最终结果的图片;你可以看到,不同图之间的子图大小不一样+左上角的子图由于标题而被推高。
答案1
由于某些奇怪的原因,使用 [scale only axis] 弄乱了 xticks(可以修复)。另一方面,这本身似乎已经足够好了。
此外,您需要坚持使用\hfill
或\quad
,而不是交替使用。
图1.tex
\documentclass{standalone}
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\definecolor{blue1}{RGB}{0, 0, 108}
\definecolor{red1}{RGB}{108, 0, 0}
\begin{document}
\begin{filecontents*}{gammagroup1group4afterv2.txt}
days Group1 Group4
-120 0.16331143 0.390679728
-119 0.139611442 0.299897574
-118 0.166181107 0.336650007
\end{filecontents*}
\begin{tikzpicture}
\begin{axis}[scale only axis,
xtick={-120, -119.5, -119, -118.5, -118},
xlabel=ipsum lopem,
xmin=-120,xmax=-118,
ylabel= ipsum lopem
]
\addplot [mark=none,blue1] table [x=days,y=Group1] {gammagroup1group4afterv2.txt};
\addplot [mark=none,red1] table [x=days,y=Group4] {gammagroup1group4afterv2.txt};
\legend{high, low}
\end{axis}
\end{tikzpicture}
\end{document}
图2.tex
\documentclass{standalone}
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\definecolor{blue1}{RGB}{0, 0, 108}
\definecolor{red1}{RGB}{108, 0, 0}
\begin{document}
\begin{filecontents*}{gammagroup1group4after.txt}
days Group1 Group4
-120 0.41168498 0.454667851
-119 0.405303768 0.438895231
-118 0.416069556 0.448782161
\end{filecontents*}
\begin{tikzpicture}
\begin{axis}[scale only axis,
xtick={-120, -119.5, -119, -118.5, -118},
xlabel=ipsum lopem ,
xmin=-120,xmax=-118,
ylabel= ipsum lopem
]
\addplot [mark=none,blue1] table [x=days,y=Group1] {gammagroup1group4after.txt};
\addplot [mark=none,red1] table [x=days,y=Group4] {gammagroup1group4after.txt};
\legend{high, low}
\end{axis}
\end{tikzpicture}
\end{document}