2

I'm using the graphicx package. By default, included graphics are aligned with the baseline at the bottom of the image. I know how to make images vertically centered (using \vcenter) or top-aligned. But what I really want is to just use the origin of the included figure as the baseline. Is there any way to do this conveniently, using either graphicx or some other similar package?

8
  • 1
    By "origin" you probably mean the vertical and horizontal midpoint/centre of the image, correct? Or, ultimately, only the vertical midpoint, since the image will be set to the right of wherever you place the \includegraphics macro.
    – Werner
    Sep 9, 2014 at 4:06
  • 1
    @Werner, no, I mean the origin in the internal coordinates of the image. I create my figures in MetaPost, so I put my origin exactly where I want it. Sep 9, 2014 at 4:10
  • graphicx places the image as a box, as defined by the bounding box, and may not consider the origin of the actual image.
    – Werner
    Sep 9, 2014 at 4:14
  • 1
    If you are making an EPS file in metapost and including it then not really possible, if you are using the feature of the pdftex driver file for graphicx to directly include mp code, translating to pdf via context based tex macros, them it's probably possible but you'd need to provide a complete test example in your question. Mar 10, 2015 at 13:15
  • 1
    There may be some confusion as to exactly what I'm asking for. EPS files have a bounding box at the top of the file, which gives not just the dimensions of the figure but also an offset (which you can think of as a preferred origin). I'd like the point (0,0) with respect to those bounding coordinates to end up on the TeX baseline. Apr 16, 2015 at 12:34

1 Answer 1

2

This can't be done when including image files with \includegraphics: graphicx has no interface to whatever the code was that originally produced the figure.

However, it can be done if you integrate your graphics drawing with the TeX code itself. I don't know much MP, but here is an example with another drawing package.

This shows a TikZ/pgf solution, using the baseline key to specify a point in the diagram (named coordinate or arbitrary x-y coordinate pair) for baseline alignment:

\documentclass{article}
\usepackage{tikz}
\def\mytest{\node[draw] (A) {text};}

\begin{document}
Here is base-aligned
\begin{tikzpicture}[baseline=(A.base)]
  \mytest
\end{tikzpicture}
and here is top-aligned
\begin{tikzpicture}[baseline=(A.north)]
  \mytest
\end{tikzpicture}.

And here is a pair of axes with the origin on the baseline:
\begin{tikzpicture}[baseline={(0,0)},x=1em,y=1em,font=\footnotesize]
  \draw[->] (-0.2,0) -- (1,0) node[right] {$x$};
  \draw[->] (0,-0.2) -- (0,1) node[right] {$y$};
\end{tikzpicture}.
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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