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.

I currently use TikZ matrix for arranging images and their nodes for putting some labels on the edges. Take a look at the attached image. For some reason, i am unable to shift connected paths. For example, i'd like to shift the vertical line to the left so that it does not cross tux A or tux B label. Yet, [xshift=] strangely, does not cause any shift.

Image Source misalignment

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}


\begin{document}

\begin{tikzpicture}[font=\sffamily\small,ampersand replacement=\&]
  \matrix [column sep=0mm,row sep=0mm,inner sep=0mm]{%
    \node(i1){\includegraphics{linux-pinguin.png}}; \&
    \node(i2){\includegraphics{linux-pinguin.png}};\\
    \node(i3){\includegraphics{linux-pinguin.png}}; \&
    \node(i4){\includegraphics{linux-pinguin.png}};\\
    \node(i5){\includegraphics{linux-pinguin.png}}; \&
    \node(i6){\includegraphics{linux-pinguin.png}};\\
};
 \node [rotate=90] at (i3.west) {tux B};
 \node [rotate=90] at (i5.west) {tux A};
 \draw [xshift=-2cm] (i5.south west) -- (i3.north west) node [rotate=90,midway,above] {benevolent};
 \draw (i2.north west) -- (i2.north east) node [midway,above] {1 col};
\end{tikzpicture}

\end{document}
share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

The coordinate transformation xshift (and similar) doesn’t apply to nodes (or their anchors).

But you can shift inside the coordinate specification:

\draw[green] ([shift={(-8mm,0mm)}] i5.south west) -- node [sloped,above] {benevolent}
             ([xshift=-8mm]        i3.north west);

This works without the calc library.

The canvas transformation does apply to nodes, but is a little bit trickier, for example it does not update the bounding box. Test the following example in the MWE posted below with xshift=-16mm) to see this yourself:

\draw[
    red,
    transform canvas={
        xshift=+5mm
    }
  ] (i5.south west) -- node [sloped,above] {benevolent} (i3.north west);

Check the PGF manual for more confusion (sections 22.3 “Coordinate Transformations” and 22.4 “Canvas Transformations”).


Though, in your instance, I would use a different approach to get the lines where you want them. Use the corners

  • (i3.north west -| tuxB.north) and
  • (tuxA.north |- i5.south west)

to place a line above the nodes.
The line has now the same space to the two smaller nodes as to its own node (you can check this with drawing the nodes).

Advantage: No messing around with some random distances, and it does move with the nodes if you are moving them around (see the following).

In the “1 col” example you drew a line from the upper corner and placed the node above it.

In the “tux A” and “tux B” case you placed the nodes directly at .west, i.e. at the image’s border, not above it. If you remove the % in front of the above you can see, how the “benevolent” line does move, too.

Code

\documentclass[tikz,border=2pt]{standalone}
\begin{document}
\begin{tikzpicture}[font=\sffamily\small,ampersand replacement=\&]
  \matrix [column sep=0mm,row sep=0mm,inner sep=0mm]{%
    \node(i1){\includegraphics{linux-pinguin.png}}; \&
    \node(i2){\includegraphics{linux-pinguin.png}};\\
    \node(i3){\includegraphics{linux-pinguin.png}}; \&
    \node(i4){\includegraphics{linux-pinguin.png}};\\
    \node(i5){\includegraphics{linux-pinguin.png}}; \&
    \node(i6){\includegraphics{linux-pinguin.png}};\\
  };

  \draw (i2.north west) -- (i2.north east) node [midway,above] {1 col};
  \node [rotate=90,
%    above
   ] at (i3.west) (tuxB) {tux B};
  \node [rotate=90,
%    above
   ] at (i5.west) (tuxA) {tux A};

  % without shifting:
  \draw (i3.north west -| tuxB.north) -- (tuxA.north |- i5.south west) node [rotate=90,midway,above] {benevolent};

  % with shifting A
  \draw[green] ([shift={(-8mm,0mm)}]i5.south west) -- node [sloped,above] {benevolent} ([xshift=-8mm]i3.north west);

  % with shifting B
  \draw[red,transform canvas={xshift=+5mm}] (i5.south west) -- node [sloped,above] {benevolent} (i3.north west);
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer
add comment

I have increased the inner sep so that you get some space around. You can use either xshift before rotate or yshift after rotate:

code

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}


\begin{document}

\begin{tikzpicture}[font=\sffamily\small,ampersand replacement=\&]
  \matrix [column sep=0mm,row sep=0mm,inner sep=0mm,inner sep=4mm]{%     %% inner sep here
    \node(i1){\includegraphics{linux-pinguin.png}}; \&
    \node(i2){\includegraphics{linux-pinguin.png}};\\
    \node(i3){\includegraphics{linux-pinguin.png}}; \&
    \node(i4){\includegraphics{linux-pinguin.png}};\\
    \node(i5){\includegraphics{linux-pinguin.png}}; \&
    \node(i6){\includegraphics{linux-pinguin.png}};\\
};
 \node [xshift=2mm,rotate=90,] at (i3.west) {tux B}; %% <--- Here
 \node [rotate=90,yshift=-2mm] at (i5.west) {tux A};  %% <--- and here
 \draw [xshift=-2cm] (i5.south west) -- (i3.north west) node [rotate=90,midway,above] {benevolent};
 \draw (i2.north west) -- (i2.north east) node [midway,above] {1 col};
\end{tikzpicture}

\end{document}

enter image description here

Another method

You can use calc library:

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}


\begin{document}

\begin{tikzpicture}[font=\sffamily\small,ampersand replacement=\&]
  \matrix [column sep=0mm,row sep=0mm,inner sep=0mm]{%     
    \node(i1){\includegraphics{linux-pinguin.png}}; \&
    \node(i2){\includegraphics{linux-pinguin.png}};\\
    \node(i3){\includegraphics{linux-pinguin.png}}; \&
    \node(i4){\includegraphics{linux-pinguin.png}};\\
    \node(i5){\includegraphics{linux-pinguin.png}}; \&
    \node(i6){\includegraphics{linux-pinguin.png}};\\
};
 \node [rotate=90,] at (i3.west) {tux B};
 \node [rotate=90] at (i5.west) {tux A}; 
 \draw ($(i5.south west)+(-2mm,0)$) -- ($(i3.north west)+(-2mm,0)$) node [rotate=90,midway,above] {benevolent};  %% <--- here
 \draw (i2.north west) -- (i2.north east) node [midway,above] {1 col};
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
Cool, i settled with the calc way as i have rectangular images that i want to connect seamlessly. Yet, it is still strange that whereas \tikz \draw (0,0) -- (0,0.5) [xshift=2pt] (0,0) -- (0,0.5); does work, xshift at the vertical path in my example does not. –  bioslime Dec 22 '12 at 2:53
add comment

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.