3

I struggle to align the picture to the bottom left corner; see the image below.

Corner of the picture is not aligned with black frame.

The placeholder picture is taken from this site, and the code is below.

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{graphicx}
%\usepackage[margin=0cm, paperwidth=16cm, paperheight=9cm]{geometry}

\newcommand*{\xMin}{-8}
\newcommand*{\xMax}{8}
\newcommand*{\yMin}{-4.5}
\newcommand*{\yMax}{4.5}

\begin{document}
\begin{tikzpicture}[x=1cm, y=1cm]

\draw [line width = 1] (\xMin,\yMin) rectangle (\xMax,\yMax);

\node[opacity = 1, anchor = south west] at (\xMin,\yMin) {\includegraphics[width=8cm, keepaspectratio]{nyc.jpg}};
\end{tikzpicture}
\end{document}

I tried to utilize the geometry package, but it worsened things.

1
  • Width should be 16cm (from -8cm to 8cm). You also need inner sep=0pt to hit the corner. Commented May 18 at 12:16

1 Answer 1

4

I have put 1cm of margin for the standalone class that you can remove. I have include the image aligned to the bottom left corner with anchor=south west and I have added inner separation with inner sep=0 to remove any internal padding around the node that could affect alignment.

enter image description here

\documentclass[margin=1cm]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{graphicx}
\newcommand*{\xMin}{-8}
\newcommand*{\xMax}{8}
\newcommand*{\yMin}{-4.5}
\newcommand*{\yMax}{4.5}
\begin{document}
\begin{tikzpicture}[x=1cm, y=1cm]
\draw [line width = 1] (\xMin,\yMin) rectangle (\xMax,\yMax);
 % Include the image aligned to the bottom left corner
\node[opacity = 1,anchor=south west, inner sep=0] at (\xMin,\yMin) {\includegraphics[width=8cm, keepaspectratio]{example-image-a}};
\end{tikzpicture}
\end{document}

You must log in to answer this question.

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