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 need a plot with two x-axes, on at the top the other at the bottom. I try to do this quite successfully with this example code:

\documentclass[12pt,twoside, a4paper]{report}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}  
 \usepackage{tikz} 
 \usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\begin{document}


\begin{tikzpicture}
 %\pgfplotsset{set layers}%Not used
\begin{semilogyaxis}[filter discard warning=false,scale only axis,
 width=5.41cm,
  height=4.415cm, 
 xmin=-7.5,xmax=7.5,ymin=0.01,ymax=50, 
 axis x line*=bottom,
 xtick={-6,-4,-2,0,2,4,6},
  enlargelimits=false,axis on top=true,
  xlabel=lower x scale,ylabel=y scale]
 \addplot[color=red,mark=x] coordinates {%just fake data
 (-6,0.1) (0,10) (6,0.2)};
 \end{semilogyaxis}

 \begin{semilogyaxis}[filter discard warning=false,
  scale only axis,
   width=5.41cm,
   height=4.415cm, 
   xmin=-0.7409,xmax=0.7409,ymin=0.01,ymax=50, 
   minor tick num=3,
   axis x line*=top,
   axis y line=none,
   enlargelimits=false,axis on top=true,
   xlabel=upper x scale]
   \end{semilogyaxis}
  \end{tikzpicture}
  \end{document}

The result is quite nice, as you can see here: Misalignment of labels

But due to the '-0.5' on the upper left corner there is a slight misalignment of the labels. How can I get rid of this problem?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

The minus sign has a greater text depth than the other characters in the labels, causing the misalignment. You can set text depth=0pt to fix this:

\documentclass[12pt,twoside, a4paper]{report}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}  
 \usepackage{tikz} 
 \usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\begin{document}


\begin{tikzpicture}
 %\pgfplotsset{set layers}%Not used
\begin{semilogyaxis}[filter discard warning=false,scale only axis,
 width=5.41cm,
  height=4.415cm, 
 xmin=-7.5,xmax=7.5,ymin=0.01,ymax=50, 
 axis x line*=bottom,
 xtick={-6,-4,-2,0,2,4,6},
  enlargelimits=false,axis on top=true,
  xlabel=lower x scale,ylabel=y scale]
 \addplot[color=red,mark=x] coordinates {%just fake data
 (-6,0.1) (0,10) (6,0.2)};
 \end{semilogyaxis}

 \begin{semilogyaxis}[filter discard warning=false,
  scale only axis,
   width=5.41cm,
   height=4.415cm, 
   xmin=-0.7409,xmax=0.7409,ymin=0.01,ymax=50, 
   xticklabel style={text depth=0pt},
   minor tick num=3,
   axis x line*=top,
   axis y line=none,
   enlargelimits=false,axis on top=true,
   xlabel=upper x scale]
   \end{semilogyaxis}
  \end{tikzpicture}
  \end{document}
share|improve this answer
    
Do you know why the minus sign needs such a depth? It looks like it could be avoided –  Spike Oct 28 '12 at 18:41
    
Thanks a lot for this easy, well working trick!! –  partial81 Oct 28 '12 at 20:16

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.