我有两个图表,除了另一个图表中有一条红线外,其余图表完全相同。但是,当它们作为两个子图包含在一个图中时subcapionbox
,带有红线的那个会缩小。
我对这个图的设置是:
\documentclass{article}
\usepackage{tikz}
\usepackage[margin = .5in]{geometry}
\usepackage{standalone}
\usepackage{subcaption}
\captionsetup[subfigure]{labelformat = parens, labelsep = space, font = small}
\newcounter{rowcount}
\newcounter{columncount}
\begin{document}
\begin{figure}
\centering
\subcaptionbox{Problem}{\includestandalone[width = 3in]{exam2prob5}}
\quad
\subcaptionbox{Solution}{\includestandalone[width = 3in]{exam2prob5sol}}
\end{figure}
\end{document}
我的两个独立文件是:
\documentclass{standalone}
\usepackage{tikz}
\newcounter{rowcount}
\newcounter{columncount}
\begin{document}
\begin{tikzpicture}[scale=2]
\begin{scope}[rotate=-45]
% rows
\foreach[count=\y from 0] \W in {% row-wise weights
{7,8,6},
{8,8,8},
{6,9,7},
{7,8,10}%
}{
\stepcounter{rowcount}
\foreach \w [count=\x, remember=\x as \lastx (initially 0)] in \W
\draw (\lastx,\y) -- (\x,\y)
node[above,pos=0.5] {\w};
}
% columns
\foreach[count=\x from 0] \W in {% column-wise weights
{5,6,10},
{7,10,5},
{10,5,6},
{7,9,11}%
}{
\stepcounter{columncount}
\foreach \w [count=\y, remember=\y as \lasty (initially 0)] in \W
\draw (\x,\lasty) -- (\x,\y)
node[above,pos=0.5] {\w};
}
\fill (0,0) circle (0.1em) node[below left] {A};
\fill ({\value{columncount}-1},{\value{rowcount}-1}) circle (0.1em) node[below right] {B};
\end{scope}
\end{tikzpicture}
\end{document}
和解决方案
\documentclass{standalone}
\usepackage{tikz}
\newcounter{rowcount}
\newcounter{columncount}
\begin{document}
\begin{tikzpicture}[scale=2]
\begin{scope}[rotate=-45]
% rows
\foreach[count=\y from 0] \W in {% row-wise weights
{7,8,6},
{8,8,8},
{6,9,7},
{7,8,10}%
}{
\stepcounter{rowcount}
\foreach \w [count=\x, remember=\x as \lastx (initially 0)] in \W
\draw (\lastx,\y) -- (\x,\y)
node[above,pos=0.5] {\w};
}
% columns
\foreach[count=\x from 0] \W in {% column-wise weights
{5,6,10},
{7,10,5},
{10,5,6},
{7,9,11}%
}{
\stepcounter{columncount}
\foreach \w [count=\y, remember=\y as \lasty (initially 0)] in \W
\draw (\x,\lasty) -- (\x,\y)
node[above,pos=0.5] {\w};
}
\fill (0,0) circle (0.1em) node[below left] {A};
\fill ({\value{columncount}-1},{\value{rowcount}-1}) circle (0.1em) node[below right] {B};
\draw[red, thick] (0, 0) -- (0, 2) -- (1, 2) -- (1, 3) -- (3, 3);
\end{scope}
\end{tikzpicture}
\end{document}
独立图像是对之前问题的回答我如何才能自动生成这个动态规划图?
我添加的红线是
\draw[red, thick] (0, 0) -- (0, 2) -- (1, 2) -- (1, 3) -- (3, 3);
pdf 生成:
如果我注释掉第一个subcaptionbox
,那么第二个图像就是常规大小。
此外,还有可供两张图片使用的空间:
答案1
较小的 MWE:
\documentclass{article}
\usepackage{standalone}
\usepackage{tikz}
\newcounter{rowcount}
\newcounter{columncount}
\begin{document}
\includestandalone[width=3in]{exam2prob5}
\includestandalone[width=3in]{exam2prob5sol}
\end{document}
所包含文件的序言.tex
是不是当它被嵌入时执行\includestandalone
。在更新的问题中,您现在添加了缺失的行
\usepackage{tikz}
\newcounter{rowcount}
\newcounter{columncount}
到主文件。
这些文档exam2prob5(sol).tex
使用全局资源,计数器rowcount
和columncount
。它们是不是图像之后重置,因此第二个包含的文档使用值4
而不是0
两个计数器。这些计数器会影响 TikZ 绘图的大小。
因此,有两种修复方法:
exam2prob5(sol).tex
在环境启动时重置文件内的计数器tikzpicture
:\begin{tikzpicture}[scale=2] \setcounter{rowcount}{0} \setcounter{columncount}{0}
或者在包含的文档之间的主文件中执行此操作:
\subcaptionbox{Problem}{\includestandalone[width = 3in]{exam2prob5}} \quad \setcounter{rowcount}{0}% \setcounter{columncount}{0}% \subcaptionbox{Solution}{\includestandalone[width = 3in]{exam2prob5sol}}