2

I want to create the illusion of a note stuck on top of the page. Here I have typed and saved in photoshop rotated post-it note and then added to the xeLatex document with \includegraphics[angle =30 ]{paper.png} paper.png is at http://www.bluehillsfarm.com/images/paper.png I would like to be able to type comments on the post-it note into TeX and have them auto-size, i.e. if the professor's comment was longer it would shrink to a smaller font to fit the same-sized post-it note. Here is my MWE but the comment is not positioned right on the note.

\documentclass{article}
\usepackage{graphicx,pstricks}

\newpsstyle{gridstyle}
{
   gridwidth=0.1pt,
subgridwidth=0.05pt, 
gridlabels=5pt,
gridcolor=green, 
subgridcolor=white, 
subgriddiv=2
}

\psset{style=gridstyle}

\newsavebox\IBox

% Ratio of the imported graphics width to the line width.
\def\RatioToLineWidth{0.95}
\savebox\IBox
{%
\includegraphics[width=\RatioToLineWidth\linewidth]{paper.png}%
}


\newdimen\width
\newdimen\height
\width=\wd\IBox
\height=\ht\IBox


\pagestyle{empty}

\begin{document}

\psset
{
xunit=0.1\width,
yunit=0.1\height
}

\begin{pspicture}(\width,\height)       
\rput[lb](0,0){\usebox\IBox}
{\parbox{4cm}{I want this text to be justified. I want this text to be justified. I want this text to be justified. I want this text to be justified. I want this text to be justified. I want this text to be justified. }}
\end{pspicture}
\end{document}

This produces: text is on bottom-right

3 Answers 3

1

Here I use nested \stackinsets, using the paper image provided by the OP and the received stamp at http://www.xpressmarking.co.za/wp-content/uploads/2015/01/Received-Trodat-S-Printy.png

\documentclass{article}
\usepackage{stackengine,graphicx,lipsum}
\begin{document}
\rotatebox{30}{%
\stackinset{c}{}{c}{-.1cm}{\parbox{3in}{\bfseries\scriptsize\sffamily\lipsum[4]}}{%
  \stackinset{r}{2cm}{t}{1.5cm}{\includegraphics[width=1in]{Received-Trodat-S-Printy}}{%
    \includegraphics[width=4in]{paper}}}}
\end{document}

enter image description here

1

If you are open to a TikZ approach, here's one possibility:

enter image description here

The code:

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{environ}
\usepackage{lipsum}

\newdimen\fontdim
\newdimen\upperfontdim
\newdimen\lowerfontdim
\newif\ifmoreiterations
\fontdim12pt

\makeatletter
\NewEnviron{fitbox}[2]{% \begin{fitbox}{<width>}{<height>} stuff \end{fitbox}
  \def\buildbox{%
    \setbox0\vbox{\hbox{\minipage{#1}%
      \fontsize{\fontdim}{1.2\fontdim}%
      \selectfont%
      \stuff%
    \endminipage}}%
    \dimen@\ht0
    \advance\dimen@\dp0
  }
  \def\stuff{\BODY}% Store environment body
  \buildbox
  % Compute upper and lower bounds
  \ifdim\dimen@>#2
    \loop
      \fontdim.5\fontdim % Reduce font size by half
      \buildbox%
    \ifdim\dimen@>#2 \repeat
    \lowerfontdim\fontdim
    \upperfontdim2\fontdim
    \fontdim1.5\fontdim
  \else
    \loop
      \fontdim2\fontdim % Double font size
      \buildbox%
    \ifdim\dimen@<#2 \repeat
    \upperfontdim\fontdim
    \lowerfontdim.5\fontdim
    \fontdim.75\fontdim
  \fi
  % Now try to find the optimum size
  \loop
    %\message{Bounds: \the\lowerfontdim\space
    %         \the\fontdim\space \the\upperfontdim^^J}
    \buildbox%
    \ifdim\dimen@>#2
      \moreiterationstrue
      \upperfontdim\fontdim
      \advance\fontdim\lowerfontdim
      \fontdim.5\fontdim
    \else
      \advance\dimen@-#2
      \ifdim\dimen@<10pt
        \lowerfontdim\fontdim
        \advance\fontdim\upperfontdim
        \fontdim.5\fontdim
        \dimen@\upperfontdim
        \advance\dimen@-\lowerfontdim
        \ifdim\dimen@<.2pt
          \moreiterationsfalse
        \else
          \moreiterationstrue
        \fi
      \else
        \moreiterationsfalse
      \fi
    \fi
  \ifmoreiterations \repeat
  \box0% Typeset content
}
\makeatother

\newsavebox\ImageBox
\savebox\ImageBox{\includegraphics[width=0.6\linewidth]{paper}}

\newcommand\MyNote[2][]{%
\begin{tikzpicture}[#1]
\node[inner sep=0pt,outer sep=0pt,anchor=north west] (image)
  {\usebox\ImageBox};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\node[anchor=north west,inner sep=0pt] at ([shift={(0.065,-20pt)}]image.north west)
  {\begin{fitbox}{0.6\wd\ImageBox}{.6\ht\ImageBox}
    #2
\end{fitbox}};
\end{scope}
\end{tikzpicture}%
}

\begin{document}

\noindent\MyNote{Some short text}

\noindent\MyNote[rotate=30,transform shape]{Some test text and here we add some more text to see what is happening with the font size }

\noindent\MyNote{Some test text and here we add some more text to see what is happening with the font size and here we add some more text to see what is happening with the font size and here we add some more text to see what is happening with the font size and here we add some more text to see what is happening with the font size and here we add some more text to see what is happening with the font size}

\end{document}

To have the font adjust to the size, I used Werner's answer to Fit text into given box by adjusting the fontsize

1
\documentclass{article}
\usepackage{pstricks-add}
\usepackage{graphicx}
\usepackage{lipsum}
\newsavebox\IBox
\sbox\IBox{\includegraphics{paper}}
\makeatletter
\def\setPaper{\@ifnextchar[\setPaper@i{\setPaper@i[0]}}
\def\setPaper@i[#1](#2,#3)#4{\rput{#1}(#2,#3){%
  \usebox\IBox\psTextFrame[linestyle=none](-\wd\IBox,0)(0,\ht\IBox){%
    \parbox{0.7\wd\IBox}{#4}}}}%
\makeatother
\begin{document}
\setPaper(3,-3){\lipsum[1]}

\setPaper[45](0.5\linewidth,-12cm){\lipsum[1]}
\end{document}

enter image description here

This site is temporarily in read-only mode and not accepting new answers.

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