Beruflich Dokumente
Kultur Dokumente
typesettingsystems.It's100%free,noregistrationrequired.
login
I know how to add a picture to my LaTeX file, e.g. \includegraphics[width=7cm]{curve.pdf} . What I'd now like to do is place
some latex symbols onto the picture. Like a \gamma to name a curve. I do not want to do that in the graphics editing
program e.g. because I might want to rename that curve later and don't want to repeat the editing process.
I know I can do a \put in a picture environment. But this environment forces me to specify its size at the beginning. That
would be cumbersome since I'd have to go open the graphics file and do some calculations. Is there a way to get the
dimensions (or aspect ratio) of a graphics file within LaTeX, so I might use it there? But even if I could do these calculations
automatically, I still wouldn't like the redundancy of specifying the width for \includegraphics again, but I could live with
that.
Also, is it possible to specify the size in cm to the picture environment? I just tried and got some errors.
So basically what I am looking for is a solution as simple as possible which:
a) lets me specify a width or a height and a file, and displays the image scaled while keeping its aspect ratio and then
b) lets me put LaTeX stuff inside the image in relative coordinates (percentages or 0...1), so I won't have to redo anything
should I decide that the image needs to be a bit larger or smaller.
(b is kind of like setting \unitlength to the whole width=height for the 'picture' environment. But of course most images
are not square and I also don't appreciate the redundancy (but could live with it).)
29
398
569
11
16
2Answers
tour
help
Takethe2minutetour
HowtosuperimposeLaTeXonapicture?
signup
Remove the 'grid' option after you are done putting symbols in the picture. Overpic
can basically be used as a replacement for \includegraphics. Also, recently a user
found some minor bug where the figure turned out to be slightly shifted (probably
due to a number rounding error). I never had (or noticed) this issue myself.
edited Jun 15 '11 at 13:33
22
42
Requirement1:
a) lets me specify a width or a height and a file, and displays the image scaled
while keeping its aspect ratio and then
There are 3 "mutual exclusive" options that can be chosen to keep the aspect ratio
easily.
scale
(dimensionless)
width
(dimension)
height
(dimension)
For example:
\includegraphics[scale=3]{filename}
\includegraphics[scale=0.75]{filename}
equal to 3cm.
\includegraphics[width=0.5\linewidth]{filename}
equal to 3cm.
One unit in PSTricks equal to 1 cm by default. Therefore the most right and top grid
labels represent the width and the height of the rendered graphics, respectively. They
behave as the horizontal and vertical rulers. You can make use them to specify the
position at which the math symbol will be placed. For example, you want to put the
pie symbol at (4.5cm, 3.5cm) as follows.
\rput(4.5,3.5){\psscalebox{20}{\color{white}$\pi$}}
Unfortunately, this coordinate is not the centroid of the rendered graphics. The exact
coordinate of the centroid can be easily obtained as follows.
\rput(0.5\width,0.5\height){\psscalebox{20}{\color{white}$\pi$}}
where \width and \height are the width and height of the rendered graphics,
respectively. They are defined as follows in the preamble.
\width=\wd\IBox
\height=\ht\IBox
The complete code and the resulting PDF output are given below. I know you are not
happy with this way. Please see the remaining answer how to accomplish your second
requirement.
\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
%Ratiooftheimportedgraphicswidthtothelinewidth.
\def\RatioToLineWidth{0.75}
\savebox\IBox
{%
\includegraphics[width=\RatioToLineWidth\linewidth]{Images/pie}%
}
\newdimen\width
\newdimen\height
\width=\wd\IBox
\height=\ht\IBox
\pagestyle{empty}
\begin{document}
\begin{pspicture}(\width,\height)
\rput[lb](0,0){\usebox\IBox}
\rput(0.5\width,0.5\height){\psscalebox{20}{\color{white}$\pi$}}
\psgrid%commentthisrowifyouwanttohidethegrid.
\end{pspicture}
\end{document}
Requirement2:
b) lets me put LaTeX stuff inside the image in relative coordinates (percentages or
0...1), so I won't have to redo anything should I decide that the image needs to be
a bit larger or smaller.
(b is kind of like setting \unitlength to the whole width=height for the 'picture'
environment. But of course most images are not square and I also don't appreciate
the redundancy (but could live with it).)
Dividing the horizontal/vertical axis into 100 or 1 part(s) is practically uncomfortable.
The former makes the grid labels crowded and the latter makes low precision. In my
personal preference, dividing the horizontal/vertical axis into 10 parts is good
enough. To do this, just set xunit and yunit as follows.
\psset
{
xunit=0.1\width,
yunit=0.1\height
}
Here we use \width and \height as references. For instance, (x,y) in the code below
must be regarded in our mind as (x/10 of \width , y/10 of \height ).
\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
%Ratiooftheimportedgraphicswidthtothelinewidth.
\def\RatioToLineWidth{0.75}
\savebox\IBox
{%
\includegraphics[width=\RatioToLineWidth\linewidth]{Images/pie}%
}
\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}
\rput(0.5\width,0.5\height){\psscalebox{20}{\color{white}$\pi$}}
\psgrid%commentthisrowifyouwanttohidethegrid.
\end{pspicture}
\end{document}
I got an info from PSTricks manual, rather than creating a new box \IBox , we can use
the existing one \pst@boxg .
edited Aug 5 '11 at 5:46
community wiki
8 revs
xport
how will the grid change if you change the 'width=' of the '\includegraphics'? peter Jun 15 '11
at 18:08
1 so it will remain a 9 by 12 grid even if the picture is half the size? if this is true those numbers
seem a bit random. no pdflatex makes it a no-go for me, but it is interesting anyway. peter
Jun 15 '11 at 18:19
No. The grid labels are not random numbers. Depending on how you specify the unit , they are
automatically adjusted instead. xport Jun 16 '11 at 7:01