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.

Inspired by http://tex.stackexchange.com/questions/3892/ I created my own snake like diagram (see below).

The entries are rather large and the figure thus too wide. My question is: Why does the figure start only almost in the middle of the page and not on the left-hand side? Why is there so much free space on the left?

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows}

\begin{document}
\begin{tikzpicture}[descr/.style={fill=white,inner sep=1.5pt}]
        \matrix (m) [
            matrix of math nodes,
             row sep=1em,
             column sep=2em,
        ]
        { Q_{5}\oplus\bigoplus_{i\in\{1,2,3,4\}} Q_{12345\setminus i}[1] &
        \bigoplus_{l\in\{1,2,3,4\}} Q_{l5}\oplus Q_{12345}[1] &
        \bigoplus_{j\neq k\in\{1,2,3,4\}} Q_{jk5} \\
          \ bigoplus_{i\in\{1,2,3,4\}} Q_{12345\setminus i} &
        Q_{12345} &
        S_{12345} \\
        };
        \path[->, font=\scriptsize,>=latex]
        (m-1-1) edge (m-1-2)
        (m-1-2) edge (m-1-3)
        (m-1-3) edge[out=355,in=175] (m-2-1)
    (m-2-1) edge (m-2-2)
        (m-2-2) edge (m-2-3);
\end{tikzpicture}
\end{document}
share|improve this question
    
Also, please help me to get my code block rendered appropriately! Thanks in advance! –  Rasmus Oct 28 '10 at 12:39
    
Fixed. For future reference: To insert a block of code, you can either pre-indent each line by 4 spaces, or, after entering the block, highlight the block and click on the "101010" symbol above the TextField. –  Willie Wong Oct 28 '10 at 12:45
    
@Willie Wong: Thank you for your help! –  Rasmus Oct 28 '10 at 14:13

3 Answers 3

up vote 8 down vote accepted

Something about the curvy edge is increasing the bounding box by a lot. This could be considered a bug. To cancel that effect, add overlay to the options for the \path which draws the arrows.

You might also consider using \limits for your \bigopluses and \mathclap (reference) to get the subscripts taking up less space. Here's my version:

\def\mathclap{\mathpalette\mathclapinternal}
\def\mathclapinternal#1#2{\clap{$\mathsurround=0pt#1{#2}$}}
\let\oldbigoplus=\bigoplus
\def\bigoplus{\oldbigoplus\limits}

\begin{tikzpicture}[remember picture=true]
        \matrix (m) [
            matrix of math nodes,
             row sep=1em,
             column sep=2em,
             text height=1.5ex, text depth=0.25ex
        ]
        {Q_{5}\oplus\bigoplus_{\mathclap{i\in\{1,2,3,4\}}} Q_{12345\setminus i}[1] &
        \bigoplus_{\mathclap{l\in\{1,2,3,4\}}} Q_{l5}\oplus Q_{12345}[1] &
        \bigoplus_{\mathclap{j\neq k\in\{1,2,3,4\}}} Q_{jk5} \\
          \bigoplus_{\mathclap{i\in\{1,2,3,4\}}} Q_{12345\setminus i} &
        Q_{12345} &
        S_{12345} \\
        };
        \path[overlay,->, font=\scriptsize,>=latex]
        (m-1-1) edge (m-1-2)
        (m-1-2) edge (m-1-3)
        (m-1-3) edge[out=348,in=172] (m-2-1)
        (m-2-1) edge (m-2-2)
        (m-2-2) edge (m-2-3);
\end{tikzpicture}

diagram

PS: Your descr/.style=... declaration has no effect unless you are actually applying the style to something. So you can cut that out for minimal example purposes.

Edit: I have incorporated @Caramdir's suggested edits.

share|improve this answer
    
Beautiful! Thank you very much! –  Rasmus Oct 28 '10 at 15:16
2  
I'm not 100% sure, but my guess would be that the control points for the Bezier curve making up the snake path were what were enlarging the picture. –  Antal S-Z Oct 28 '10 at 16:18
    
