# includegraphics with TikZ

I am trying to create an environment with some picture in the left margin. Here is the code

\documentclass[twoside]{article}
\usepackage[paperwidth=170mm, paperheight=240mm, left=142pt, top=40pt,textwidth=280pt, marginparsep=6pt, marginparwidth=100pt, textheight=560pt, footskip=40pt,bindingoffset=30pt,asymmetric,reversemarginpar]{geometry}

\usepackage{lipsum}
\usepackage{sidenotes}
\usepackage{tikz}

\newcounter{sides}

\newenvironment{sideletter}[2]%
{\newcommand{\foot}{\includegraphics[width=#2]{#1}}%
\refstepcounter{sides}%
\par\makebox(0,0)[r]{\large\bfseries\sffamily\colorbox{red}{Ejercicio~\thesides}%
\hspace{6pt}%
}\ignorespaces}%
{\begin{marginfigure}
\hfill\tikz{\node at (0,0){\foot};}
\end{marginfigure}\bigskip}

\newenvironment{sideletter*}%
{\refstepcounter{sides}%
\par\makebox(0,0)[r]{\large\bfseries\sffamily\colorbox{red}{Ejercicio~\thesides}%
\hspace{6pt}%
}\ignorespaces}%
{\begin{marginfigure}
\hfill\tikz{\node at (0,0) {text};}
\end{marginfigure}\bigskip}

\setlength\parindent{0pt}

\begin{document}

\begin{sideletter}{imagen}{20pt}
\lipsum[4]
\end{sideletter}

\begin{sideletter}{imagen}{35pt}
\lipsum[6]
\end{sideletter}

\begin{sideletter*}
\lipsum[7]
\end{sideletter*}

\end{document}


which needs a graphic file.

This is a result:

This is almost what I want. A paragraph on the right, with some text in the margin as a title, and at the bottom of the paragraph, some picture on the left margin.

My problem is that the base of the picture is not align with the baseline because, I think, \includegraphics inside a \tikz command considers the origin at the center of the picture. I want the picture to be aligned with the baseline of the paragraph as in the third example with the word 'text'.

-
Hi ernesto. Note that you don't have to sign with your name since it automatically appears in the lower right corner of your post. –  Claudio Fiandrino Feb 13 at 17:31
Try \tikz[baseline=0pt] \node[anchor=south, inner sep=0pt] at (0,0) {\foot}; –  JLDiaz Feb 13 at 17:49
There is no difference. I don't understand well the behavior. If I use texto \tikz[baseline=0pt]{\includegraphics[width=60pt]{imagen}}; without node then the image is aligned to the baseline as I would like in my environment, but the graphics is over the paragraph. However, if I use node as in \tikz[baseline=0pt] \node at (0,0) {\includegraphics[width=60pt]{imagen}}; then the image is included putting the center of the picture at (0,0). –  ernesto Feb 14 at 14:59

Ok, I have found what I wanted. That was a problem with marginfigure enviroment. I had to use marginpar so my environment is:

\newenvironment{sideletter}[2]%
{\newcommand{\foot}{\includegraphics[width=#2]{#1}}%
\refstepcounter{sides}%
\par\makebox(0,0)[r]{\large\bfseries\sffamily\colorbox{red}{Ejercicio       \thesides}%
\hspace{6pt}%
}\ignorespaces}%
{\marginpar{%
\hfill\tikz[baseline=0pt]\node[anchor=base] {\foot};}
\bigskip}

-