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'm trying to create a simple figure in which the tick labels will not line up properly, because the coordinate system is skewed. Here is the MWE code:

\documentclass[a4paper,twocolumn]{article}

\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning}

\begin{document}

\begin{figure}
    \begin{center}
        \begin{tikzpicture}
            \node[anchor=south west, inner sep=0] (image) at (0.3,0.2) {\includegraphics[width=0.8\columnwidth]{asmmodes}};
            \begin{scope}[x={(image.south east)},y={(image.north west)}]
                \draw (-0.02, 0.833) node [right]{1};
                \draw (-0.02, 0.5) node [right]{2};
                \draw (-0.02, 0.167) node [right]{3};
                \draw (0.07, -0.03) node [text centered,above]{-4};
                \draw (0.22, -0.03) node [text centered,above]{-2};
                \draw (0.37, -0.03) node [text centered,above]{-1};
                \draw (0.50, -0.03) node [text centered,above]{0};
                \draw (0.65, -0.03) node [text centered,above]{1};
                \draw (0.79, -0.03) node [text centered,above]{2};
                \draw (0.94, -0.03) node [text centered,above]{4};
                \draw (0.5, -0.03) node [text centered,below]{standard deviations};
                \draw (-0.04, 0.5) node [text centered]{\rotatebox{90}{first three model shape parameters}};
                \draw [thick,red] (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
            \end{scope}
        \end{tikzpicture}
    \end{center}
    \label{fig:asmmodes1}
\end{figure}

\end{document}

This gives me the following output: Example of issue

As you can see the tick labels are not lined up nicely because the coordinate system is skewed. I'm not sure what to do about this. Can someone help me out here?

share|improve this question
2  
Don't know why it happens, but looks like the coordinate system in the scope is a bit skewed, try adding \draw [thick,red] (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle; at the end of the scope and you'll see. –  Torbjørn T. Jun 6 at 21:52
    
You are correct, the coordinate system is indeed skewed. But why is that? –  Korijn Jun 6 at 21:58
2  
In your scope, you may try to fix the origin via shift={(0.3,0.2)}. –  Paul Gaborit Jun 6 at 22:28
2  
@PaulGaborit yes, that's the problem. Either fix the origin in the scope or change the position of the image node to (0,0) as in \node[anchor=south west, inner sep=0] (image) at (0,0) {\includegraphics[width=0.8\columnwidth]{asmmodes}};. You should write an answer. –  Gonzalo Medina Jun 6 at 22:31
    
@PaulGaborit Would you like to write an answer so I can mark it as accepted? Technically, you got it right first. –  Korijn Jun 7 at 12:51

3 Answers 3

up vote 2 down vote accepted

First problem: when you change x and y without changing the origin, your axis are not orthogonal. You have to shift the origin to image.south west.

Second problem: the anchors of image are not on the borders of the included image because outer sep is not null. You have to add outer sep=0 to remove this margin.

Instead of \rotatebox, you may use rotate option.

enter image description here

\documentclass[margin=1mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \node[anchor=south west, inner sep=0,outer sep=0] (image)
  at (0.3,0.2) {\includegraphics[width=0.8\columnwidth] {example-image-a}};
  \begin{scope}[
    shift=(image.south west),
    x={(image.south east)},y={(image.north west)}
    ]
    \draw (-0.02, 0.833) node [right]{1};
    \draw (-0.02, 0.5) node [right]{2};
    \draw (-0.02, 0.167) node [right]{3};
    \draw (0.07, -0.03) node [text centered,above]{-4};
    \draw (0.22, -0.03) node [text centered,above]{-2};
    \draw (0.37, -0.03) node [text centered,above]{-1};
    \draw (0.50, -0.03) node [text centered,above]{0};
    \draw (0.65, -0.03) node [text centered,above]{1};
    \draw (0.79, -0.03) node [text centered,above]{2};
    \draw (0.94, -0.03) node [text centered,above]{4};
    \draw (0.5, -0.03) node [text centered,below] {standard deviations};
    \draw (-0.04, 0.5) node [text centered,rotate=90] {first three model shape parameters};
  \end{scope}
\end{tikzpicture}
\end{document}
share|improve this answer

The issue is not actually the shifting though helps because it brings the coordinate system back into the orthogonal regular axis.

The problem is

\begin{scope}[x={(image.south east)},y={(image.north west)}]

which makes x and y unit vectors distorted because it's not exactly perpendicular due to, I guess(!), outer sep.

share|improve this answer

After trying out Paul and Gonzalo's suggestions, I was able to resolve the situation. I felt that Gonzalo's suggestion to move the image node back to (0, 0) was the one that actually solved the issue at the root of the problem. Therefore, I have changed the line describing the image node to the following:

\node[anchor=south west, inner sep=0] (image) at (0, 0) {\includegraphics[width=0.9\columnwidth]{asmmodes}};

This gives me the following (desired) result:

Issue resolved

Thanks for helping me out.

[Edit] PaulGaborit's answer actually solves the issue. My change (documented in this answer) only avoids the issue.

share|improve this answer
    
The person who answered the question asked me personally to write an answer. See Gonzalo's final comment on the question. –  Korijn Jun 6 at 23:57
    
Ah, I totally missed that. I'm sorry! Just trying to be a good citizen of TeX stackexchange. :) –  Korijn Jun 7 at 9:57
1  
PaulGaborit has kindly written an answer and I've marked it as the correct answer. –  Korijn Jun 8 at 12:05

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.