6

The answer to this question is a duplicate to Pgfplots: title covers scientific notation. However, the title/topic of this question is broader and therefore for some people easier to find.

How can I change the distance from the title to the axis of a plot? I'd like to have some tick labels at a axis at the top of a plot and a title above it. The title and the labels are written to near to each other as in the example below.

\documentclass{minimal}

\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\newcommand{\width}{6cm}
\newcommand{\height}{8cm}
\newcommand{\vertShift}{3cm}

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
    width=\width, height=\height, 
    yshift=\vertShift, % trying to shift the plot to give the title some space.
    axis x line*=bottom,
    hide y axis,
    ]
\end{axis}
\begin{axis}[% 
    title=A title,
    width=\width,height=\height, 
    yshift=\vertShift, % Trying to shift the plot to give the title some space.
    ybar,xticklabel pos=right,
    xticklabels={?,L,A}, 
    xlabel near ticks,
    ] 
    \addplot coordinates {(0,50) (0.2,20)}; 
\end{axis}
\end{tikzpicture}
\end{document}
0

1 Answer 1

10

Ah, found the answer. When shifting the title with title style={yshift=1.5ex} the problem is solved. With

\documentclass{minimal}

\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\newcommand{\width}{6cm}
\newcommand{\height}{8cm}

\begin{document}

\begin{tikzpicture}

\begin{axis}[%
    width=\width, height=\height,
    axis x line*=bottom,
    hide y axis,
    ]
\end{axis}
\begin{axis}[% 
    title style={yshift=2.5ex,},
    title=A title,
    width=\width,height=\height,
    ybar,xticklabel pos=right,
    xticklabels={?,L,A}, 
    xlabel near ticks,
    ] 
    \addplot coordinates {(0,50) (0.2,20)}; 
\end{axis}
\end{tikzpicture}
\end{document}

it is fine.

1
  • 1
    This is probably getting closed as a duplicate, but in any case, this answer would be more helpful if you said what you have changed. Jul 18, 2014 at 7:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.