Fraction of \textwidth as image width
Informally, length calculation are done using factor multiplication as there is no division notation. Since any division can be represented as some multiplication, this shouldn't be a problem. So, .5\textwidth
refers to half (1/2) of \textwidth
, while 2\wd0
refers to twice the w
id
th of box 0
. In your case it suffices to use
\includegraphics[width=0.3333\textwidth]{<img>}
You can perform all kinds of calculations using calc
or even LaTeX3:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff
\begin{document}
\newlength{\mylen}
\setlength{\mylen}{\textwidth}
\verb|\mylen|: \the\mylen
\setlength{\mylen}{\calc{1/3}\textwidth}
\verb|1/3\mylen|: \the\mylen
\end{document}
The LaTeX3 syntax above makes \calc
an new
c
ontrol s
equence (or macro) that is eq
uivalent to \fp_eval:n
- a fl
oating p
oint function that eval
uates it's argument using the regular programming arithmetic (like +
, -
, *
, /
, ^
, ...) taking a single argument.
Compile with lualatex
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{luacode}
\begin{document}
\newcommand\w{\directlua{tex.sprint(1/3)}}
This is my graph, it has width of \w and it looks very nice
\includegraphics[width=\w\textwidth]{}
\end{document}