0

I'd like to have the (big) node with Long text long text span from the very left of cell m-2-2 to the very right of cell m-2-5.

How can I achieve that?

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={
        text height=1.5ex,
        text depth=0.25ex,
        align=left,
        anchor=center,
        %   text width=6cm,
        font=\sffamily\bfseries\small,
        rectangle,
        minimum height=1.0cm,
        draw=black,
        very thick,
        fill=black!40
    },
    phasentext/.style={
        align=left,
        anchor=center,
        %node distance=0.5cm,
        rectangle,
        minimum width=2cm,
        minimum height=1cm, 
        %   text width=7cm,
        draw=gray,
        very thick,
        font=\sffamily\small
    }
}

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\sffamily\small,node distance=0.5cm]
\matrix (m) [
matrix of nodes,
nodes in empty cells,
row sep=6mm,
column sep=3mm,
inner sep=7pt
] {
    %
    |[phase]| 1 & & & & \\
    & |[phasentext] (WordA)| Test: \tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
    |[phasentext] (WordB)| Stuff:\tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
    |[phasentext] (WordC)| Stuff text word: \tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
    |[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=(m-1-2)(m-1-5), align=left, text height=1.5ex, text depth=0.25ex] (Words) {Long text I suppose};
\end{tikzpicture}
\end{center}
\end{document}

About the title: feel free to edit it if you can think of a better one.

3

enter image description here

This is your matrix before adding long text node and with empty nodes drawn. As you can see empty nodes are empty, i.e. just nothing with some inner sep.

And you can also see why fit=(m-1-2)(m-1-5) produces a shorter node than expected. But its size is the correct one, your expectation was wrong ;-)

A possible solution consists in using nodes WordA and WordD to fix long text node size but aligning it over first row.

\node[phase, fit=(WordA)(WordD), align=left, text height=1.5ex, text depth=0.25ex,
      anchor=west, inner sep=0pt] (Words) 
      at (m-1-1-|WordA.west) {\ Long text I suppose};

In previous line I've added \ (white space) before node's text because we need to fix inner sep=0pt for adjusting fitting node size.

The complete code is

\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=0.25ex,
        align=left,
        anchor=center,
        %   text width=6cm,
        font=\sffamily\bfseries\small,
        rectangle,
        minimum height=1.0cm,
        draw=black,
        very thick,
        fill=black!40
    },
    phasentext/.style={
        align=left,
        anchor=center,
        %node distance=0.5cm,
        rectangle,
        minimum width=2cm,
        minimum height=1cm, 
        %   text width=7cm,
        draw=gray,
        very thick,
        font=\sffamily\small
    }
}

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\sffamily\small,node distance=0.5cm]
\matrix (m) [
matrix of nodes,
nodes in empty cells,
row sep=6mm,
column sep=3mm,
inner sep=7pt,
] {
    %
    |[phase]| 1 & & & & \\
    & |[phasentext] (WordA)| Test: \tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
    |[phasentext] (WordB)| Stuff:\tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
    |[phasentext] (WordC)| Stuff text word: \tikz \draw[thick, circular glow={fill=gray}] (0,0) circle [radius=6pt]; &
    |[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=(WordA)(WordD), align=left, text height=1.5ex, text depth=0.25ex, anchor=west, inner sep=0pt] (Words) at (m-1-1-|WordA.west) {\ Long text I suppose};
\end{tikzpicture}
\end{center}
\end{document}

and the final result:

enter image description here

  • The inner space-option can be omitted, btw. Also, the option anchor=west is crucial as I have found out... – henry Apr 2 '14 at 9:26
  • @henry If you omit inner sep=0pt, long text node will be longer (by 2 x inner sep) than distance WordD.east - WordA.west. If you don't mind having a longer node, you can omit this correction. anchor=west is crucial here because it fixes the reference point for node. This node anchor will be placed where at fixes. – Ignasi Apr 2 '14 at 11:11

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.