# [Tex/LaTex] includegraphics with TikZ

tikz-pgf

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:

(source: uclm.es)

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'.

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}