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?
1 Answer
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}
\includegraphics
macro.graphicx
places the image as a box, as defined by the bounding box, and may not consider the origin of the actual image.