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 want to set tick labels of positive numbers to occupy the same space as negative numbers for alignment of 'ylabel'. I want to avoid absolute setting of location since I have other concerns not to do that. I would like to align the axis, is there any way to set a 'y tick label' to occupy same space with the case when there is a negative sign there. Can I add a hidden negative tick label ?

\documentclass[]{article}

    \usepackage{tikz}
    \usepackage{pgf,pgfplots}
    \pgfplotsset{compat=newest}
    \pgfplotsset{
    compat=newest,
    plot coordinates/math parser=false,
    every axis/.append style={
        xlabel shift=0.5em,
        ylabel shift=-0.5em
    }}
\begin{document}


\begin{tikzpicture}
    \begin{axis}[%
        xlabel={XLABEL},
        ylabel={YLABEL},
        axis lines*=left]
        \addplot+[mark=none] plot {x};
    \end{axis}
\end{tikzpicture}

\begin{tikzpicture}
    \begin{axis}[%
        xlabel={XLABEL},
        ylabel={YLABEL},
        ymin=0, ymax=6,
        axis lines*=left]
        \addplot+[mark=none] plot {x};
    \end{axis}
\end{tikzpicture}


\end{document} 

enter image description here

Edit:

I use tikzscale to scale the plots:

\documentclass[]{article}

    \usepackage{tikz}
    \usepackage{pgf,pgfplots,graphicx,subfig}
    \usepackage{tikzscale}
    \pgfplotsset{compat=newest}
    \pgfplotsset{
    compat=newest,
    plot coordinates/math parser=false,
    every axis/.append style={
        xlabel shift=0.5em,
        ylabel shift=-0.5em
    }}
\begin{document}


\begin{figure}
\subfloat{\includegraphics[width=3cm,height=4cm]{plot1}}
\subfloat{\includegraphics[width=3cm,height=4cm]{plot1}}
\\
\subfloat{\includegraphics[width=3cm,height=4cm]{plot2}}
\subfloat{\includegraphics[width=3cm,height=4cm]{plot2}}
\end{figure}

\end{document}

Results in this output, where the axis are not aligned because of the negative signs of the upper plots

enter image description here

After adding trim axis left and scale only axis it looks like this:

   \pgfplotsset{
    compat=newest,
    plot coordinates/math parser=false,
    trim axis left,
    scale only axis,
    every axis/.append style={
        xlabel shift=0.5em,
        ylabel shift=-0.5em
    }}

enter image description here

share|improve this question

1 Answer 1

up vote 5 down vote accepted

The "cleanest" way to do this is to set trim axis left so the tick labels aren't taken into account for determining the bounding box, and scale only axis, which specifies that only the axis area without the labels is taken into account for setting the size of the plots. That way, your axis lines will have the same length, and they'll be alined along the y axis:

\documentclass[]{article}

    \usepackage{tikz}
    \usepackage{pgf,pgfplots}
    \pgfplotsset{compat=newest}
    \pgfplotsset{
    compat=newest,
    scale only axis,
    width=8cm, height=6cm,
    trim axis left,
    plot coordinates/math parser=false,
    every axis/.append style={
        xlabel shift=0.5em,
        ylabel shift=-0.5em
    }}
\begin{document}


\begin{tikzpicture}
    \begin{axis}[%
        xlabel={XLABEL},
        ylabel={YLABEL},
        axis lines*=left]
        \addplot+[mark=none] plot {x};
    \end{axis}
\end{tikzpicture}

\begin{tikzpicture}
    \begin{axis}[%
        xlabel={XLABEL},
        ylabel={YLABEL},
        ymin=0, ymax=6,
        axis lines*=left]
        \addplot+[mark=none] plot {x};
    \end{axis}
\end{tikzpicture}


\end{document} 
share|improve this answer
    
Thank you Jake for the useful answer. Now the problem I have is that, I am using the tikzscale package to scale the plots and setting trim axis left or scale only axis lead to an inappropriate scaling with that package. Do you know of any other ways to align the axis which doesn't require these two settings? (compatible with tikzscale scaling`) –  M.Reza Jan 28 '13 at 7:51
1  
There are other options, but it would be good if you could edit your question to include an example closer to the setup you're actually using (i.e. including tikzscale, and the alignment options you're using). –  Jake Jan 28 '13 at 8:17
    
@ Jake, I edited the post and included a sample with tikzscale package. Would appreciate any help on that. –  M.Reza Jan 28 '13 at 16:46

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.