2

I wanted to do this:

Crop jpeg into circular tikz node

but write with a variable width:

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\def\mywidth{2cm}
\tikz\node[circle,draw,minimum size=1.2*\mywidth
           text=white,
           path picture={
               \node at (path picture bounding box.center){
                   \includegraphics[width=1.2\mywidth]{frog}
               };
           }]{I'm watching you!};
\end{document}

Why does this not work? The includegraphics command does not display the image in 1.2\mywidth but some arbitrary size. The circle is the right size.

Second examples

Code 1

\documentclass[tikz,border=5mm]{standalone}
\begin{document}

\def\firstwidth{1cm}
\def\secondwidth{2\firstwidth}

\tikz\node[circle,draw,minimum size=\firstwidth,
           path picture={
               \node at (path picture bounding box.center){
                   \includegraphics[width=\firstwidth]{blackbox.png}
               };
           }]{};
\end{document}

Result 1

enter image description here

Code 2

\documentclass[tikz,border=5mm]{standalone}
\begin{document}

\def\firstwidth{1cm}
\def\secondwidth{2\firstwidth}

\tikz\node[circle,draw,minimum size=\firstwidth,
           path picture={
               \node at (path picture bounding box.center){
                   \includegraphics[width=0.5\secondwidth]{blackbox.png}
               };
           }]{};
\end{document}

Result 2 (should be like Result 1)

enter image description here

  • maybe you need \def instead of \dev? – percusse Dec 2 '15 at 19:40
  • @percusse: Typo. Issue remains of course. – Make42 Dec 2 '15 at 19:50
  • How about the missing * sign? – percusse Dec 2 '15 at 19:56
  • Can you make a sketch what you like to obtain? And where you like to place your frog on page? – Zarko Dec 2 '15 at 20:10
  • @Zarko: It's supposed to look as in the link. Difference only in size. – Make42 Dec 2 '15 at 20:27
2

It seems that the problem is how are defined lengths \mywidth, \firstwidth and \secondwidth. If insted of \def\mywidth{2cm} etc use definitions:

\newlength\mywidth\setlength\mywidth{2cm}

\newlength\firstwidth
\setlength\firstwidth{1cm}

\newlength\secondwidth
\setlength\secondwidth{2\firstwidth}

Your example will work as you expected (of course, if I correctly understand your problem):

enter image description here

Complete MWE is:

\documentclass[tikz,border=5mm]{standalone}
    \usepackage{graphicx}

\begin{document}
\newlength\mywidth\setlength\mywidth{2cm}

\newlength\firstwidth
\setlength\firstwidth{1cm}

\newlength\secondwidth
\setlength\secondwidth{2\firstwidth}

\tikz\node[circle,draw,minimum size=1.2\mywidth,
           text=white,
           path picture={
               \node at (path picture bounding box.center){
                   \includegraphics[width=1.2\mywidth]{example-image-a}
               };
           }]{see};

\tikz\node[circle,draw,minimum size=\firstwidth,
           text=white,
           path picture={
               \node at (path picture bounding box.center){
                   \includegraphics[width=\firstwidth]{example-image-b}
               };
           }]{see};

\tikz\node[circle,draw,minimum size=\firstwidth,
           text=white,
           path picture={
               \node at (path picture bounding box.center){
                   \includegraphics[width=0.5\secondwidth]{example-image-c}
               };
           }]{see};
\end{document}
| improve this answer | |

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.