我有以下代码:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}
\begin{document}
\tikzset{
desicion/.style={
diamond,
draw,
text width=4em,
text badly centered,
inner sep=0pt
},
block/.style={
rectangle,
draw,
text width=10em,
text centered,
rounded corners
},
cloud/.style={
draw,
ellipse,
minimum height=2em
},
descr/.style={
fill=white,
inner sep=2.5pt
},
connector/.style={
-latex,
font=\scriptsize
},
rectangle connector/.style={
connector,
to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
pos=0.5
},
rectangle connector/.default=-2cm, straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes}
}
\begin{figure}[htpb]
\begin{center}
\begin{tikzpicture}
\def\x{1.5}
\node [block] (init) {Initialisation};
\node [block, right = 3cm of init] (running) {Running};
\draw[->] (init) -- (running);
\end{tikzpicture}
\end{center}
\caption{Fonctionnement du programme.}
\label{fig:svnfm-main-flow}
\end{figure}
\end{document}
输出:
如您所见,“初始化”和“运行”未正确水平对齐。我该如何改变这种情况?谢谢。
答案1
您的问题与这个问题密切相关:如何按基线对齐 TikZ 节点中的文本?
您可以简单地将\strut
s 添加到文本中(例如Initialisation\strut
)。或者,正如 Zarko 以及链接问题的答案中所述,您可以将text depth=...
and添加text height=...
到block
样式中。我建议\strut
深度和高度:
text depth=.3\baselineskip,
text height=.7\baselineskip
您可以尝试其他值或链接问题中 Qrrbrbirlbel 的答案的其他可能性。
MWE 采用后一种解决方案:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}
\begin{document}
\tikzset{
desicion/.style={
diamond,
draw,
text width=4em,
text badly centered,
inner sep=0pt
},
block/.style={
rectangle,
draw,
text width=10em,
text centered,
rounded corners,
text depth=.3\baselineskip,
text height=.7\baselineskip
},
cloud/.style={
draw,
ellipse,
minimum height=2em
},
descr/.style={
fill=white,
inner sep=2.5pt
},
connector/.style={
-latex,
font=\scriptsize
},
rectangle connector/.style={
connector,
to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
pos=0.5
},
rectangle connector/.default=-2cm, straight connector/.style={
connector,
to path=--(\tikztotarget) \tikztonodes}
}
\begin{figure}[htpb]
\begin{center}
\begin{tikzpicture}
\def\x{1.5}
\node [block] (init) {\rlap{\rule{9cm}{.5pt}}Initialisation};
\node [block, right = 3cm of init] (running) {Running};
\draw[->] (init) -- (running);
\end{tikzpicture}
\end{center}
\caption{Fonctionnement du programme.}
\label{fig:svnfm-main-flow}
\end{figure}
\end{document}
制作: