0

I automatically generate a bunch of diagrams, and I'd like them to be automatically formatted to fit the page according to the following style:

  1. If the diagram (in the form of a .png figure) is smaller than a certain linewidth factor b=1.11\linewidth, then I'd like it to have a fixed scale a=0.5, for example scale=0.5.
  2. If the diagram is larger (at that scale of 0.5) than 1.11\linewidth, I'd like the image to be scaled to have a maximum linewidth of 1.11\linewidth.
  3. If the image has 1.11\linewidth I'd like it to be centered on the page.

The latter can be done using \makebox or [adjustbox] according to this answer:

\begin{figure}[H]
\makebox[\linewidth][c]{\includegraphics[width=1.11\linewidth]{latex/project6/Images/some_image.png}}%
  \caption{Some caption.}\label{fig:some_reference}
\end{figure}

My question is: how can I automatically detect whether the image width is larger than 1.11\linewidth at scale=0.5 (ideally parametrically) and automatically adjust the image width accordingly?

a.t.
  • 267
  • 1
    Hi! I do not understand that very well --- a png is a bitmap figure, so it's size is dependent on the density you want, i.e., it has no "natural" size. At 300dpi it is smaller than at 150dpi... Besides, maybe you just need max width? https://tex.stackexchange.com/a/32902/38080 – Rmano Jan 11 '22 at 10:19
  • Thank you for asking for clarification. The .png files that are generated have a fixed dpi and variable sizes, for example one image may have dimensions 300x123, whereas another may have dimensions 200x2354. So if the images in the pdf are below a certain linewidth, I would like to keep them at a fixed scale=0.5 however, if that makes them to large for the page, I would like to limit their width to a 1.11\linewidth. Thank you, I will look into max width! – a.t. Jan 11 '22 at 10:26
  • Thank you, the solution was given in this answer. I voted to close this question as a duplicate. – a.t. Jan 11 '22 at 12:25

0 Answers0