4

I have a graph for which I want a centered x-label at the bottom. The idea is to use overpic and then insert som text at the bottom using \put(50,1){some x-label}.

The problem is that \put places the START of the text relative to the image. Is there a way to put the CENTER of the text relative to the image?

Code:

\begin{center}
    \begin{overpic}[width=0.8\textwidth]{graph}
        \put(50,1){some x-label}
    \end{overpic}
\end{center}

I also want a y-label rotated 90deg counter clockwise horisontally centered on the left side of the graph. Is there a way to do this?

0

3 Answers 3

4
   \put(50,1){\makebox(0,0){some x-label}}

will put the (horizontal and vertical) centre of of the text at the specified position.

To rotate text you can use \rotatebox

   \put(50,1){\makebox(0,0){\rotatebox{90}{some x-label}}}
4

With swiss army knife tikz:

\documentclass{article}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \node[inner sep = 0pt] (a) {\includegraphics[width=6cm]{example-image-a}};
    \node[anchor=south,inner sep=1pt] at (a.south) {This is $x-$label};
    \node[anchor=south,inner sep=1pt,rotate=-90] at (a.west) {This is $y-$label};
  \end{tikzpicture}
\end{document}

enter image description here

1

This uses the stackengine package. Here, the x-axis label is centered horizontally, with the offset to the bottom of the label specified from the bottom of the graph. Likewise, the y-axis label is centered vertically, with the offset to the left of the label specified from the left of the graph.

EDITED to show that image aspect poses no problems; nor does math in label.

\documentclass{article}
\usepackage{stackengine,graphicx}
\begin{document}
\stackinset{l}{2pt}{c}{}{\rotatebox{-90}{This is my $y$-axis label}}{%
  \stackinset{c}{}{b}{2pt}{This is my $x$-axis label}{%
    \includegraphics[width=3in]{example-image-A}%
}}
\end{document}

enter image description here

If your graph has no blank region in which to apply the labels, \stackinset can apply the labels outside of the image, by using negative offsets. However, in this case, make the y-axis label the innermost nested inset, because an inset that extends above or below the base content (as does the x-label) effectively changes the image height for subsequent insets. In contrast, extending out the left or right of the image does not change the effective width of the image.

\documentclass{article}
\usepackage{stackengine,graphicx}
\begin{document}
\stackinset{c}{}{b}{-12pt}{This is my x-axis label}{%
  \stackinset{l}{-12pt}{c}{}{\rotatebox{-90}{This is my y-axis label}}{%
    \includegraphics[width=3in,height=3in]{example-image-A}%
}}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .