使用以下代码
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{intersections,shapes,arrows,positioning}
\begin{document}
\tikzstyle{block} = [rectangle, draw,
text width=7em, text centered, rounded corners, minimum height=3em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse, node distance=4.5cm,
minimum height=2.5em]
\begin{figure}
\begin{tikzpicture}[node distance = 3cm,auto]
\node [block] (firm) {Bob's favorite $i$};
\node [cloud, right of= firm] (C) {country $A$};
\node [cloud, below right of=firm] (C') {Alice $B$};
\path [line, thick] (firm) -- node {t}(C');
\path [line, thick] (C') -- node {t}(C);
\path [line,dashed, very thick] (firm) -- node {t+1}(C);
\end{tikzpicture}
\hspace{1cm}% NO SPACE!
\begin{tikzpicture}[node distance = 3cm,auto]
\node [block] (firm) {Bob's favorite $i$};
\node [cloud, right of= firm] (C) {country $A$};
\node [cloud, below right of=firm] (C') {Alice $B$};
\path [line, thick] (firm) -- node {t}(C');
\path [line, thick] (C') -- node {t}(C);
\path [line,dashed, very thick] (firm) -- node {t+1}(C);
\end{tikzpicture}
\caption{Bob and Alice}
\end{figure}
\end{document}
我怎样才能使图形位于中心?
我有以下问题:
- 如果我
\centering
在figure
环境中使用,两张图片将会排成两行;但我想让它们并排放置。 - 我曾尝试重新调整图片大小这个答案确实如此。但我不知道在我的案例中将缩放参数放在哪里。
答案1
由于图像相对简单,我建议重新绘制它们。在此使用新的语法进行定位和样式定义。在重新绘制时,您实际上只需要更改一些参数,这将缩小图像宽度:
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows,
calc, % added
intersections, positioning, shapes}
\usepackage{showframe}
\begin{document}
\tikzset{ % changed from tikzstyle
block/.style = {rectangle, draw, rounded corners,
text width=4em, % reduced, now text is in two lines
minimum height=3em, align=center},
line/.style = {draw, thick, -latex'},
cloud/.style = {draw, ellipse, minimum height=2.5em, inner xsep=0pt}
}
\begin{figure}
\centering
\begin{tikzpicture}[
node distance = 2cm and 1.5cm, % changed (reduced)
auto]
\node [block] (firm) {Bob's favorite $i$};
\node [cloud, right=of firm] (C) {country $A$}; % new syntax according to positioning library
\node [cloud, below=of $(firm)!0.5!(C)$] (C') {Alice $B$}; % use of calc library
\path [line] (firm) -- node {t}(C');
\path [line] (C') -- node {t}(C);
\path [line,dashed, very thick] (firm) -- node {t+1} (C);
\end{tikzpicture}
\hfil % for distance between images
\begin{tikzpicture}[
node distance = 2cm and 1.5cm,
auto]
\node [block] (firm) {Bob's favorite $i$};
\node [cloud, right=of firm] (C) {country $A$};
\node [cloud, below=of $(firm)!0.5!(C)$] (C') {Alice $B$};
\path [line] (firm) -- node {t}(C');
\path [line] (C') -- node {t}(C);
\path [line,dashed, very thick] (firm) -- node {t+1} (C);
\end{tikzpicture}
\caption{Bob and Alice}
\end{figure}
\end{document}
的默认文本宽度article
非常窄。期刊或会议的边距通常要窄得多,小于 25 毫米。在这种情况下,您可以使用宽block
,例如在 MWE (7em) 中所使用的。