Graphics, Figures & TablesTikz multiline matrix

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
reisgabrieljoao
Posts: 5
Joined: Sat Sep 26, 2009 6:11 am

Tikz multiline matrix

Post by reisgabrieljoao »

Is it possible to create a multiline node in a Tikz matrix? If yes, how?

Thanks in advance.
Last edited by reisgabrieljoao on Thu Oct 28, 2010 11:32 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Tikz multiline matrix

Post by localghost »

Very simple after specifying a text width for the node.

Code: Select all

\documentclass{minimal}
\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}
    \draw (0,0) node[text width=4cm] {The quick brown fox jumps over the lazy dog.};
  \end{tikzpicture}
\end{document}
However, the line wrapping might be insufficient.

For more specific help it requires a minimal example.


Thorsten
reisgabrieljoao
Posts: 5
Joined: Sat Sep 26, 2009 6:11 am

Tikz multiline matrix

Post by reisgabrieljoao »

Well, I'll try to explain myself a little better. What I meant was that I wanted a node to occupy 2 lines, not its text. Here's a minimal example:

Code: Select all

\documentclass{minimal}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
        \matrix {
            & \node (node1) [draw] {Node number 1}; \\
            \node (node2) [draw, minimum height=3em] {Node number 2}; & \node (node3) [draw] {Node number 3}; \\
        };
    \end{tikzpicture}
\end{document}
I want that node 2 occupies 2 lines (the first and the second) so that node 1 and 3 get aligned with it.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Tikz multiline matrix

Post by gmedina »

You could use the fit library:

Code: Select all

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{fit}

\begin{document}

\begin{tikzpicture}
\matrix {
  \node (node0) {\phantom{Node number 2}}; & \node[draw] (node1) {Node number 1};\\
  \node (node2) {\phantom{Node number 2}}; & \node [draw] (node3) {Node number 3};\\
 };
 \node[draw, fit = (node0) (node2),inner sep=0pt] {Node number 2};
\end{tikzpicture}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
reisgabrieljoao
Posts: 5
Joined: Sat Sep 26, 2009 6:11 am

Re: Tikz multiline matrix

Post by reisgabrieljoao »

Seems that it solved my problem, thank you very much.
Post Reply