6

I am trying to put piece-wise functions into nodes in a Tikz diagram. Using cases works fine in a Tikz node that is separate within a tikzpicture environment. Putting the same node in a matrix breaks the use of & to divide a single line within the cases block.

Is there any way to get the output of the node inside the matrix to match that of the separate node?

Differences between nodes

\documentclass{article}

\usepackage{tikz, amsmath}

\usetikzlibrary{shapes, positioning}

\begin{document}
    \tikzstyle{block} = [draw, rectangle, align=center]

    \begin{tikzpicture}

    \node[block] (b1) {Separate node:\\
        \(
        u_{out}=
        \begin{cases}
        255 & \mbox{if } u_{in} > 255
        \end{cases}
        \)};

    \matrix[below=of b1] (m)
    {
        \node[block] (b2) {Node in matrix:\\
         \(
         u_{out}=
         \begin{cases}
         255 & \mbox{if } u_{in} > 255
         \end{cases}
         \)};\\
    };

    \end{tikzpicture}

\end{document}
4

Option ampersand replacement allows you to define which symbol to use instead of & in matrix environments. More detailed information in 20.5 Considerations Concerning Active Characters

\documentclass{article}

\usepackage{tikz, amsmath}

\usetikzlibrary{shapes, positioning}

\begin{document}
    \tikzstyle{block} = [draw, rectangle, align=center]

    \begin{tikzpicture}

    \node[block] (b1) {Separate node:\\
        \(
        u_{out}=
        \begin{cases}
        255 & \mbox{if } u_{in} > 255
        \end{cases}
        \)};

    \matrix[below=of b1, ampersand replacement=\&] (m)
    {
        \node[block] (b2) {Node in matrix:\\
         \(
         u_{out}=
         \begin{cases}
         255 & \mbox{if } u_{in} > 255
         \end{cases}
         \)};\\
    };

    \end{tikzpicture}

\end{document}

enter image description here

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.