@Antal: good guess. –  Matthew Leingang Oct 28 '10 at 20:31

Some additional small improvements on Matthew's version: In the original example I removed text height=1.5ex, text depth=0.25ex which I usually add to center the arrows on complicated the text. However, it is necessary here. Also the starting and ending directions of the curved arrow need to be tweaked a little bit:

\documentclass{article}
\usepackage{tikz,mathtools} %mathtools provides \mathclap
\usetikzlibrary{matrix,arrows}

\let\oldbigoplus=\bigoplus
\def\bigoplus{\oldbigoplus\limits}

\begin{document}

\begin{tikzpicture}
        \matrix (m) [
            matrix of math nodes,
            row sep=2.5em,
            column sep=2em,
            text height=1.5ex, text depth=0.25ex
        ]
        {Q_{5}\oplus\bigoplus_{\mathclap{i\in\{1,2,3,4\}}} Q_{12345\setminus i}[1] &
        \bigoplus_{\mathclap{l\in\{1,2,3,4\}}} Q_{l5}\oplus Q_{12345}[1] &
        \bigoplus_{\mathclap{j\neq k\in\{1,2,3,4\}}} Q_{jk5} \\
          \bigoplus_{\mathclap{i\in\{1,2,3,4\}}} Q_{12345\setminus i} &
        Q_{12345} &
        S_{12345} \\
        };

        \path[overlay,->, font=\scriptsize,>=latex]
        (m-1-1) edge (m-1-2)
        (m-1-2) edge (m-1-3)
        (m-1-3) edge[out=348,in=172] (m-2-1)
        (m-2-1) edge (m-2-2)
        (m-2-2) edge (m-2-3);
\end{tikzpicture}
\end{document}

rendered code

share|improve this answer
    
Nice. I thought about moving the arrows up to align with the center of the opluses but didn't know how best to do it. –  Matthew Leingang Oct 29 '10 at 12:13
    
@Matthew: I favor using the mid east and mid west anchors for this purpose, which eliminates dimension-guessing but requires me to put anchors in just about every coordinate. I wonder if there is an edge style that can do this? –  Ryan Reich Apr 25 '11 at 23:51

It is most definitely the curvy path which is pushing things out. To see this, you can draw the bounding box at a particular point by writing:

\draw (current bounding box.north west) rectangle (current bounding box.south east);

at appropriate junctures, say after the \matrix and after the \path commands. Note that this draws the current bounding box so putting it at different places shows how the bounding box changes during the diagram.

As an alternative solution, the \useasboundingbox sets the bounding box for the picture. To be accurate, it means that as far as the bounding box is concerned everything after this command gets ignored. So putting it after the matrix command but before the path command means that the matrix gets used for the bounding box but the path doesn't. Thus my soution:

\documentclass{article}
\thispagestyle{empty}
\usepackage[scale=.96]{geometry}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows}

\begin{document}
\begin{tikzpicture}
        \matrix (m) [
            matrix of math nodes,
             row sep=2em,
             column sep=2em,
        ]
        { Q_{5}\oplus\bigoplus_{i\in\{1,2,3,4\}} Q_{12345\setminus i}[1] &
        \bigoplus_{l\in\{1,2,3,4\}} Q_{l5}\oplus Q_{12345}[1] &
        \bigoplus_{j\neq k\in\{1,2,3,4\}} Q_{jk5} \\
          \bigoplus_{i\in\{1,2,3,4\}} Q_{12345\setminus i} &
        Q_{12345} &
        S_{12345} \\
        };
        \useasboundingbox (0,0);
        \path[->, font=\scriptsize,>=latex]
        (m-1-1) edge (m-1-2)
        (m-1-2) edge (m-1-3)
        (m-1-3) edge[out=355,in=175] (m-2-1)
    (m-2-1) edge (m-2-2)
        (m-2-2) edge (m-2-3);
\end{tikzpicture}
\end{document}

The effect of the overlay tag is similar. That tag removes the path from the bounding box consideration, whereas the \useasboundingbox removes everything after it (but not including itself).

share|improve this answer

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.