我已经使用 Tikz 创建了一个图形,但我不知道为什么在编译代码时它没有出现整个图形。
我的代码是:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{snakes}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}
\begin{tikzpicture}[x=2.5cm,nodes={text width=2.2cm,align=left}]
\draw[black,-,thick,>=latex,line cap=rect] (0,0) -- (4.5,0);
\foreach \Xc in {0,...,4}
{
\fill (\Xc,0) circle[radius=1.5pt];
}
\node[below=4pt,align=left,anchor=north,inner xsep=0pt,color=black]
at (0.05,0)
{Dueño elige un nivel de monitoreo $g\in[0,1]$};
\node[below=4pt,align=left,anchor=north,inner xsep=0pt]
at (1,0)
{Dueño diseña y ofrece un esquema de incentivos $w(x)$};
\node[below=4pt,align=left,anchor=north,inner xsep=0pt]
at (2.18,0)
{Gerente acepta o \quad rechaza};
\node[below=4pt,align=left,anchor=north,inner xsep=0pt]
at (3.2,0)
{Gerente elige una acción (no verificable) $a\in\lbrace m,s \rbrace$};
\node[below=4pt,align=left,anchor=north,inner xsep=0pt]
at (4.1,0)
{Monitoreo};
\draw[-,thick] (4.5,0) -- (5,1.5);
\node[above=4pt, rotate=50, align=center] at (4.75,0.5) {No detecta $(1-g)$};
\draw[-,thick] (4.5,0) -- (5,-1.5);
\node[below=8pt, rotate=-50, align=center] at (4.8,-0.5) {Detecta \qquad $(g)$};
\node[above right] at (5,-1.5) {$a=s$};
\draw[->,thick] (5,1.5) -- (7,1.5);
\node[below=4pt, align=left] at (6, 1.5) {Flujo de caja $x$ y beneficios $b$ son realizados. Compensación $w(x)$ es pagada.}
\filldraw (6,1.5) circle (1.5pt);
\draw[->,thick] (5,-1.5) -- (7,-1.5);
\node[below=4pt, align=left] at (6, -1.5) {Flujo de caja $x$ y beneficios $b$ son realizados. Compensación $w(x)$ es pagada.}
\filldraw (6,-1.5) circle (1.5pt);
\draw[->,thick] (5,-1.5) -- (5, -4);
\node[below, align=center] at (5,-4) {Gerente es despedido};
\node[right] at (5,-2.75) {$a=m$};
\end{tikzpicture}
\end{figure}
\end{document}
有人能帮我正确编译我的 tikz 图形吗?我需要它只出现在一个页面中并居中(使用\centering
after\begin{figure}
不起作用 :( )
谢谢!!!
答案1
考虑到@Schrödinger's cat 在评论中的建议,在节点后立即使用相对坐标监控器,获取的图像短于文本宽度:
(红线表示文本边框)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[x=12mm,
node distance = 1mm and 12mm,
N/.style = {text width=#1, inner xsep=0pt, align=left,
font=\small\linespread{0.84}\selectfont},
N/.default = 17mm,
dot/.style = {circle, fill, inner sep=1pt},
every path/.style ={thick, ,line cap=rect}
]
\foreach \x in {0,...,4}
\node (n\x) [dot] at (\x,0) {};
%
\begin{scope}[nodes={N}]
\node[below=of n0] {Dueño elige un nivel de monitoreo $g\in[0,1]$};
\node[above=of n1] {Dueño diseña y ofrece un esquema de incentivos $w(x)$};
\node[N=13mm,below=of n2] {Gerente acepta o rechaza};
\node[above=of n3] {Gerente elige una acción (no verificable) $a\in\{m,s\}$};
\node[N=15mm,below=of n4] {Monitoreo};
\end{scope}
\coordinate[right=of n4,] (n5);
\draw[->] (n0) -- (n5)
-- node[above, sloped] {Detecta $(1-g)$} ++ (45:2)
-- ++ (0:1.3) node (n6) [dot] {} -- ++ (0:1.3);
\node[N=24mm,
below=of n6] {Flujo de caja $x$ y beneficios $b$ son realizados.
Compensación $w(x)$ es pagada.};
%
\draw[->] (n5) -- node[below, sloped] {Detecta $(g)$} ++ (-45:2) coordinate (n7)
-- node[above] {$a=s$} ++ (0:1.3)
node (n8) [dot] {} -- ++ (0:1.3);
\node (n9) [N=24mm, below=of n8]
{Flujo de caja $x$ y beneficios $b$ son realizados.
Compensación $w(x)$ es pagada.};
%
\draw[->] (n7) -- node[left] {$a=m$} (n7 |- n9.south)
node[N,below] {Gerente es despedido};
\end{tikzpicture}
\end{figure}
\end{document}