Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The problem with the following MWE is that I don't understand why the text in the big node isn't aligned in the center (vertically speaking).

How can I do that?

Picture

enter image description here

MWE

\documentclass[
11pt
]{scrartcl}
\usepackage{
tikz,
relsize,
tgheros
}

\usetikzlibrary{
    calc,trees,shadows,positioning,arrows,chains,
    decorations.pathreplacing,
    decorations.pathmorphing,
    decorations.shapes,
    decorations.text,
    shapes,
    shapes.geometric,
    shapes.symbols,
    matrix,
    patterns,
    intersections,
    fit
}

\pgfdeclarelayer{background layer}
\pgfdeclarelayer{foreground layer}
\pgfsetlayers{background layer,main,foreground layer}

\tikzset{
    >=latex,
    line/.style={draw, thick, ->},
    phase/.style={
        align=left,
        anchor=center,
        rectangle,
        %drop shadow={opacity=0.5},
        %   minimum width=2cm,
        minimum height=1.0cm,
        %   text width=6cm,
        font=\sffamily\bfseries\small,
        draw=black,
        very thick,
        fill=black!40,
        %top color=white,
        %bottom color=white!20!blue
    },
    phasentext/.style={
        align=left,
        anchor=center,
        %node distance=0.5cm,
        rectangle,
        %drop shadow={opacity=0.5},
        %rounded corners, 
        minimum width=2cm,
        minimum height=1cm, 
        %   text width=7cm,
        draw=gray,
        very thick,
        %fill=black!20,
        %shade,
        font=\sffamily\small,
        %top color=white!80!black,
        %bottom color=white
    }
}

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\sffamily\small,node distance=0.5cm]
\matrix (Versuchsplan) [
matrix of nodes,
nodes in empty cells,
row sep=6mm,
column sep=3mm,
inner sep=7pt
] {
    %
    |[phase]| 1 & & & & \\
    & |[phasentext] (WordA)| Testa: \tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
    |[phasentext] (WordB)| Stuff: \tikz \draw[very thick, drop shadow] (0.2,0.1) rectangle (0.7,0.2); &
    |[phasentext] (WordC)| Stuff text word: \begin{tikzpicture} \draw[thick] (0,0) circle [radius=6pt]; \draw[thick,fill=black] (0,0) circle [radius=0.5pt]; \end{tikzpicture} &
    |[phasentext] (WordD)| Some more words: \begin{tikzpicture} \draw[thick] (0,0) circle [radius=6pt]; \draw[thick] (-3pt,-2pt) -- (3pt,-2pt) -- (0,2pt) -- cycle; \draw[thick] (0,2pt) -- (0,-2pt); \end{tikzpicture} \\
};
\node[phase, fit=(Versuchsplan-1-2)(Versuchsplan-1-5), align=left, anchor=center] (Words) {Longs text I suppose};
\end{tikzpicture}
\end{center}
\end{document}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

As mentioned in the PGF-TikZ Manual for version 3.0.0 (pag. 68 sec. 5.1), you have to manually adjust text height and text depth. In the following code I added red lines to highlight the correct vertical displacement.

\documentclass[
11pt
]{scrartcl}
\usepackage{
tikz,
relsize,
tgheros
}

\usetikzlibrary{
    calc,trees,shadows,positioning,arrows,chains,
    decorations.pathreplacing,
    decorations.pathmorphing,
    decorations.shapes,
    decorations.text,
    shapes,
    shapes.geometric,
    shapes.symbols,
    matrix,
    patterns,
    intersections,
    fit
}

\pgfdeclarelayer{background layer}
\pgfdeclarelayer{foreground layer}
\pgfsetlayers{background layer,main,foreground layer}

\tikzset{
    >=latex,
    line/.style={draw, thick, ->},
    phase/.style={text height=1.5ex,text depth=2ex,%<-- Here's the trick
        align=left,
        anchor=center,
        rectangle,
        %drop shadow={opacity=0.5},
        %   minimum width=2cm,
        minimum height=1.0cm,
        %   text width=6cm,
        font=\sffamily\bfseries\small,
        draw=black,
        very thick,
        fill=black!40,
        %top color=white,
        %bottom color=white!20!blue
    },
    phasentext/.style={
        align=left,
        anchor=center,
        %node distance=0.5cm,
        rectangle,
        %drop shadow={opacity=0.5},
        %rounded corners, 
        minimum width=2cm,
        minimum height=1cm, 
        %   text width=7cm,
        draw=gray,
        very thick,
        %fill=black!20,
        %shade,
        font=\sffamily\small,
        %top color=white!80!black,
        %bottom color=white
    }
}

    \begin{document}
    \begin{center}
    \begin{tikzpicture}[font=\sffamily\small,node distance=0.5cm]
    \matrix (Versuchsplan) [
    matrix of nodes,
    nodes in empty cells,
    row sep=6mm,
    column sep=3mm,
    inner sep=7pt
    ] {
        %
        |[phase] (1)| 1 & & & & \\
        & |[phasentext] (WordA)| Testa: \tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
        |[phasentext] (WordB)| Stuff: \tikz \draw[very thick, drop shadow] (0.2,0.1) rectangle (0.7,0.2); &
        |[phasentext] (WordC)| Stuff text word: \begin{tikzpicture} \draw[thick] (0,0) circle [radius=6pt]; \draw[thick,fill=black] (0,0) circle [radius=0.5pt]; \end{tikzpicture} &
        |[phasentext] (WordD)| Some more words: \begin{tikzpicture} \draw[thick] (0,0) circle [radius=6pt]; \draw[thick] (-3pt,-2pt) -- (3pt,-2pt) -- (0,2pt) -- cycle; \draw[thick] (0,2pt) -- (0,-2pt); \end{tikzpicture} \\
    };
    \node[phase, fit=(Versuchsplan-1-2)(Versuchsplan-1-5), align=left, anchor=center] (Words) {Longs text I suppose};
    \draw [red] let \p1=(1.base),
                           \p2=(Words.base)
                in (\x1,\y1) -- ++(5cm,0)
                   (\x2,\y2) -- ++(-5cm,0);
    \end{tikzpicture}
    \end{center}
    \end{document}

enter image description here

share|improve this answer
1  
Thanks. For anyone else: the code has to be added locally: \node[phase, fit=(Versuchsplan-1-2)(Versuchsplan-1-5), align=left, anchor=center, text height=1.5ex,text depth=2ex] (Words) {Longs text I suppose}; –  henry Apr 2 at 6:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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