我试图让我的子图处于同一条线上。
现在我成功使用 subfigure 和 TikZ 包得到了图 1 (a) 和图 1. (b)。
但是,无论我怎么尝试,它们都是一个叠在另一个之上的。我希望这两个子图并排。
\documentclass{article}
\usepackage{subfigure,tikz}
\usetikzlibrary{backgrounds,automata}
\begin{document}
\begin{figure}
\centering
\subfigure[Before]
{%
\begin{tikzpicture}[show background rectangle, scale=.5]
\draw[rounded corners=5pt] (0,0) rectangle (6,8);
\draw[rounded corners=5pt] (1,2) rectangle (5,6);
\draw [dashed] (3,2) to[line to] (3,6);
\node[state] (a) at (3,7) {$a$};
\node[state] (b_x) at (2,5) {$b_x$};
\node[state] (b_y) at (4,5) {$b_y$};
\node[state] (c_x) at (2,3) {$c_x$};
\node[state] (c_y) at (4,3) {$c_y$};
\node[state] (d) at (3,1) {$d$};
\draw (1.25,5.75) node {$x$};
\draw (3.25,5.75) node {$y$};
\draw (0.25,7.75) node {$z$};
\end{tikzpicture}
}
\subfigure[After]
{%
\begin{tikzpicture}[show background rectangle, scale = 0.5]
\draw[rounded corners=5pt] (0,0) rectangle (4,8);
\draw [dashed] (2,0) to[line to] (2,8);
\node[state] (a_x) at (1,7) {$a_x$};
\node[state] (a_y) at (3,7) {$a_y$};
\node[state] (b_x) at (1,5) {$b_x$};
\node[state] (b_y) at (3,5) {$b_y$};
\node[state] (c_x) at (1,3) {$c_x$};
\node[state] (c_y) at (3,3) {$c_y$};
\node[state] (d_x) at (1,1) {$d_x$};
\node[state] (d_y) at (3,1) {$d_y$};
\draw (0.25,7.75) node {$x$};
\draw (2.25,7.75) node {$y$};
\end{tikzpicture}
}
\caption{An example of the procedure} \end{figure}
\end{document}
答案1
编辑:看过 MWE 后,问题在于您在图形之间放置了一个空行。LaTeX 将此解释为换行符,然后断开该行。
删除第二张图片前的空行就可以了。
这是有效的代码:
\documentclass{article}
\usepackage{tikz}
\usepackage{subfigure}
\usetikzlibrary{backgrounds,automata}
\begin{document}
\begin{figure}
\centering
\subfigure[Before]
{
\begin{tikzpicture}[show background rectangle, scale=.5]
\draw[rounded corners=5pt] (0,0) rectangle (6,8);
\draw[rounded corners=5pt] (1,2) rectangle (5,6);
\draw [dashed] (3,2) to[line to] (3,6);
\node[state] (a) at (3,7) {$a$};
\node[state] (b_x) at (2,5) {$b_x$};
\node[state] (b_y) at (4,5) {$b_y$};
\node[state] (c_x) at (2,3) {$c_x$};
\node[state] (c_y) at (4,3) {$c_y$};
\node[state] (d) at (3,1) {$d$};
\draw (1.25,5.75) node {$x$};
\draw (3.25,5.75) node {$y$};
\draw (0.25,7.75) node {$z$};
\end{tikzpicture}
}
% The only difference is here, where I have commented out an empty line.
\subfigure[After]
{
\begin{tikzpicture}[show background rectangle, scale = 0.5]
\draw[rounded corners=5pt] (0,0) rectangle (4,8);
\draw [dashed] (2,0) to[line to] (2,8);
\node[state] (a_x) at (1,7) {$a_x$};
\node[state] (a_y) at (3,7) {$a_y$};
\node[state] (b_x) at (1,5) {$b_x$};
\node[state] (b_y) at (3,5) {$b_y$};
\node[state] (c_x) at (1,3) {$c_x$};
\node[state] (c_y) at (3,3) {$c_y$};
\node[state] (d_x) at (1,1) {$d_x$};
\node[state] (d_y) at (3,1) {$d_y$};
\draw (0.25,7.75) node {$x$};
\draw (2.25,7.75) node {$y$};
\end{tikzpicture}
}
\caption{An example of the procedure}
\end{figure}
\end{document}
后人的旧答案:
如果没有平均能量损失很难确切知道问题是什么。尝试缩小 tikz 图片,看看它们是否适合一条线。也就是说,让您的 tikz 图形开始:\begin{tikzpicture}[scale=0.5]
如果完成此操作后它们可以放在一条线上,那么接下来就是找到可以给它们的最大比例并让它们放在一条线上。如果这不是问题,那么你需要更详细地回答你的问题。
答案2
一个例子 :
\documentclass{scrartcl}
\usepackage{tkz-euclide,subfigure}
\usetkzobj{all}
\begin{document}
\begin{figure}[!h]
\centering
\subfigure[angle:\hbox to 2cm{\dotfill}]{
\begin{tikzpicture}
\draw ( 2,3)+(158:4cm) -- ( 2,3) -- +(31:4cm);
\tkzOriProtractor[scale=0.7, shift = {(2,3)}, rotate = -22]
\end{tikzpicture}}
\hfill
\subfigure[angle:\hbox to 2cm{\dotfill}]{
\begin{tikzpicture}
\def\ang{53}
\draw ( 2,3)+(180-\ang:4cm) -- ( 2,3) -- +(31:4cm);
\tkzOriProtractor[shift = {(2,3)}, scale=0.7, rotate = 31]
\end{tikzpicture}}
\end{figure}
\end{document}