如果有人能帮助我解决以下问题,我将不胜感激。这是我的乳胶代码:
\documentclass[12pt]{report}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{verbatim}
\begin{document}
\tikzstyle{int}=[draw, line width = 1mm, minimum size=8em]
\begin{figure}
\centering
\begin{tikzpicture}[node distance=4.5cm,auto,>=latex']
\node [int] (a) {};
\node (b) [left of=a,node distance=5cm, coordinate] {a};
\node [int] (c) [] {$S$};
\node [coordinate] (end) [right of=c, node distance=5cm]{};
\path[->] (b) edge node {$\gamma$} (a);
\draw[->] (c) edge node {$\psi$} (end) ;
\end{tikzpicture}
\caption{This is a single compartment model}
\end{figure}
\end{document}
我对 tikz 还很陌生,我曾简要地看过 Till Tantau 撰写的 405 页文档。我不得不说,我甚至不知道从哪里开始。上面的代码是一个模板,我设法对其进行了编辑,以生成所见的图像。我不太明白每个代码的作用,而且我确信这里有些代码是不需要的。我想引入一个循环,箭头位于框下方,指向框后方(箭头上有一个标签:“z”)。我还想知道是否有人可以帮助将箭头加粗,甚至更大。
或者,如果有人可以指导我阅读 tikz 文档中的哪一页来回答这些问题,我将不胜感激。
谢谢
答案1
你可以
通过以下方式更改箭头的粗细
ultra thick
:\path[->, ultra thick, blue] (b) edge node {$\gamma$} (a);
或指定实际的
line width=
:\draw[->, line width=5pt, red] (c) edge node {$\psi$} (end) ;
使用语法绘制一个循环
to
(紫色箭头):\draw [violet, ultra thick, ->] ([xshift=-1.0cm]a.south) to[out=-120, in=-60, distance=2cm] ([xshift=1.0cm]a.south);
添加节点
\node
:\node [below=0.5cm] at (a.south) {$z$};
笔记:
- 最好使用
\tikzset
而\tikzstyle
不是应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?。
代码:
\documentclass[12pt]{report}
\usepackage{caption}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
%\tikzstyle{int}=[draw, line width = 1mm, minimum size=8em]
\tikzset{int/.style={draw, line width = 1mm, minimum size=8em}}
\begin{figure}
\centering
\begin{tikzpicture}[node distance=4.5cm,auto,>=latex']
\node [int] (a) {};
\node (b) [left of=a,node distance=5cm, coordinate] {a};
\node [int] (c) [] {$S$};
\node [coordinate] (end) [right of=c, node distance=5cm]{};
\path[->, ultra thick, blue] (b) edge node {$\gamma$} (a);
\draw[->, line width=5pt, red] (c) edge node {$\psi$} (end) ;
\draw [violet, ultra thick, ->]
([xshift=-1.0cm]a.south) to[out=-120, in=-60, distance=2cm] ([xshift=1.0cm]a.south);
\node [below=0.5cm] at (a.south) {$z$};
\end{tikzpicture}
\caption{This is a single compartment model}
\end{figure}
\end{document}
答案2
Mike Renfro 的回答略有修改。添加了关于所用样式的评论,并使用了所有样式。
\documentclass[12pt]{report}
\usepackage{tikz}
\usetikzlibrary{arrows} % TikZ libraries needed for
% drawing of TikZ pictures in document
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[% definition of own styles in picture
node distance = 5cm,% define distance between nodes and coordinates
auto, % placement od edge nodes
>=latex', % define type of arrow
int/.style = {draw, line width = 1mm, minimum size=4em}
]
\node[int] (a) {This is a text};% make a box with style "int"
% containing a text "This is a text%}
\coordinate[left of=a] (b); % define just a point at node distance left from the box
\coordinate[right of=a] (c); % similarly on the right side of the box
\path[->] (b) edge node {$\gamma$} (a) % left arrow with label $\gamma$
(a) edge node {$\psi$} (c); % right arrow
\end{tikzpicture}
\caption{This is a single compartment model}
\end{figure}
\end{document}
对于使用 TikZ 绘图来说,阅读完整章节“TikZ ist kein Zeichenprogramm”非常有帮助。
答案3
不完全是一个答案,但是我从 MWE 中删除了冗余或无关的部分并添加了一些评论:
\documentclass[12pt]{report}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
% define a style for a node (thick lined box, square if any included label is small enough)
\tikzstyle{int}=[draw, line width = 1mm, minimum size=4em]
\begin{figure}
\centering
\begin{tikzpicture}[node distance=4.5cm,auto,>=latex']
% make a thick lined box with a label
\node [int] (c) [] {This is a label};
% define a point to the left of the box, add a label for clarity, remove it when not needed
\node (b) [left of=c,node distance=5cm] {b};
% similarly, define a point to the right of the box
\node (end) [right of=c, node distance=5cm]{end};
% draw arrows from left to right, label them
\path[->] (b) edge node {$\gamma$} (c);
\path[->] (c) edge node {$\psi$} (end) ;
\end{tikzpicture}
\caption{This is a single compartment model}
\end{figure}
\end{document}
结果: