0

I have the following code:

\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}

Output:

enter image description here

As you can see, "Initialisation" and "Running" are not correctly aligned horizontally. How can I change that ? Thank you.

1
  • for start try add \vphantom{g} to text in the first node. than see, where you to nodes style definition can add text depth=0.5ex.
    – Zarko
    Jul 3 '18 at 9:38
1

Your question is closely related to this one: How to align text in TikZ nodes by baseline?

You could simply add \struts to your text (e.g. Initialisation\strut). Or, as mentioned by Zarko and also in answers of the linked question, you could add text depth=... and text height=... to your block style. I would recommend the \strut depth and height:

text depth=.3\baselineskip,
text height=.7\baselineskip

You could try other values or the other possibilities of Qrrbrbirlbel's answer in the linked question.

MWE with the latter solution:

\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}

Producing:

result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.