4

Can I use TikZ's own tools to make a line break in the matrix cells or do I have to use a tabular-environment or a \parbox?

MWE (doesn't work, I included the faulty code)

\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=0ex,
        align=left,
        anchor=center,
        %   text width=6cm,
        font=\sffamily\bfseries\small,
        rectangle,
        minimum height=1.0cm,
        draw=black,
        very thick,
        fill=black!40
    }
}

\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]| This should include\\a line break\\
    |[phase], align=center| Here should be a line\\break as well.
};
\end{tikzpicture}
\end{center}
\end{document}
henry
  • 6,594

1 Answers1

3

The usual methods used to have a line break inside a tikz node can be applied here also. You can use text width=<dimesion> and if you want a break at some specified point, put a \\ there. But take care to hide it by using braces for otherwise it will be mistaken for the end of row.

\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=1.5ex,
        align=left,
        anchor=center,
           text width=6cm,
        font=\sffamily\bfseries\small,
        rectangle,
        minimum height=1.5cm,
        draw=black,
        very thick,
        fill=black!40
    }
}

\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]| {This should include\\a line break}\\
    |[phase, align=center]| {Here should be a line\\break as well}\\
};
\end{tikzpicture}
\end{center}
\end{document}

enter image description here