Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a very large(heightwise) figure and would like to fit it on a page with its caption, that I place below (document wide style which I would like to keep, and the figure fills the line anyhow, so placing the caption on the side is not a solution). Is there any way to scale the figure to fit the page with the caption? (I amaware of scalebox, but I would like to avoid scaling the captiontext).

\documentclass{report}
\usepackage{floatrow}
\usepackage[demo]{graphicx}
\floatsetup{style=ruled, footposition=caption, capposition=bottom, heightadjust=object}
\begin{document}
\begin{figure}
  \includegraphics[height=1.2\textheight]{dummy}
  \caption{this should be in text}
\end{figure}
\end{document}
share|improve this question
1  
Can't you just change 1.2\textheight to e.g. 0.9\textwidth, or something like that? –  Torbjørn T. Sep 11 '13 at 14:24
    
@TorbjørnT. : this is a MWE, I use a tikz picture. I could try guessing some height(!) however I would like to scale my picture down as little as possible. And I hope that there is a tex style of way to say "fit this figure (with its caption and floatfoot) into the page bounds". (In short: my actual figure does not have height, and I am trying not to guess the apropriate scaling factor. –  ted Sep 11 '13 at 14:38
    
Ah, I see, a tikzpicture is a little different, wouldn't have hurt to mention that. (Oh, and not that it matters, but I did of course mean 0.9\textheight in my previous comment.) –  Torbjørn T. Sep 11 '13 at 14:43

2 Answers 2

up vote 7 down vote accepted

You could work out how much space is taken up by your float style and adjust accordingly, or you could just let latex do it for you.

If you use

  \includegraphics[height=\dimexpr\textheight\relax]{dummy}

LaTeX reports

LaTeX Warning: Float too large for page by 22.2pt on input line 9.

so if you use

  \includegraphics[height=\dimexpr\textheight-22.2pt\relax]{dummy}

It is happy.

share|improve this answer

Use LaTeX to calculate the height automatically, and scale the image appropriately:

\documentclass{report}
\usepackage{floatrow}
\usepackage[demo]{graphicx}
\usepackage{calc}
\usepackage{fp}
\floatsetup{style=ruled, footposition=caption, capposition=bottom, heightadjust=object}
\begin{document}
\begin{figure}
  \newlength{\spacearoundfigures}        % It should be possible to calculate this value
  \setlength{\spacearoundfigures}{124pt} % Include \abovecaptionskip and \belowcaptionskip\
  \newsavebox{\figurebox}
  \savebox{\figurebox}{\includegraphics[height=1.2\textheight]{dummy}}
  \newsavebox{\captionbox}
  \savebox{\captionbox}{this should be in text}% N.B. only works for one-line captions add code to allow line breaking and limit width to \textwidth less figure horizontal space
  \newlength{\cbh}
  \settototalheight{\cbh}{\usebox{\captionbox}}
  \newlength{\fbh}
  \setlength{\fbh}{\textheight}
  \addtolength{\fbh}{-\cbh}
  \makeatletter\FPdiv\result{\strip@pt\fbh}{\strip@pt\textheight}\makeatother
  \scalebox{\result}{\usebox{\figurebox}}
  \caption{\usebox{\captionbox}}
\end{figure}
\end{document}
share|improve this answer
2  
I get LaTeX Warning: Float too large for page by 123.86978pt on input line 21. –  David Carlisle Sep 11 '13 at 16:47
1  
Missed that. Naturally, one would also have to include into one's calculations the space used thus far on the page, the space above and below figures, &c. (which is left as an exercise for the reader --- I added a hard-coded value to remove the warning message) –  WillAdams Sep 11 '13 at 16:50
2  
A multiline caption will give a bunch of problems. Can you see why? –  egreg Sep 12 '13 at 17:04
1  
Yes, one would need to add in code to limit the width of the caption box to \textwidth less any horizontal spacing around the figure. –  WillAdams Sep 13 '13 at 12:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.